error at for loop end (courseera course ref. solution- fixed points Lorentz equations)

4 次查看(过去 30 天)
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,

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-4-13
编辑:Cris LaPierre 2021-4-13
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by