MATLAB: Plotting a p-V diagram

p-vthermodynamics

I need to plot a p-V diagram for an ideal cycle using the ideal gas law: pV=mRT
Ive chosen arbitrary values of 373K and 273K for the max and min temperatures, 5kg for the mass, 0.2871 for R and [p1, V1] is [7.8378, 50]. Using this I can calculate the values for [p2 V2], [p3 V3] and [p4 V4]. However I need [p1 V1] and [p2 V2] to be connected by an isothermal and the same for [p3 V3] and [p4 V4]. Does anyone know how I can do this?? The plot should look like this:
p-V.png
Many thanks!

Best Answer

I’ve not considered this since senior Thermodynamics (back in the phlogiston era).
This should get you started:
Tv1 = linspace(273, 323, 10);
Tv2 = linspace(323, 373, 10);
Vv1 = linspace(150, 200, 10);
[T1m,V1m] = ndgrid(Tv1,Vv1);
[T2m,V1m] = ndgrid(Tv2,Vv1);
R = 0.2871;
m = 5;
% p1 = 7.8378;
% V1 = 50;
p = @(T,V) m*R*T./V;
figure
surf(T1m, V1m, p(T1m,V1m))
hold on
surf(T2m, V1m, p(T2m,V1m))
hold off
grid on
xlabel('T')
ylabel('V')
zlabel('p')
view(90,0)
figure
plot(Vv1, p(Tv1,Vv1), 'LineWidth',2)
hold on
plot(Vv1, p(Tv2,Vv1), 'LineWidth',2)
plot(Vv1(1)*[1 1], p([Tv1(1) Tv1(end)],[1 1]*Vv1(1)), '-g', 'LineWidth',2)
plot(Vv1(end)*[1 1], p([Tv2(1) Tv2(end)],[1 1]*Vv1(end)), '-g', 'LineWidth',2)
hold off
grid
xlabel('V')
ylabel('p')
axis([125 225 2.0 3.3])
legend('T(273 - 323)', 'T(323 - 373)')
If you want to plot the arrows, use the quiver function. You may need to change the plot arguments in figure(2) to get the correct directions.
Make any necessary changes to get the result you want.
Plotting a p-V diagram - 2019 11 04.png