フィルターのクリア

where is the error in code of Shifted Power Method?

1 回表示 (過去 30 日間)
sadiqah aldahan
sadiqah aldahan 2022 年 5 月 14 日
回答済み: Amanjeet Pani 2022 年 7 月 13 日
Ash=[3 -1 0;-2 6 -2;0 -1 3];
v=zeros(3,10);
vT=zeros(10,3);
v(:,1)=[0;1;0];
vT(1,:)=[0;1;0];
l=6.9996;
Av=zeros(3,10);
AvT=zeros(10,3);
m=zeros(10,1);
error=zeros(10,1);
display('-------------------------------------------------------------------------------------------')
display(' k [v^k]^T [Ashifited v^k]^T mk+1 |error|')
display('-------------------------------------------------------------------------------------------')
for k=1:10
if error(k,1)<0.0005
Ash=Ash-l*eye(3);
Av(:,k)=Ash*v(:,k);
AvT(k,:)=(Av(:,k))';
m(k+1,1)=Av(1,k);
vT(k,:)=(v(:,k))';
error(k+1,1)=abs(m(k+1,1)-m(k,1));
v(:,k+1)=Av(:,k)/m(k+1,1);
l=m(k+1,1);
end
end
  1 件のコメント
Jeffrey Clark
Jeffrey Clark 2022 年 6 月 30 日
@sadiqah aldahan, you should not use MATLAB commands (e.g., error) as your variable names. See Variable Names and use exist to check. Also don't use display where disp should be used. But your real issue is that when k==3 v(:,k+1)=Av(:,k)/m(k+1,1) divides 0 by 0 which results in NaN being stored in v which in turn results in plenty of NaN in almost every variable.

サインインしてコメントする。

回答 (1 件)

Amanjeet Pani
Amanjeet Pani 2022 年 7 月 13 日
Do not use MATLAB keywords (e.g., error) as your variable names.
To display on the matlab command window use disp().
Also when k==3, v(:,k+1)=Av(:,k)/m(k+1,1) divides 0 by 0 which results in NaN being stored in v which in turn results in plenty of NaN in almost every variable.

カテゴリ

Help Center および File ExchangeScripts についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by