Routine Name: powerIteration
Author: David Merkley
Language: Python
Description/Purpose: performs power iteration
Input: a matrix and starting point
Output: the operation
Implementation/Code:
def powerIteration(A, x0, tol=1e-10, maxiter=1e3):
l0 = float('inf')
x = x0
for i in range(int(maxiter)):
y = matrixVectorMultiply(A, x)
v = vectorScalarMultiply(y, 1/l2(y))
l1 = vectorDotProduct(v, matrixVectorMultiply(A, v))
error = abs(l1 - l0)
if (error < tol):
return l1, v
else:
l0 = l1
x = v
print("Max Iter")