Use result of the for ith iteration of the for loop to compute the i+1 iteration

3 次查看(过去 30 天)
Hi all,
I am using relatively complex equations in order to derive the values of the variables: a and a_prime. These variables are derived following an iterative approach, starting with a = a_prime = 0 , and going through the for loop to obtain better values.
I am having however difficulty with using the final result of the a and a_prime as derived at the end of each for loop, in order to re-run the for loop with that value. Below is the code:
% Input Data
R = 5 ; % m
V = 10 ; % m/s
B = 3 ; % blades
lambda = 6 ; % tip speed ratio
% Input Matrix
% r(m) g(deg) c(m)
M = [ 0.20 53.0 0.65 ; ...
0.15 74.3 0.76 ; ...
2.50 84.9 0.44 ; ...
3.75 89.1 0.30 ; ...
5.00 92.6 0.19 ] ;
% Variables
r = M(:,1) ;
gamma = M(:,2) ;
c = M(:,3) ;
% Calculations
Omega = lambda * V / R ; % rad/s
% First guesses
a = 0 ;
a_prime = 0 ;
% Iterations
for k = 1:2 %length(M)
% Local factors
sigma = B * c(k) / (2 * pi * r(k)) ; % Local solidity
lambda_r = Omega * r(k) / V ; % Local tip speed
beta = atan(lambda_r * (1 + a_prime) / (1 - a) ) ; %relative flow anlge onto the blades
i = gamma(k) - beta * 180/pi ; % angle of incidence
C_L = 0.327 + 0.1059 * i - 0.0013 * i^2 ; % lift coefficient
% New a and a'
a = 1 / (1 + (4 * cos(beta)^2 ) / (sigma * C_L * sin(beta) )) ;
a_prime = (sigma * C_L / 4 / lambda_r / cos(beta) ) * (1 - a) ;
end
Any help would be appreciated.
Kind Regards,
KMT.

采纳的回答

Ameer Hamza
Ameer Hamza 2018-5-1
Instead of overwriting the variables, create an array. In the end, it will also help you to look at values of a and a_prime during each iteration.
a = zeros(1, length(M)+1) ;
a_prime = zeros(1, length(M)+1) ;
% Iterations
for k = 1:2 %length(M)
% Local factors
sigma = B * c(k) / (2 * pi * r(k)) ; % Local solidity
lambda_r = Omega * r(k) / V ; % Local tip speed
beta = atan(lambda_r * (1 + a_prime(k)) / (1 - a(k)) ) ; %relative flow anlge onto the blades
i = gamma(k) - beta * 180/pi ; % angle of incidence
C_L = 0.327 + 0.1059 * i - 0.0013 * i^2 ; % lift coefficient
% New a and a'
a(k+1) = 1 / (1 + (4 * cos(beta)^2 ) / (sigma * C_L * sin(beta) )) ;
a_prime(k+1) = (sigma * C_L / 4 / lambda_r / cos(beta) ) * (1 - a(k)) ;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by