Effacer les filtres
Effacer les filtres

Trouble with using atan in script, output generated by script is not correct.

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Image Analyst
Image Analyst le 29 Avr 2012
What are you doing with your calculator? Did you set a break point on that line and actually punch those numbers in? I even tried assuming you thought it was degrees instead of radians and still didn't get your number of 0.001204. Here's the values from your program:
phi =
0.049958395721943
atanInput =
0.050000000000000
atan(0.050000) = 0.049958
alphai2 =
6.938893903907228e-018
(The atan result may be clipped for display.) I'm tending to believe MATLAB rather than what you did with your calculator.
  2 commentaires
Roger
Roger le 29 Avr 2012
Thanks, it was a matter of me not carrying around enough significant figures.
Richard Brown
Richard Brown le 29 Avr 2012
No it wasn't - see my answer below

Connectez-vous pour commenter.

Plus de réponses (1)

Richard Brown
Richard Brown le 29 Avr 2012
Here's what happens.
  1. alphai2 gets computed
  2. the variable wt, which alphai2 depends on, gets updated.
  3. 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.

Community Treasure Hunt

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

Start Hunting!

Translated by