Pressure drop script is not running

2 ビュー (過去 30 日間)
Jayashri Patil
Jayashri Patil 2021 年 9 月 13 日
回答済み: Rik 2021 年 9 月 13 日
clear "all"
clc
N=input('enter the number of different pipe size: ');
for i=1:N
d(i)=input('enter the diamter of pipe %s(m): ',i);
l(i)=input('enter the length of pipe %s(m): ',i);
Kl(i)=input('enter the no of bends %s(m): ',i);
end
rho=input('enter the value of density: ');
v(i)=input('enter the value of v(i): ');
Mu=input('enter the value of viscocity: ');
Q=input('enter the flowrate: ');
eps=input('enter the epsilon: ');
for i=1:N
A(i)=pi*D(i)*D(i)/4;
v(i)=Q/A(i);
ReynoldsNumber1=Rho*v(i)*D(i)/Mu;
if ReynoldsNumber1 <2300
f1=64/ReynoldsNumber1;
elseif ReynoldsNumber1 >4000
c=@(f(i))(1/sqrt f(i))+ 2*(log10((eps/3.7*D(i))+(2.51/(ReynoldsNumber1*sqrt f(i))));
f(i)=fzero(c,[0.01,0.02]);
end
deltap(i)=(f(i)*(L(i)/D(i))*((Rho*v(i)*v(i))/2)/1000); % pressure drop in kpa
KL(i)=sum(KL(i)entrance+KL(i)elbow+KL(i)valve+KL(i)exit);
HL(i)=(f(i)*(L(i)/D(i))+KL(i)*v(i)*v(i)/2*g); %head loss in m
end
  2 件のコメント
Rik
Rik 2021 年 9 月 13 日
What are you trying to do? Did you read the documentation for the input function? You seem to be using it as if it is sprintf.
Jayashri Patil
Jayashri Patil 2021 年 9 月 13 日
I am trying for calculate pressure drop taking different type of diameter from user.but there is error.

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

採用された回答

Rik
Rik 2021 年 9 月 13 日
If you have problems with a function, you should really check the documentation.
The input function does not work like you expect it to. It will not use later input variables to compose a string. You need to use sprintf to do that. You should also add the 's' parameter to your input call. That way you get the actual text your user entered. You can then use str2double to convert to a number. That will prevent users from using variable names that you're using as a parameter.
tmp=input(sprintf('enter the diamter of pipe %d(m): ',i),'s');
tmp=str2double(tmp);
if isnan(tmp)
error('variable entered is not a valid number')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by