Effacer les filtres
Effacer les filtres

Only one graph appear instead of two.

1 vue (au cours des 30 derniers jours)
N/A
N/A le 28 Août 2022
Réponse apportée : dpb le 28 Août 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;

Réponse acceptée

Star Strider
Star Strider le 28 Août 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;
.

Plus de réponses (1)

dpb
dpb le 28 Août 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.

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by