stuck in a while loop

18 Ansichten (letzte 30 Tage)
Jonathan Ish-Shalom
Jonathan Ish-Shalom am 8 Mai 2020
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 Kommentare
Akihumi
Akihumi am 8 Mai 2020
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 am 8 Mai 2020
putting a break point helped! thanks

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by