stuck in a while loop

19 ビュー (過去 30 日間)
Jonathan Ish-Shalom
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by