running a summation function for different values of N
2 ビュー (過去 30 日間)
古いコメントを表示
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');
0 件のコメント
採用された回答
Walter Roberson
2013 年 6 月 14 日
編集済み: Walter Roberson
2013 年 6 月 14 日
At the line you are encountering the error, your "iN" is going to be a scalar. You are assigning to "result(iN)" which designates a scalar location. You would get the error,
??? 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 the cast that what is on the right hand side does not return a scalar.
So we need to examine what is on the right hand side. The function declaration is
function[An,CL,delta,CDi,Gamma,Cl]=LLT_type2(b,N,c,a,alpha,alphaoL,e,AR)
outputs are assigned positionally, and since you only use one of the outputs, the one output that will be assigned to "result(iN)" is going to be the value of what is named "An" inside the function.
As we look back from the end of the function LLT_type2, we see that "An" is assigned a value in the statement,
An=IC\RHS
What size is that? Well, IC is N by N, and RHS is ... ah, we cannot tell hat size RHS is with the information given. If the c, a, alpha, alphaoL are all scalars then RHS is N by 1, but the code would also work if those variables start out as column vectors of the same size P by 1, in which case RHS would be N by P.
If the noted variables were scalars, then
(N by N) \ (N by 1)
would have a result that was (N by 1), a column vector. That would only be able to fit into the scalar result(iN) if N was 1.
If the noted variables were P x 1 column vectors, then
(N by N) \ (N by P)
would have a result that was N by P... which is not going to fit into the scalar result(iN) unless N and P are both 1.
I could show you have to construct "result" to be the right size to allow assignment from the loop, but somehow I suspect that you do not really want an to be the value returned from the function. Gamma or C1 look more plausible as the result you would want returned.
0 件のコメント
その他の回答 (1 件)
Christopher
2013 年 6 月 14 日
編集済み: Christopher
2013 年 6 月 14 日
1 件のコメント
Walter Roberson
2013 年 6 月 14 日
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.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!