stuck in a while loop

조회 수: 19 (최근 30일)
Jonathan Ish-Shalom
Jonathan Ish-Shalom 2020년 5월 8일
댓글: Jonathan Ish-Shalom 2020년 5월 8일
My code is stuck in the determine_dh section when I try to run it and I can't figure out why. If you look in my code it seems that keeps looping through the "while" function. If you could help me debug this that would be great.
function [dhn] = determine_dh(acc,doverhstart,Ka1Kp1,ah,l1h,P1)
dho=doverhstart;
dhn=1000;
while abs(dhn-dho)>acc
dho=dhn;
bh = 1+dho-l1h;
dhn=find_dh(Ka1Kp1,dho,ah,bh,P1);
end
end
For refrence here is find_dh
function [dhout] = find_dh(Ka1Kp1,dh,ah,bh,P1)
numerator1=2/3*(1+dh)^2*Ka1Kp1*(dh+1-3/2*ah);
numerator2=P1*bh^2*((1/3)*bh-1-dh+ah);
denominator=2/3*dh+1-ah;
dhoutsq=(numerator1-numerator2)/denominator;
dhout=sqrt(dhoutsq);
end
  댓글 수: 2
Akihumi
Akihumi 2020년 5월 8일
Could you please provide some sample input? Or you can try setting a breakpoint before the while loop and run line by line to check the changes of dhn, dho, and other variables.
You can also set a breakpoint in find_dh or press F11 or 'Step In' to enter find_dh to check the changing variables inside find_dh.
Jonathan Ish-Shalom
Jonathan Ish-Shalom 2020년 5월 8일
putting a break point helped! thanks

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by