I want to do the calculations in the for loop for each diameter, D value, and then draw the graph for each result, but with this code, I calculate one value and only one value appears in the graph. Where am I doing wrong? Sorry I'm beginner in mtlab

3 views (last 30 days)
L=(2000+(5*50))
T=5+5*0.25
It=0.0075*L
ht=0.15*T
bt=0.50*It
e=0.0003*(5+50)
t=15000/sqrt(9.81/ht)
V=It*ht*bt
flwrt=V/t
for D=0.1:0.01:0.5
v=4*flwrt/pi*D
Re=(v*D)/0.00000131
if Re<2300
disp('It is laminar flow')
elseif Re<4000
disp('It is transitition')
else
disp('It is turbulant flow')
end
valvecost=320+(D/25)*200
elbowcost=60+((D/25)*50)
pipecost=((2000+(5*50))/25)*1,5
f=1.325/(log10(e/D*3.7+5.74/Re^0.9))
hp=5+5*0.25+(v^2)/2*9.81*[f*(2000+5*50)/D+8.1]
Ppower=((9.81*1000*flwrt*hp)/1000)
pumpandmotorcost=3700+100*ht
electricitycost=(0.15*(t/3600)*Ppower)
yearelectric=electricitycost*730
plot(D,Ppower)
plot(D,ht)
end

Accepted Answer

David Fletcher
David Fletcher on 16 May 2021
As a general guide have a look at:
L=(2000+(5*50));
T=5+5*0.25;
It=0.0075*L;
ht=0.15*T;
bt=0.50*It;
e=0.0003*(5+50);
t=15000/sqrt(9.81/ht);
V=It*ht*bt;
flwrt=V/t;
iteration=1;
for D=0.1:0.01:0.5
v=4*flwrt/pi*D;
Re=(v*D)/0.00000131;
if Re<2300
disp('It is laminar flow')
elseif Re<4000
disp('It is transitition')
else
disp('It is turbulant flow')
end
valvecost=320+(D/25)*200;
elbowcost=60+((D/25)*50);
pipecost=((2000+(5*50))/25)*1,5;
f=1.325/(log10(e/D*3.7+5.74/Re^0.9));
hp=5+5*0.25+(v^2)/2*9.81*[f*(2000+5*50)/D+8.1];
Ppower(iteration)=((9.81*1000*flwrt*hp)/1000);
pumpandmotorcost=3700+100*ht;
electricitycost=(0.15*(t/3600)*Ppower);
yearelectric=electricitycost*730;
htVals(iteration)=ht;
iteration=iteration+1;
end
plot(0.1:0.01:0.5,htVals)
hold on
plot(0.1:0.01:0.5,Ppower)
If you wish to retain the other loop variables from each iteration (valvecost, elbowcost, pipecost etc.) you will have to adopt a similar strategy tothat of Ppower.

More Answers (0)

Categories

Find more on Graph and Network Algorithms 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!