Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-11-24, 04:56   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 Power Method in MATLAB

I would like to implement the Power Method for determining the dominant eigenvalue and eigenvector of a matrix in MATLAB.



Here's what I wrote so far:



%function to implement power method to compute dominant
%eigenvalue/eigenevctor
function [m,y_final]=power_method(A,x);
m=0;
n=length(x);
y_final=zeros(n,1);
y_final=x;
tol=1e-3;
while(1)
mold=m;
y_final=A*y_final;
m=max(y_final);
y_final=y_final/m;
if (m-mold) break;
end
end
end


With the above code, here is a numerical example:



 A=[1 1 -2;-1 2 1; 0 1 -1]

A =

1 1 -2
-1 2 1
0 1 -1

>> x=[1 1 1];
>> x=x';
>> [m,y_final]=power_method(A,x);
>> A*x

ans =

0
2
0


When comparing with the eigenvalues and eigenvectors of the above matrix in MATLAB, I did:



[V,D]=eig(A)

V =

0.3015 -0.8018 0.7071
0.9045 -0.5345 0.0000
0.3015 -0.2673 0.7071


D =

2.0000 0 0
0 1.0000 0
0 0 -1.0000


The eigenvalue coincides, but the eigenvector should be approaching [1/3 1 1/3]. Here, I get:



 y_final

y_final =

0.5000
1.0000
0.5000


Is this acceptable to see this inaccuracy, or am I making some mistake?





More...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 01:41


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.