필터 지우기
필터 지우기

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