Now trying to loop my code for lambda and calculate a CL for each lambda but my code runs only twice.

2 次查看(过去 30 天)
My code for the for loop for lambda only runs once but I need it to run for each value of lambda and save the CL value for each one.
clc; clear all; close all
N=20;
V_inf = 50;
for lambda = linspace(0,1,20)
S = 39.2699;
AR = 10.1859;
AoA = 8; % Angle of Attack in degrees
b = 20;
alpha_0 = 0; % Zero lift angle of attack is 0 due to airfoil being symmetric
cr = (2*b)/(AR*(lambda+1));
ct = cr*lambda;
i = 1;
alpha = AoA * (pi/180);
alpha_0 = alpha_0 * ones(N,1);
Ntheta = N; % Number of theta = 20
theta = linspace(.01,pi-.01,Ntheta); % Set the value of theta
for k = 1:Ntheta % Calculate each theta
y = (b/2)*cos(theta(k));
if theta(k) <= pi/2
c = (2/b)*cr*(1-lambda)*y+cr;
else
c = -(2/b)*cr*(1-lambda)*abs(y)+cr;
end
if length(alpha) == 1
alpha = alpha * ones(N,1);
end
if length(c) == 1
c = c * ones(N,1);
end
C = zeros(Ntheta,N);
B = zeros(Ntheta,1);
for j = 1:Ntheta
for n = 1:N
C(j,n) = 2*b/(pi*c(j)) * sin(n*theta(j)) + n * sin(n*theta(j))/sin(theta(j));
end
B(j,1) = alpha(j,1) - alpha_0(j,1);
end
A = inv(C)*B;
Gamma = zeros(Ntheta,1);
alpha_i = zeros(Ntheta,1);
for n = 1:N
Gamma(j,1) = Gamma(j,1) + 2*b*V_inf * A(n) * sin(n*theta(j));
alpha_i(j,1) = alpha_i(j,1) + n * A(n) * sin(n*theta(j))/sin(theta(j));
end
end
A1(i) = A(1);
CL(i) = AR*A1*pi;
i = i +1;
end

回答(1 个)

Torsten
Torsten 2022-3-5
Set
i=1;
outside the lambda-loop !

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by