hello, i need to plot a graph (n) number of times with an offset of a known number between each line on the graph, note all the lnes should be parallel on the same graph but repeated
2 次查看(过去 30 天)
显示 更早的评论
clear,clc,clf
format short
Q=3.3;
%gamma=8.43 kN/m3 = 859.62076503 Kg/m3 (*1000/9.81)
rouh=859.62076503;
g=9.81;
Gamma=(rouh.*g);
Zs=0;
Ze=0;
L=1285000;
Ks=(0.000045);
Er=(1.*10.^-8);
viscosity=(3.83.*10.^-3);
% material grade X70
strength= 482000000;
%API 5L
D5L=[12.75*0.0254 14*0.0254 16*0.0254 18*0.0254 20*0.0254 22*0.0254 24*0.0254 26*0.0254 28*0.0254 30*0.0254 32*0.0254 34*0.0254 36*0.0254 38*0.0254 40*0.0254 42*0.0254 44*0.0254 46*0.0254 48*0.0254 52*0.0254 56*0.0254 60*0.0254 64*0.0254 68*0.0254 72*0.0254 76*0.0254 80*0.0254]
V5L=((4.*Q)./(pi.*D5L.^2));
V=V5L(V5L > 1 & V5L < 4.5)
Do=((4.*Q)./(pi.*V)).^(0.5)
Re=(V.*Do./viscosity)
Fo=0.01;
for I=0:1:10^6;
Fn=(1./(-4.*log10((Ks./(3.71.*Do))+((1.26)./(Re.*sqrt(Fo)))))).^2;
E=abs((Fn-Fo)/Fn);
if E<=Er;
Fn=Fn(end),display(E),break,
end
if E>Er;
Fo=Fn;
end
end
Hloss=((Fn.*L.*Q.^2)./(12.*Do.^5))
Hpump=Hloss+Ze-Zs
PRESSURE=rouh.*g.*Hpump.*10.^(-5)
numberofpumps=ceil(PRESSURE./90)
pressureperpump=(PRESSURE./numberofpumps)
Distancebetweeneachpump=L./numberofpumps
%calculating Hloss every 128500M
n=numberofpumps
LC=1:128500:1285000;
for i=1:1:length(LC);
HlossN=((Fn.*LC(i).*Q.^2)./(12.*Do.^5))
TEL(i,:)=(Hpump-HlossN+Zs)
HGL(i,:)=(TEL(i,:)-((V.^2)./(2.*g)))
PE=Gamma.*(HGL-Ze)
T=((PE(i).*Do)./(2.*strength))
end
n=numberofpumps
for ii=1:1:length(Do)
subplot(4,4,ii)
plot(LC,TEL(:,ii))
hold on
plot(LC,HGL(:,ii))
xlabel('LC')
ylabel('HGL & TEL')
end
....
please note that the the number of lines that should be available per graph is the (number of pumps)--line 37
and each line should be (distance between each pump)--line 39 away from the line before it.
it should look like that
0 个评论
采纳的回答
Cris LaPierre
2019-1-30
17 个评论
Cris LaPierre
2019-2-1
编辑:Cris LaPierre
2019-2-1
Ok, I dug in. I think you are making a mistake with your x values. You use all values of LC each time you plot a line segment. I think you need to have length(Do) number of points between each pump over a distance of dx, and numberofpumps line segments.
I assume the pumps are the cause of the vertical lines, and therefore should occur every dx. I also assume that the peaks should be gradually dropping as there will be some irrecoverable losses.
Not to thoroughly confuse you, but I've taken advantage of some linear algebra tricks to write this code:
Q=3.3;
%gamma=8.43 kN/m3 = 859.62076503 Kg/m3 (*1000/9.81)
rouh=859.62076503;
g=9.81;
Gamma=rouh*g;
Zs=0;
Ze=0;
L=1285000; % meters
Ks=0.000045;
Er=1E-8;
viscosity=3.83E-3;
% material grade X70
strength= 482000000;
%API 5L
D5L=0.0254 * [12.75 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 52 56 60 64 68 72 76 80]
V5L=(4*Q./(pi*D5L.^2));
V=V5L(V5L > 1 & V5L < 4.5)
Do=((4*Q)./(pi*V)).^(0.5)
Re=(V.*Do/viscosity)
Fo=0.01;
for I=0:1:10^6
Fn=(1./(-4.*log10((Ks./(3.71*Do))+(1.26./(Re.*sqrt(Fo)))))).^2;
E=abs((Fn-Fo)/Fn);
if E<=Er
Fn=Fn(end);
display(E);
break
end
if E>Er
Fo=Fn;
end
end
Hloss=((Fn.*L.*Q.^2)./(12.*Do.^5))
Hpump=Hloss+Ze-Zs
PRESSURE=rouh.*g.*Hpump.*10.^(-5)
numberofpumps=ceil(PRESSURE./90)
pressureperpump=(PRESSURE./numberofpumps)
Distancebetweeneachpump=L./numberofpumps
%calculating Hloss
for i=1:length(Distancebetweeneachpump)
dx = Distancebetweeneachpump(i);
LC=1:dx:L; % meters
HlossN=(Fn*LC*Q.^2)./(12*Do.^5)';
TEL=Hpump'-HlossN+Zs;
HGL=TEL-(V.^2)'/(2*g);
PE=Gamma*(HGL-Ze);
T=(Do*PE)/(2*strength);
X=[];
for p = 1:numberofpumps(i)
X=[X linspace(LC(p),LC(p)+dx,length(Do))];
end
subplot(4,4,i)
hold on
plot(X,TEL(:))
plot(X,HGL(:))
hold off
xlabel('LC')
ylabel('HGL & TEL')
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202291/image.png)
Cris LaPierre
2019-2-1
Since the linear algebra tricks at the end may be confusing, here is code that yields the same result but done using the syntax and variables you used
for i = 1:length(Distancebetweeneachpump)
X=[]; Y1=[]; Y2=[];
dx = Distancebetweeneachpump(i);
LC = 1:dx:L;
for ii = 1:length(LC)
HlossN=((Fn.*LC(ii).*Q.^2)./(12.*Do.^5));
TEL(ii,:)=(Hpump-HlossN+Zs);
HGL(ii,:)=(TEL(ii,:)-((V.^2)./(2.*g)));
PE(ii,:)=Gamma.*(HGL(ii,:)-Ze);
T(ii,:)=((PE(ii,:).*Do)./(2.*strength));
X=[X linspace(LC(ii),LC(ii)+dx,length(Do))];
Y1 = [Y1 TEL(ii,:)];
Y2 = [Y2 HGL(ii,:)];
end
subplot(4,4,i)
hold on
plot(X,Y1)
plot(X,Y2)
hold off
xlabel('LC')
ylabel('HGL & TEL')
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!