error at for loop end (courseera course ref. solution- fixed points Lorentz equations)
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
r=28; sigma=10; b=8/3;
RelTol=1.e-06; AbsTol=1.e-09;
for nroot=1:3
if nroot==1, x=1; y=1; z=1; end
if nroot==2, x=10; y=10; z=10; end
if nroot==3, x=-10; y=-10; z=-10; end
error=Inf;
while error > max(RelTol*max(abs([x,y,z])),AbsTol)
J=[-sigma, sigma, 0; r-z, -1, -x; y, x, -beta;];
rhs = -[sigma*(y-x); r*x-y-x*z; x*y-beta*z];
delta_xyz=rhs/J;
x = x + delta_xyz(1);
y = y + delta_xyz(2);
z = z + delta_xyz(3);
error=max(abs(delta_xyz));
end
xroot(nroot)=x; yroot(nroot)=y; zroot(nroot)=z;
end
roots=[xroot;yroot;zroot];
fprintf('steady-state solution:\n')
fprintf('(x, y, z) = (%2.0f,%2.0f,%2.0f) \n', roots(:,1));
fprintf('(x, y, z) = (%7.5f,%7.5f,%3.0f) \n', roots(:,2));
fprintf('(x, y, z) = (%7.5f,%7.5f,%3.0f) \n', roots(:,3));
They give the reference solution code as above. When I try to run it I get the error message, which I am really confused with cause this line is just 'end' of for for loop I thought.
"Error in beta (line 19)
y = exp(betaln(z,w));"
many thanks,
0 commentaires
Réponses (1)
Cris LaPierre
le 13 Avr 2021
Modifié(e) : Cris LaPierre
le 13 Avr 2021
I wonder if the variable b defined in the first line is supposed to be beta.
However, changing that just led to a new error. If this is truly the reference solution, you should notify the course instructor.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!