-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpowerit.m
34 lines (33 loc) · 897 Bytes
/
powerit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [vec,value]=powerit(start,A,toler)
% function [vec,value]=powerit(start,A,toler)
% Power method for computing eigenvalues
% Susan Holmes, Stanford, 2002
%
% INPUTS:
% start [npts] - initialization vector of Eigenvalues
% A [npts npts] - either A'A or A'WA, where A is system matrix
% toler [1] - stopping tolerance, normally 1e-5
%
% OUTPUTS:
% vec [npts] - Eigenvector associated with largest Eigenvalue
% value [1] - largest Eigenvalue
dd=1;
x=start;
n=10;
iter=1;
while dd> toler
y=A*x;
dd=abs(norm(x)-n);
n=norm(x);
x=y/n;
%pause
if mod(iter,5)==0
fprintf('no. iter.: %3.0f\n', iter);
else
end
iter=iter+1;
end
vec=x;
value=n;
fprintf('total iter.: %3.0f\n', iter);
end