loop while doesn't stop
显示 更早的评论
Hi everybody,
I wrote a code related to a wind turbine exercice but my loop while does not stop and I don't understand why because it seems that stop conditions are fulfilled.
My loop while should stop when (a-a1=0) & (aprime-aprime1=0)
It would be great if you can have a look at my following code :
clear all
% Variable speed of the rotor
w=2.61;
% Air density 1.225 kg/m3
d=1.225;
% Rotor diameter 62 m
R=31;
% Number of blades 3
B=3;
% Cut in wind speed 5m/s
V0=15;
% local pitch
theta=0;
r=24.5;
Betat=2;
c1=1.09
erreur=1;
a=0;
aprime=0;
a1=0;
aprime1=0;
compteur=0;
while erreur>1e-3
compteur=compteur+1
a=a1;
aprime=aprime1;
phi=atan((1-a)*V0/((1+aprime)*w*r));
phi_deg=phi*180/pi;
alpha=phi_deg-(theta+Betat);
Cl=1;
Cd=0.001;
Cn=Cl*cos(phi)+Cd*sin(phi);
Ct=Cl*sin(phi)-Cd*cos(phi);
F=(2/pi)*acos(exp((-B/2)*(R-r)/(r*sin(phi))));
sigma=c1*B/(2*pi*r);
a=1/((4*(sin(phi))^2*F/(sigma*Cn))+1);
aprime=1/((4*sin(phi)*cos(phi)*F/(sigma*Ct))-1);
erreur=abs(abs(a-a1)+abs(aprime1-aprime));
matrix(compteur,1)=a
matrix(compteur,2)=aprime
matrix(compteur,3)=alpha
matrix(compteur,4)=phi_deg
matrix(compteur,5)=Cn
matrix(compteur,6)=Ct
end
Kind regards
2 个评论
Jan
2011-9-25
Please use proper code formatting to improve the readability. Follow the "Markup help" link to learn the details.
See this link about avoiding CLEAR ALL:
http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Andrei Bobrov
2011-9-25
so?
a1=1/((4*(sin(phi))^2*F/(sigma*Cn))+1);
回答(1 个)
Jan
2011-9-25
0 个投票
Your code creates the same values in each iteration, because you initialize a to a1 and aprime to aprime1 repeatedly. Please use a debugger to check this: Set a breakpoint in the code and step through your program line by line.
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!