필터 지우기
필터 지우기

How do I modify my code to get rid of this error: "Index exceeds the number of array elements. Index must not exceed 1. Error in AEM614HW2Q2 (line 35) "

조회 수: 3 (최근 30일)
This is my error.
Index exceeds the number of array elements (1).
Error in HW2P2 (line 35)
C(j,n) = 2*b/(pi*c(j)) * sin(n*theta(j)) + n * sin(n*theta(j))/sin(theta(j));
clc; clear all; close all
N=500;
V_inf = 50;
i = 1;
lambda = .5; %linspace(0,1,N)
S = 39.2699;
AR = 10.1859;
alpha = 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;
for theta = linspace(.001,pi-.001,20);
y = (b/2)*cos(theta);
if theta <= pi/2
c = (2/b)*cr*(1-lambda)*y+cr;
else
c = -(2/b)*cr*(1-lambda)*abs(y)+cr;
end
alpha = alpha * pi/180;
alpha_0 = alpha_0 * pi/180;
if length(alpha) == 1
alpha = alpha * ones(N,1);
end
if length(alpha_0) == 1
alpha_0 = alpha_0 * ones(N,1);
end
if length(c) == 1
c = c * ones(N,1);
end
C = zeros(N,N);
B = zeros(N,1);
for j = 1:N
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 = C\B;
Gamma = zeros(N,1);
alpha_i = zeros(N,1);
for j = 1:N
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
end
A1(i) =A(1);
Cl(i) = AR*pi*A1;

채택된 답변

David Hill
David Hill 2022년 3월 5일
C(j,n) = 2*b/(pi*c(j)) * sin(n*theta) + n * sin(n*theta)/sin(theta);%get rid of theta(j) theta is scalar, cannot index >1 into it

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 3월 5일
for theta = linspace(.001,pi-.001,20);
theta is a scalar
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
but there theta has to be a vector of length N

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by