Skip to content

Instantly share code, notes, and snippets.

@hurutoriya
Last active November 29, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hurutoriya/7199bba526cfbc582618 to your computer and use it in GitHub Desktop.
Save hurutoriya/7199bba526cfbc582618 to your computer and use it in GitHub Desktop.
Visalization and Implemention of Power Method in MATLAB
res = 10^(-13);
A = [[1, 2, 0];
[2, 1, 1];
[0, 1, 0];]
[V, D] =eig(A)
eigen_value = diag(D);
norm(A*V(:,3)-eigen_value(3)*V(:,3))
x = [1; 0; 0]
ite = 0;
lambda = 0;
while res < abs(norm(A*x-lambda*x))
y = A*x;
ite = ite +1
lambda = dot(y,y)/dot(y,x);
x = y;
x = x/norm(x);
figure
fig = quiver3(0,0,0,x(1),x(2),x(3));
title(strcat(num2str(x),num2str(lambda)))
saveas(fig,strcat('eigenvector',num2str(ite),'.png'))
end
disp('residual norm')
norm(norm(A*x-lambda*x))

Visalization and Implemention of Power Method in MATLAB

We show a visualization of eigenvector in Power method by each iteration.

This animation made by convert command in imagemagic.

>> convert -layers optimize -loop 0 -delay 40 eigenvector*.png anim.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment