필터 지우기
필터 지우기

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