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
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 个评论
Roman
Roman 2013-10-26
编辑:Roman 2013-10-26
Because if I don't know r1 but know beta1d I it is possible to approximate r1.
Roman
Roman 2013-10-26
Finally I relize it :) There was a logic problem as you said. Again...Thank you for your help, patience and willingness. :)
if beta1d>=beta1dpoz
beta1d=beta1d
else
for r1=r1:0.1:inf
.
.
.
etad=atand(b/a);
deltad=180-90-etad;
beta1d=deltad-gammad1;
while beta1d>=beta1dpoz
return
end
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by