Nested While Loops won't restart
显示 更早的评论
Hi all!
I am having a very difficult time with my while loops. The idea of this code is supposed to guess a temperature (T), then calculate V using the inner while loop, proceed to calculate S, then go back up to the top and do it again until S is solved for.
The problem I am running into is that the inner while loop (solving for V) only runs once. Then, every time the outer while loop runs after that it just skips the inner while loop and send my temperature off into infinity. Please help! here is the code below.
while S_check>5
T=T+.5;
while pCheck>1
P = R*T/(V-b)-a/(sqrt(T)*V*(V+b));
p_out = 50; %bar
pCheck = abs(p_out-P)*100/p_out; %percent agreement
V=V-0.00001
end
rho=1/(V/0.04607);
S2=(5*a*log(1+rho*b)/(2*T^(3/2)*R)+log(rho)-log((1/rho)-b)+log(1/(1-rho*b)-a*rho/(T^1.5*R*(1+b*rho))))*R; %expression for entropy
S_check=abs(S2-S1)*100/S2; %percent agreement
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!