MATLAB Answers

Pressure drop script is not running

조회 수: 4(최근 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
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by