Effacer les filtres
Effacer les filtres

where is the error in code of Shifted Power Method?

1 vue (au cours des 30 derniers jours)
sadiqah aldahan
sadiqah aldahan le 14 Mai 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 commentaire
Jeffrey Clark
Jeffrey Clark le 30 Juin 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.

Connectez-vous pour commenter.

Réponses (1)

Amanjeet Pani
Amanjeet Pani le 13 Juil 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.

Catégories

En savoir plus sur Scripts dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by