Filter löschen
Filter löschen

where is the error in code of Shifted Power Method?

1 Ansicht (letzte 30 Tage)
sadiqah aldahan
sadiqah aldahan am 14 Mai 2022
Beantwortet: Amanjeet Pani am 13 Jul. 2022
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 Kommentar
Jeffrey Clark
Jeffrey Clark am 30 Jun. 2022
@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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Amanjeet Pani
Amanjeet Pani am 13 Jul. 2022
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.

Kategorien

Mehr zu Scripts finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by