stuck in a while loop

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 Comments

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.
putting a break point helped! thanks

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!