Combining lines into one graph.
1 view (last 30 days)
Show older comments
Hi,
I have plotted the code below, and no errors occur. I would like to combine subplots 1 to 5 on a single graph. When I had tried doing this replacing it with the directly below. The graph I get for volume is different to the graph I get for volume when i plot them separately. Any help would be appreciated.
figure
hold on
plot(t,x(:,1));
plot(t,x(:,2));
plot(t,x(:,3));
plot(t,x(:,4));
plot(t,x(:,5));
xlabel('Time (hr)');
ylabel('Concentration (kmol/m3)');
legend('x1','x2','x3','x4','x5');
hold off
subplot(2,2,5);
plot(t,x(:,5));
xlabel('Time (hr)');
ylabel('V (m3)');
title('Volume');
%MATLAB SYMBOL DESCRIPTION IC Units
%x(1) X Cell Concentration 50 kg/m3
%x(2) Sx Substrate (Xylose) Concentration 23.8 kg/m3
%x(3) Sg Substrate (Glucose) Concentration 42.9 kg/m3
%x(4) P Product Concentration 0 kg/m3
%x(5) G Glycerol Concentration 0 kg/m3
%x(6) V Volume 70 m3
ic = [50;23.8;42.9;0;0;70];
%MATLAB PARAMETER DESCRIPTION Value UNITS
%mumax mu_{max} Maximum Growth Rate 0.2 1/hour
%Ks K_s Monod Constant 2 kg/m3
%Yxs Y_{X/Sx} Cell Yield 0.58 kg/kg
%Ygs Y_{X/Sg} Cell Yield 0.41 kg/kg
%Ypx Y_{P/X} Product Yield 0.2 kg/kg
%Yxo Y_{O/X} Glycerol Yield 2.46 kg/kg
%Sf S_f Feed Substrate Concentration 66.7 kg/m3
%Kp K_p Product Inhibition 97.9 kg/m3
mumax = 0.20;
Ks = 2;
Yxs = 0.58;
Ygs = 0.41;
Ypx = 0.2;
Yxo = 2.46;
Sf = 66.7;
Kp = 97.9;
mu1 = @(Sx,P) (mumax*(Sx)./(Ks + Sx))*sqrt(1 -(P/Kp)); % Monod Equation for xylose
mu2 = @(Sg,P) (mumax*(Sg)./(Ks + Sg))*sqrt(1 -(P/Kp)); % Monod Equation for glucose
rg1 = @(X,Sx,P) mu1(Sx,P)*X; % Rate of cell growth from xylose
rg2 = @(X,Sg,P) mu2(Sg,P)*X; % Rate of cell growth from glucose
rp = @(X,Sx,Sg,P) (Ypx*rg1(X,Sx,P)+Ypx*rg2(X,Sg,P)); % Rate of ethanol formation
rpg = @(X,Sx,Sg,P) (Yxo*rg1(X,Sx,P)+Yxo*rg2(X,Sg,P)); % Rate of glycerol formation
F = @(t) 6337.7
dXV = @(t,x) x(6)*(rg1(x(1),x(2),x(4)) + (rg2(x(1),x(3),x(4))));
dPV = @(t,x) x(6)*rp(x(1),x(2),x(3),x(4));
dSxV = @(t,x) F(t)*Sf - x(6)*rg1(x(1),x(2),x(4))/Yxs;
dSgV = @(t,x) F(t)*Sf - x(6)*rg2(x(1),x(3),x(4))/Ygs;
dGV = @(t,x) x(6)*rpg(x(1),x(2),x(3),x(5));
dV = @(t,x) F(t);
dX = @(t,x) (dXV(t,x) - x(1)*dV(t,x))/x(6);
dSx = @(t,x) (dSxV(t,x) - x(2)*dV(t,x))/x(6);
dSg = @(t,x) (dSgV(t,x) - x(3)*dV(t,x))/x(6);
dP = @(t,x) (dPV(t,x) - x(4)*dV(t,x))/x(6);
dG = @(t,x) (dGV(t,x) - x(5)*dV(t,x))/x(6);
f = @(t,x) [dX(t,x); dSx(t,x); dSg(t,x); dP(t,x); dG(t,x); dV(t,x)];
tspan = [0 65];
[t,x] = ode45(f,tspan,ic);
subplot(3,2,1);
plot(t,x(: , 1));
xlabel('Time (hr)');
ylabel('X (kg/m3)');
title('Cell Concentration');
subplot(3,2,2);
plot(t,x(:, 3));
xlabel('Time (hr)');
ylabel('Xylose (kg/m3 )');
title('Xylose Concentration');
subplot(3,2,3);
plot(t,x(:,2));
xlabel('Time (hr)');
ylabel('Glucose (kmol/m3)');
title('Substrate Concentration');
subplot(3,2,4);
plot(t,x(:,4));
xlabel('Time (hr)');
ylabel('Ethanol (m3)');
title('Ethanol Concentration');
subplot(3,2,5);
plot(t,x(:,5));
xlabel('Time (hr)');
ylabel('Glycerol (m3)');
title('Concentration');
subplot(3,2,6);
plot(t,x(:,6));
xlabel('Time (hr)');
ylabel('V (m3)');
title('Volume');
0 Comments
Answers (1)
Luna
on 23 Jan 2019
Hi,
Check what you are plotting in the first section and last section.
First section:
subplot(2,2,5);
plot(t,x(:,5)); % here you are plotting 5th column of X
xlabel('Time (hr)');
ylabel('V (m3)');
title('Volume');
The second section :
subplot(3,2,6);
plot(t,x(:,6)); % here you are plotting 6th column of X
xlabel('Time (hr)');
ylabel('V (m3)');
title('Volume');
One of them is not Volume.
3 Comments
Luna
on 23 Jan 2019
After your solver use this:
tspan = [0 65];
[t,x] = ode45(f,tspan,ic);
%%
figure;
legendLabels = {'X (kg/m3)','Xylose (kg/m3 )','Glucose (kmol/m3)','Concentration','Glycerol (m3)'};
hold on;
plot(t,x(:,1));
plot(t,x(:,2));
plot(t,x(:,3));
plot(t,x(:,4));
plot(t,x(:,5));
legend(legendLabels);
title('Some Chemical Things');
xlabel('Time (hr)');
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!