The code from the M file will not complete

조회 수: 1 (최근 30일)
Marko Radovic
Marko Radovic 2024년 11월 27일
답변: Abhinav Aravindan 2024년 12월 2일
When I run the code, which I received from my colleagues and which performs the calculation according to the Runge–Kutta–Fehlberg method (the method uses a variable integration step), the situation is such that the code cannot be completed.
The only thing I noticed is that the problem is in the last while loop.
When I remove the last while loop, the code completes successfully.
It does not matter what input value you enter for the parameter "a".
The controversial while loop is marked in the M file.
Please help

답변 (1개)

Abhinav Aravindan
Abhinav Aravindan 2024년 12월 2일
After looking through your code, it seems that the issue is due to the last "while" loop in Line 352, as pointed out in your query. The issue is that for the breaking condition of the "while" loop to be met, the value of "Le(q)" must be greater than "Lrange(2)". However, after the first few iterations, the value of "Le(q)" and "q" are not updated as the following "if" condition in your code is not satisfied, since the value of "gres_v" and "H" is above the set tolerance:
if gres_v<tol && gres_T<tol || H<2*Hmin
v(q+1)=v_II;
T(q+1)=T_II;
if Lq+H>br1
Le(q+1)=Lrange(2);
else
Le(q+1)=Lq+H;
end
P(q+1)=f*omega*(1-(v_II/V_gr)^2)/(s*(L_1+Le(q+1)));
q=q+1;
Lq=Le(q);
end
As a result, the loop keeps running indefinitely, and the program never completes. To resolve this, you may look into the above snippet from your code (Line 394) to address the update issue for "Le(q)".
Additionally, you may refer to following File Exchange submissions on "Runge-Kutta-Fehlberg" which may be helpful:

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by