Azzera filtri
Azzera filtri

where is the error in code of Shifted Power Method?

1 visualizzazione (ultimi 30 giorni)
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 Commento
Jeffrey Clark
Jeffrey Clark il 30 Giu 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.

Accedi per commentare.

Risposte (1)

Amanjeet Pani
Amanjeet Pani il 13 Lug 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.

Categorie

Scopri di più su Scripts in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by