How do i can write a for loop inside a for loop?

I am working on a fluid flow problem i want to find the velocity, Reynolds, darcy friction factor and the loss head.
However, the velocity is function of darcy friction factor and the loss head.
Reynolds and flow rate are functions of velocity.
darcy friction should be calculated by a for loop using Colebrook equation.(1 loop)
I don't have any of: velocity, flow rate, loss and darcy friction factor.

4 件のコメント

Image Analyst
Image Analyst 2020 年 6 月 14 日
If you don't have any of the values, or ranges of values, then you really can't do anything, can you. Not even a loop.
To have a for loop inside a for loop, you can do
for k1 = k1Start : k1Stop
for k2 = k2start : k2stop
% Some code...
end
end
Hussein Rida
Hussein Rida 2020 年 6 月 14 日
can i share my code?
Hussein Rida
Hussein Rida 2020 年 6 月 14 日
function [f,v,Re,q,com] =Darcy_Weisbach_fittingsa(k,total_loss,pump_loss,l,d,r,rho,viscosity)
f0=0.04;
f=zeros(size(total_loss));
com0=12;
for i=1:100
v0=sqrt(((2*9.81*(total_loss+pump_loss-com0))/((f0*(l/(d/1000)))+k)));
Re0=(rho*v0*(d/1000))/(viscosity*0.001);% Convert viscosity from centipoise to Kg/m.s
q0=v0*(pi*(0.10226^2)*0.25);
v(i)=v0;
Re(i)=Re0;
q(i)=q0;
for j=1:length(Re(i))
f0=(-2*log10((r/d)/3.7+2.51/Re(j)/sqrt(f0)))^-2;% used for smooth pipes and fully rough pipes
f(j)=f0;
end
com0=((q(i)*13.3)/(12*1000))^2;
com(i)=com0;
end
v=v(i)
Re=Re(i)
q=q(i)
com=com(i)
if Re<2000
f=64/Re
end
end
darova
darova 2020 年 6 月 15 日
How to run your code

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFluid Dynamics についてさらに検索

製品

リリース

R2019a

質問済み:

2020 年 6 月 14 日

コメント済み:

2020 年 6 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by