M.Sidorenko
M.Sidorenko

Reputation: 49

Power Method doesn't work for symmetric matrices

I implemented a simple power method in Python 3.7, which is supposed to compute the largest eigenvalue of a given matrix:

def power(A, x0, num_iter):
    """ A - matrix, x0 - initial approximation of eigenvector,
    num_iter - number of iteration"""

    x = x0
    l = x.T @ A @ x
    for i in range(num_iter):
        y = A @ x
        x = y / np.linalg.norm(y)
        l =  x.T @ (A @ x)
    return l

When I tried to compute the eigenvalue of a simple symmetric matrix, which has two eigenvalues 3 and 1:

test_matrix = numpy.array([[2, -1],[-1, 2]])

I got:

In1: test_matrix, np.array([1, 1]), 100 

Out1: 1

Why doesn't my algorithm in this case converge to the largest eigenvalue, i.e. 3?

Upvotes: 1

Views: 758

Answers (1)

Gabriel Hernandez
Gabriel Hernandez

Reputation: 573

I think the problem is the vector you used for initialization x0 = [1,1] If you run the Power method with x0 = [-1, 1] or [1, -1] you should get that largest eigenvalue is 3 after 3 iterations if your tolerance is 0.0001

Upvotes: 1

Related Questions