How to define multiple while loop conditions?
5 次查看(过去 30 天)
显示 更早的评论
Hello
I have a basic script to calculate a curve length. In first step I eliminate the complex number with a while loop function. In second step I try to received a curve length with one more specific parameter(second angle). But second "while" function do not work. I can not realize this problem. Can you help me with this problem?
if true
% code
r1=0;
r2=110.5;
r3=212.5;
beta2d=35;
beta1dpoz=45;
format long
xs2=r3*sind(beta2d); ys2=r1-r3*cosd(beta2d);
kruh1=xs2^2+ys2^2; kruh2=r1^2+r3^2-2*r1*r3*cosd(beta2d);
xA1=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))+ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1))); xA2=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))-ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1)));
xAmat=[xA1,xA2]; xA=max(xAmat);
while isreal(xA)==0
r1=r1+0.1;
xs2=r3*sind(beta2d);
ys2=r1-r3*cosd(beta2d);
kruh1=xs2^2+ys2^2;
kruh2=r1^2+r3^2-2*r1*r3*cosd(beta2d);
xA1=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))+ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1)));
xA2=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))-ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1)));
xAmat=[xA1,xA2];
xA=max(xAmat);
end
p=sqrt(2*r1^2+r3^2-2*r1*r3*(sind(beta2d)+cosd(beta2d)));
if r2>p
yA1=sqrt(r1^2-xA^2);
yA=yA1;
else
yA=-1*sqrt(r1^2-xA^2);
end
gamma=pi/2-atan(yA/xA);
gammad=gamma*180/pi;
L=2*pi*r1*gammad/360;
b=abs(abs(xs2)-abs(xA));
a=abs(abs(ys2)-abs(yA));
gammad1=gammad-90;
etad=atand(b/a);
deltad=abs(180-90-etad);
beta1d=deltad-gammad1;
if beta1d>=beta1dpoz
beta1d=beta1d
else
r1=r1
while beta1d>=beta1dpoz
r1=r1+0.1
xs2=r3*sind(beta2d);
ys2=r1-r3*cosd(beta2d);
kruh1=xs2^2+ys2^2;
kruh2=r1^2+r3^2-2*r1*r3*cosd(beta2d);
xA1=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))+ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1)));
xA2=1/2*(xs2*(1+((r1^2-r2^2)/(xs2^2+ys2^2)))-ys2*(sqrt(((2*(r1^2+r2^2))/(xs2^2+ys2^2))-((r1^2-r2^2)/(xs2^2+ys2^2))^2-1)));
xAmat=[xA1,xA2];
xA=max(xAmat);
p=sqrt(2*r1^2+r3^2-2*r1*r3*(sind(beta2d)+cosd(beta2d)));
if r2>p
yA1=sqrt(r1^2-xA^2);
yA1=yA;
else
yA=-1*sqrt(r1^2-xA^2);
end
gamma=pi/2-atan(yA/xA);
gammad=gamma*180/pi;
L=2*pi*r1*gammad/360;
b=abs(abs(xs2)-abs(xA));
a=abs(abs(ys2)-abs(yA));
gammad1=gammad-90;
etad=atand(b/a);
deltad=180-90-etad;
beta1d=deltad-gammad1;
end
end
q=[r1 r2 r3 beta1d beta2d L];
end
采纳的回答
dpb
2013-10-26
if beta1d>=beta1dpoz
beta1d=beta1d
else
r1=r1
while beta1d>=beta1dpoz
...
You've got the while clause in an else clause that ensures the condition is never true when that code section is reached.
Stated in another way, the test on the while is the same one as the T in the if so if it is false at that point the while test is also false and the while will never execute.
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!