creating while loop for two different variable

1 view (last 30 days)
I am trying to create while or for loop but i could not point out the logic becase i have two variables for each iteration that they are chaning each loop and each iteration
a and a_prime are changing in each loop and the next loop will use the previous a and a_prime as old ones.
my third manual iterations are here. could you please help me to put it into the loop to achive the condition
condition is
a - a_old < epsilon
a - a_prime_old < epsilon
clear
clc
%%%%% when delta_a and delta_a_prime is less than epsilon get out the loop
R = 31 ; % Blade Radius in meter
B = 3 ; % Number of Blades
Rho = 1.225 ; % Density of air kg/m3
V0 = 8 ; % Wind Speed m/s
w = 2.61 ; % Rotational Speed rad/s
Theta_P = -3 ; % Tip Pitch Angle in degree
Chord = 0.5 ; % chordwise
Beta = 2 ; % Local Twist Angle in degree
Cl = 0.5 ; % Constant for this example
Cd = 0.01 ; % Constant for this example
r = 24.5 ; % Local Radius in meter
ac = 0.2 ;
epsilon = 5.0000e-05 ;
%%%%%%%%%%%%%%%%%%%%% Process
a_old = 0 ; % axial induction factor
a_prime_old = 0 ; % Tangential induction factor
save_a = [a_old] ;
save_a_prime = [a_prime_old] ;
% % % % iter 1
disp('iter 1')
disp(' ')
Phi = atand(((1-a_old)*V0)/((1+a_prime_old)*w*r)); % Flow Angle
Theta = Beta + Theta_P ;
Alpha = Phi - Theta ; % local angle of attack in degree
f = (B/2)* ((R-r)/(r*sind(Phi)));
F = (2/pi)*acos(exp(-f)); % Prandtl correction factor
Cn = Cl*cosd(Phi)+Cd*sind(Phi);
Ct =Cl*sind(Phi)-Cd*cosd(Phi);
sigma = (B*Chord)/(2*pi*r);
K=(4*F*(sind(Phi))^2)/(sigma*Cn);
%%%%%%%%%% a and ac condition
a1 = 1/(((4*F*(sind(Phi)^2))/(sigma*Cn))+1);
if a1 < ac || a1==ac
a1=a1;
else
a1 = 0.5*(2+K*(1-2*ac)-sqrt(((K*(1-2*ac)+2)^2)+4*((K*(ac^2))-1)));
end
a1_prime =1/(((4*F*(sind(Phi)*cosd(Phi)))/(sigma*Ct))-1);
save_a = [save_a a1];
save_a_prime = [save_a_prime a1_prime];
delta_a=a1-a_old
delta_a_prime=a1_prime-a_prime_old
disp(' ')
disp('iter 2')
% % % % iter 2
Phi = atand(((1-a1)*V0)/((1+a1_prime)*w*r)); % Flow Angle
Theta = Beta + Theta_P ;
Alpha = Phi - Theta ; % local angle of attack in degree
f = (B/2)* ((R-r)/(r*sind(Phi)));
F = (2/pi)*acos(exp(-f)); % Prandtl correction factor
Cn = Cl*cosd(Phi)+Cd*sind(Phi);
Ct =Cl*sind(Phi)-Cd*cosd(Phi);
sigma = (B*Chord)/(2*pi*r);
K=(4*F*(sind(Phi))^2)/(sigma*Cn);
%%%%%%%%%% a and ac condition
a2 = 1/(((4*F*(sind(Phi)^2))/(sigma*Cn))+1);
if a2 < ac || a2==ac
a2=a2;
else
a2 = 0.5*(2+K*(1-2*ac)-sqrt(((K*(1-2*ac)+2)^2)+4*((K*(ac^2))-1)));
end
a2_prime =1/(((4*F*(sind(Phi)*cosd(Phi)))/(sigma*Ct))-1);
save_a = [save_a a2];
save_a_prime = [save_a_prime a2_prime];
delta_a=a2-save_a(2)
delta_a_prime = a2_prime - save_a_prime(2)
disp(' ')
disp('iter 3')
% % % % iter 3
Phi = atand(((1-a2)*V0)/((1+a2_prime)*w*r)); % Flow Angle
Theta = Beta + Theta_P ;
Alpha = Phi - Theta ; % local angle of attack in degree
f = (B/2)* ((R-r)/(r*sind(Phi)));
F = (2/pi)*acos(exp(-f)); % Prandtl correction factor
Cn = Cl*cosd(Phi)+Cd*sind(Phi);
Ct =Cl*sind(Phi)-Cd*cosd(Phi);
sigma = (B*Chord)/(2*pi*r);
K=(4*F*(sind(Phi))^2)/(sigma*Cn);
%%%%%%%%%% a and ac condition
a3 = 1/(((4*F*(sind(Phi)^2))/(sigma*Cn))+1);
if a3 < ac || a3==ac
a3=a3;
else
a3 = 0.5*(2+K*(1-2*ac)-sqrt(((K*(1-2*ac)+2)^2)+4*((K*(ac^2))-1)));
end
a3_prime =1/(((4*F*(sind(Phi)*cosd(Phi)))/(sigma*Ct))-1);
save_a = [save_a a3]
save_a_prime = [save_a_prime a3_prime];
delta_a=a3-save_a(3)
delta_a_prime = a3_prime - save_a_prime(3)

Accepted Answer

Walter Roberson
Walter Roberson on 6 Dec 2021
while delta_a > epsilon || delta_a_prime > epsilon

More Answers (0)

Community Treasure Hunt

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

Start Hunting!