Pressure drop script is not running

1 view (last 30 days)
Jayashri Patil
Jayashri Patil on 13 Sep 2021
Answered: Rik on 13 Sep 2021
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 Comments
Rik
Rik on 13 Sep 2021
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 on 13 Sep 2021
I am trying for calculate pressure drop taking different type of diameter from user.but there is error.

Sign in to comment.

Accepted Answer

Rik
Rik on 13 Sep 2021
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!