Pressure drop script is not running
1 view (last 30 days)
Show older comments
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
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.
Accepted Answer
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!