Trouble with using atan in script, output generated by script is not correct.
Afficher commentaires plus anciens
I am working on a problem requiring an iterative process involving the use of the atan() function. When I allow the script to run I am getting a number
alphai2 = 6.9389e-018
however, when I copy the line of code into the command window and execute I get the correct answer of 0.001204 (confirmed by calculator). I can't for the life of me figure out where the script is generating that number from. Since it is part of my convergence criteria my while loop is not running more than once.
V=5; %Velocity of flow coming into prop
Radius=12; %Radius of Prop
omegarpm=1200; %Rotational speed
omegarps=1200/60; %rotational speed in rad/s
localradius=5;
PoverD=8;
Clalpha=2*pi();
Clnot=1.2;
blades=2;
chord=0.1;
Vt=omegarps*Radius; %tips speed caused by rotation
lambda=V/Vt;
x=localradius/Radius;
wtVt=0;
cont=1;
i=2;
alphai1=0;
alphai2=0;
wtf=1;
while wtf<2;
alphai1=alphai2;
beta=atan(PoverD/(pi()*x));
wt=wtVt*Vt;
waVt=0.5*(-1*lambda+sqrt(lambda*lambda+4*wtVt*(x-wtVt)));
wa=waVt*Vt;
phi=atan(lambda/x);
alphai2=atan((V+wa)/(omegarps*localradius-wt))-phi
alpha=beta-alphai2-phi;
Cl=Clalpha*alpha+Clnot;
vevt=((lambda+waVt)^2+(x-wtVt)^2)^0.5;
Ve=vevt*Vt;
gamma=0.5*chord*Cl*Ve;
Fprandtl=(2/pi())*cos(exp(-(blades*(1-x)/(2*sin(atan(lambda))))));
wt=blades*gamma/(4*pi()*localradius*Fprandtl);
wtvt=wt*Vt;
cont=alphai2-alphai1;
if cont<0.00001
wtf=2;
end
end
1 commentaire
Image Analyst
le 29 Avr 2012
Nice variable name: wtf.
Réponse acceptée
Plus de réponses (1)
Richard Brown
le 29 Avr 2012
0 votes
Here's what happens.
- alphai2 gets computed
- the variable wt, which alphai2 depends on, gets updated.
- The exit condition is met, but the old value of alphai2 is retained.
If you recompute alphai2 using the updated wt, you get the answer you're getting if you run the single line at the command prompt after running the script.
Catégories
En savoir plus sur Execution Speed dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!