Power Method Eigenvectors Code

조회 수: 4 (최근 30일)
Benjamin Boettcher
Benjamin Boettcher 2021년 1월 28일
댓글: Benjamin Boettcher 2021년 1월 28일
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
James Tursa
James Tursa 2021년 1월 28일
What do you mean by "look smoother"?
Benjamin Boettcher
Benjamin Boettcher 2021년 1월 28일
편집: Benjamin Boettcher 2021년 1월 28일
It seems to work, I guess I just wanted it verified. and see if it could be made any better.

댓글을 달려면 로그인하십시오.

답변 (1개)

James Tursa
James Tursa 2021년 1월 28일
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
Benjamin Boettcher
Benjamin Boettcher 2021년 1월 28일
Thanks. That was an artifact from the generation of this.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by