Only one graph appear instead of two.

3 views (last 30 days)
N/A
N/A on 28 Aug 2022
Answered: dpb on 28 Aug 2022
Hello, so I'm trying to plot a graph using Antoine equation. I was given two equation and was tasked to plot a graph. Unfortunately, when I run the code, only 1 graph appear instead of 2 and I don't know where I go wrong. Help is greatly appreciated. Thank you.
Below is the code I use as reference.
A1=14.895;
B1=-3412.1;
C1=-22.627;
A2=14.751;
B2=-3331.7;
C2=-45.55;
D=30:75; %temperature range required
T=D+273; %converted to Kelvin
log10P=A1-B1./(T+C1); %Antoine's equation
Psat1 = 10.^log10P; %Computing Psat1
log10P=A2-B2./(T+C2); %Antoine's equation
Psat2 = 10.^log10P; %Computing Psat2
plot(D,Psat1,D,Psat2,'.-');
xlabel('Temperature [K]');
ylabel('Pressure [kPa]');
title('Saturation Pressure from Antoine Equation');
plot(T,Psat1,'r');
plot(T,Psat2,'b');
legend('Psat1', 'Psat2')
grid on;

Accepted Answer

Star Strider
Star Strider on 28 Aug 2022
Use the hold function —
A1=14.895;
B1=-3412.1;
C1=-22.627;
A2=14.751;
B2=-3331.7;
C2=-45.55;
D=30:75; %temperature range required
T=D+273; %converted to Kelvin
log10P=A1-B1./(T+C1); %Antoine's equation
Psat1 = 10.^log10P; %Computing Psat1
log10P=A2-B2./(T+C2); %Antoine's equation
Psat2 = 10.^log10P; %Computing Psat2
figure
plot(D,Psat1,D,Psat2,'.-')
hold on % <— ADDED
xlabel('Temperature [K]');
ylabel('Pressure [kPa]');
title('Saturation Pressure from Antoine Equation');
plot(T,Psat1,'r')
plot(T,Psat2,'b')
hold off % <— ADDED
legend('Psat1', 'Psat2', 'Location','best')
grid on;
.

More Answers (1)

dpb
dpb on 28 Aug 2022
You forgot
hold on
to put more on the same axes after the first...
plot(T,Psat1,'r');
hold on
plot(T,Psat2,'b');
title('Saturation Pressure from Antoine Equation');
...
will do the deed -- as will for somewhat more compact code
plot(T,Psat1,'r-',T,Psat2,'b-');
without the need for hold on. Or,
...
D=(30:75).'; % make the independent variable a column vector so results will be, too...
...
hL=plot(T,[Psat1,Psat2]); % use plot() by column inbuilt feature, save line handles
...
For the last, the typical default line colors start with 'r', 'b' so you'll get those by default if that default order hasn't been redefined. It it has, that's the reason saved the line handles; the final step would be
set(hL,{'Color'},{'r';'B'}) % set colors explicitly
All the various syntax options are in the doc for plot; it's far more flexible than simply "one-at-a-time" use.

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!