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) "

1 次查看(过去 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 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by