Question on code to calculate Pipe flow
Mostra commenti meno recenti
Hello,
I am unfortunately not very experienced with matlab but really trying to learn. Below is a code I wrote to calculate Q and head loss through a system of pipes and I'm having several issues:
a) my program will not check each value individually so either it calculates all positive or all negative values.
b) I have no idea how to check for common lines
c) It wont substitute new found values for old ones
please help
thanks
clear;clc;
%IW = 10; % Number of iterations
NL = 3; % Number of loops
NJ = 4; % Number of lines in Ith loop
Km = 1; % minor loss constants
e = .00085;
v = .00001082;
g = 32.2; % gravity constant
i = [1;2;3];% loop numbers
j = [16 10560;12 15840;14 10560;16 15840;16 15840;14 13200;12 10560;16 10560;12 15840;10 15840;12 15840;12 15840];% pipe diameter lengths
D = j(:,1)./12;%pipe diameter in feet
A = ((pi/4)*D.^2);%area of pipes
Q = [3;1.5;-1.6;-4.0;3.8;1.7;.3;-3;1.8;.4;-1;-1.5]; % inital guessed flow rates
V = Q(:,1)./A;
ed = e./j(:,1);%flow rates
Alpha = (8.*j(:,2))./(pi^2*g*D.^5);%alpha calculations
Beta = (8.*Km)./(pi^2*g*D.^4);
SBeta = sum(Beta);
hm = (Q(:,1).^2)*SBeta;
Re = ((abs(V).*D)./v);
for IW =1:5;
if Re>2000
f = (1.325./(log((.00085./((3.7).*D))+(5.74./(Re.^(.9)))).^2))
else
f = 64./Re;
end
if Q(Q(:,1)>0)
Hij = (Alpha.*(Q(:,1)>0).^2.*f)+hm
elseif Q(Q(:,1)<0)
Hij = -1.*(Alpha.*(Q(:,1)<0).^2.*f)+hm
else
continue
end
if Re>=2000
DfDq = ((13.69.*(((e./(3.7*D))+(5.74./(Re.^.9)))).^-1))./(Re.*Q(:,1).*(log((e./(3.7.*D)+(5.74./Re.^.9))).^3))
else
DfDq = -64./Re.*Q(:,1)
end
if Q(Q(:,1)>0)
DhDq =((2.*Alpha.*Q(:,1).*f)+(Alpha.*Q(:,1).*DfDq)+(2*SBeta.*Q(:,1)))
elseif Q((Q(:,1))< 0 )
DhDq =((-2.*Alpha.*Q(:,1).*f)+(Alpha.*Q(:,1).*DfDq)+(2*SBeta.*Q(:,1)))
else
continue
end
SDhDq =sum(DhDq)
DQi = -sum(Hij)/SDhDq
Qnew = Q(:,1)+DQi
if Qnew-Q(:,1)>.0001
break
else
continue
end
syms('Q','Qnew',Q(:,1))
subs(Q,Q(:,1),Qnew)
IW = IW+1
end
Risposte (1)
Image Analyst
il 22 Feb 2015
This
if Q(Q(:,1)>0)
will be ambiguous since Q(:,1)>0 is a logical vector of 12 values. What is your thinking there? What do you want to happen if, say, 4 are >0 and 8 are < 0????
1 Commento
Emma Cusano
il 22 Feb 2015
Modificato: Emma Cusano
il 22 Feb 2015
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!