iterations while in loop

having trouble making this iterate for each increment of Vn, it goes straight to Vn = 30, i want it to also to calc a new Re, f, dPloss_1, Va & Q with each new iteration.
D = 0.1; L = 10; 
A = 0.25*pi*D^2; 
e = 0.0015e-3; 
rho = 998; 
nu = 1.01e-6;  
eoverD = e/D;
alpha = 0.1;
Vo = 2;
for Vn = 2:0.1:30;% iteration length.
%
Re = (Vo.*D) / nu;
%
if Re < 2300
f = 64 / Re;
else
darbyFormula = @(x) 1/sqrt(x)+2*log10(eoverD/3.7 + 2.51/Re/sqrt(x));
f = fzero(darbyFormula,0.01);
end
%
dPloss_1 = (f*rho*(L/D)) * ((Vn*Vo)./2);
Va = (alpha*Vn)+((1-alpha)*Vo);
Q=Va*A;
Vo = Va;
end %

4 件のコメント

David Sanchez
David Sanchez 2013 年 8 月 27 日
what is the problem? Who is D? Do you want to update Re, f, dPloss_1, Va and Q, saving previous values?
harley
harley 2013 年 8 月 27 日
code edited, yes i want it to update at each iteration saving previous values of Re, f, dPloss_1, Va and Q etc.
David Sanchez
David Sanchez 2013 年 8 月 27 日
but what is the problem?
harley
harley 2013 年 8 月 27 日
編集済み: harley 2013 年 8 月 27 日
David actually works fine, sorry for the confusion.

サインインしてコメントする。

 採用された回答

Jan
Jan 2013 年 8 月 27 日

0 投票

No, of course it iterates through 2:0.1:30. You can test this easily either by using the debugger or by a disp(Vn) command inside the loop.
The problem might be, that the result is overwritten in each iteration. So try:
Vn_pool = 2:0.1:30;
Q = zeros(1, length(Vn_pool))); % pre-allocate!!!
for k = 1:length(Vn_pool)
Vn = Vn_pool(k);
...
Q(k) = Va * A; % same for the other values wanted as outputs
end

1 件のコメント

harley
harley 2013 年 8 月 27 日
yes your right, its over writing each iteration, thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2013 年 8 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by