Pressure drop script is not running

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by