Just finished a nice little matlab script that gives me the dominant eigenvalue (with an error of at most 10^-7) and eigenvector of a 3×3 matrix, using the power method.

However, it’s giving me the correct eigenvalue, but the negative of the eigenvector (-b instead of b).

Here’s my script

a=[9 5 1;8 -5 9;-9 -2 -2];

b=[1;1;1];

function bnew=powermethod(a,b)

bnew=[0;0;0]; c=0; itterations = 0;

while c==0

itterations = itterations + 1;

bnew=a*b/norm(a*b);

d=a*b; e=a*bnew;

error = abs( (d(1)/b(1)) – (e(1)/bnew(1)) );

if error<10^-7

c=1;

end

b=bnew;

end

fprintf(‘\n Script took %d itterations to converge.\n’, itterations);

fprintf(‘\n Eigenvalue is %d.\n’, e(1)/bnew(1));

end

I know this is pushing it a bit, but thought someone might be able to see what’s going on. Cheers.