running a summation function for different values of N
Afficher commentaires plus anciens
Hello,
I am trying to solve this summation function LLT_type 2 for three different values of N. The values of N are 5, 20, 100. When I run the code to solve the function for the three different values it solves for N=5, but then I get an error saying:
??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> LLT_run at 12 result(iN) = LLT_type2(b,N(iN),c,a,alpha,alphaoL,e,AR)
In my code N is a scalar value. I basically would just like to rerun the code for each value of N and store the results ,so that they can be plotted together. Any help is greatly appreciated.
function [LLT_solver] = LLT_run
global b N c a alpha alphaoL e AR
type=2 % read the input file using read_inp1.m
if type == 2
read_inp_type2;
N = [5, 20, 100];
result = zeros(1, length(N)); % Or what ever matchs your output
for iN = 1:length(N)
result(iN) = LLT_type2(b,N(iN),c,a,alpha,alphaoL,e,AR)
end
end
The function file is:
function[An,CL,delta,CDi,Gamma,Cl]=LLT_type2(b,N,c,a,alpha,alphaoL,e,AR)
b;
N;
c=(c*ones(1,N))';
a=(a*ones(1,N))';
alpha=(alpha*ones(1,N))';
alphaoL=(alphaoL*ones(1,N))';
e=(e*ones(1,N))';
n=1:N; % n rows
theta=(n.*pi/(N+1))'; % theta values
y0=-b/2*cos(theta); % y values for each theta
RHS=(alpha+e-alphaoL)/180*pi; % Solving RHS
% Finding IC matrix to solve for An's
IC = zeros(N);
for l = 1:N;
for m = 1:N;
IC(l,m) = (4*b/a(l)/c(l)+m/sin(theta(l)))*sin(m*theta(l));
end
end
format long
An=IC\RHS
CL=An(1)*pi*AR
x=((n.*((An'./An(1))).^2));
delta=x(2:N);
format short
delta=sum(delta)
CDi=(CL^2/(pi*AR))*(1+delta)
% calculation of the vorticity Gamma on the wing
for i=1:N,
Gamma(i)=2*b*sum(An(:).*sin((1:N)*theta(i))');
end;
Gamma
Cl=(2*Gamma)./c'
plot(y0,Cl); ylabel('Cl / Vinf');
Réponse acceptée
Plus de réponses (1)
Christopher
le 14 Juin 2013
Modifié(e) : Christopher
le 14 Juin 2013
0 votes
1 commentaire
Walter Roberson
le 14 Juin 2013
You will need to tell us the rule for deciding what the size of the outputs will be. I have already done my share of analysis of output variable sizes for your routine.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!