필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

채택된 답변

Image Analyst
Image Analyst 2012년 4월 29일
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
Roger
Roger 2012년 4월 29일
Thanks, it was a matter of me not carrying around enough significant figures.
Richard Brown
Richard Brown 2012년 4월 29일
No it wasn't - see my answer below

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Richard Brown
Richard Brown 2012년 4월 29일
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.

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by