Using a loop in a loop Help pls..

조회 수: 2 (최근 30일)
Ernest Yim
Ernest Yim 2015년 12월 8일
편집: John BG 2016년 2월 13일
Help... please a question about using loop inside a loop.
I got a loop which is
N=100;
i=1;
for x=0:c/N:c
if x>=(P*c)
dzdx(:,i)=(M*c/(1-P)^2)*(2*P/c-2*x/c^2);
else
dzdx(:,i)=(M*c/P^2)*(2*P/c-2*x/c^2);
end
i=i+1;
end
x=[0:c/N:c];
%%Using vortex_lattice to get gamma and xj
[gamma, xj] = vortex_lattice(dzdx, x, alpha, vinf, rhoinf, c);)
which i want to find gamma and , xj
I am sure the above code is correct , can i know how should i type if i want this loop run when N=[20:20:640]
following up from the gamma and xj
gamma_total=sum(gamma);
gamma_big=vinf*gamma_total;
% Finding Lift
L=rhoinf*vinf*gamma_big;
% Finding Coefficient of lift
C_lN(n)=L/(0.5*rhoinf*c*vinf^2);
How am I suppose to get 6 different C_lN when N[20,40,80,160,320,640]??

답변 (1개)

John BG
John BG 2015년 12월 8일
편집: John BG 2016년 2월 13일
c=3e8;M=5;P=10 % since you did not define them I gave P and M these values
N=[20:20:640]
gamma_array=[]
xj_array=[]
big_dzdx=zeros(101,32) % 32 out of the 640/20 you want N to sweep through
for j=1:1:numel(N)
i=1;
for x=0:c/N:c
if x>=(P*c)
dzdx(:,i)=(M*c/(1-P)^2)*(2*P/c-2*x/c^2);
else
dzdx(:,i)=(M*c/P^2)*(2*P/c-2*x/c^2);
end
i=i+1;
end
x=[0:c/N:c];
big_dzdx(:,j)=dzdx
%%Using vortex_lattice to get gamma and xj
[gamma, xj] = vortex_lattice(dzdx, x, alpha, vinf, rhoinf, c);)
gamma_array(:,j)=[gamma_array; gamma]
xj_array=[xj_array; xj]
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by