Power Method Eigenvectors Code
Show older comments
I am attempting to make a code for a manual computation of the Power Method.
I think I have it working properly but wanted to make sure. Any thoughts?
function [lambda,x,k] = power_method(A,x,tol,maxit);
% Initialize
n = length(A);
k = 0;
y = zeros(1,n);
tolerance = 1;
while k < maxit && (tolerance > tol)
yk = A * x; % y(k) = A* x(k)
xnext = yk / norm(yk); % X(k+1) = yk / 2norm(yk)
lambda = dot (xnext,(A * xnext)); % lambda = X(k+1) * (A * X(k+1))
k = k + 1;
tolerance = norm(yk - lambda * x);
err = tolerance;
x = xnext;
end
2 Comments
James Tursa
on 28 Jan 2021
What do you mean by "look smoother"?
Benjamin Boettcher
on 28 Jan 2021
Edited: Benjamin Boettcher
on 28 Jan 2021
Answers (1)
James Tursa
on 28 Jan 2021
The only obvious thing I would note is that the following line doesn't accomplish anything because you don't use err in your code, so it can be removed:
err = tolerance;
1 Comment
Benjamin Boettcher
on 28 Jan 2021
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!