Learn how to plot Diesel Cycle P–V Diagram Using MATLAB
Overview
This script builds a complete pressure–volume diagram of an ideal Diesel cycle. You see all four processes clearly. The model uses standard air assumptions and basic thermodynamic relations.
You all can generete:
- Compression curve
- Heat addition at constant pressure
- Expansion curve
- Heat rejection at constant volume
The result matches the classic Diesel cycle diagram used in thermodynamics.
Key Inputs
The model starts with three core parameters:
gamma = 1.4
Ratio of specific heats for airr = 18
Compression ratio
Higher value increases peak pressure and efficiencyrc = 3
Cut-off ratio
Controls how long heat addition continues
These three values shape the entire cycle.
You all can adjust and set the above value as per your requirement and observe the behavior of PV diagram.
State Point Calculations
We can define four thermodynamic states.
State 1
- Initial condition
V1 = 1,P1 = 1- Used as reference
State 2
- End of compression
- Volume reduces by factor
r - Pressure rises using isentropic relation
State 3
- Heat addition at constant pressure
- Volume increases using cut-off ratio
- Pressure remains constant
State 4
- Expansion back to original volume
- Pressure drops using isentropic relation
These four points define the full cycle.
Process Modeling
Each process is generated using arrays of points.
1–2 Compression
- Isentropic process
- Pressure rises sharply
- Curve bends steeply
P_12 = P1 * (V1 ./ V_12).^gamma;
2–3 Heat Addition
- Constant pressure
- Horizontal line
- Volume increases
3–4 Expansion
- Isentropic expansion
- Pressure drops smoothly
- Longer curve compared to compression
4–1 Heat Rejection
- Constant volume
- Vertical drop in pressure
Plot Construction
The script plots each process with distinct colors:
- Blue: Compression
- Red: Heat addition
- Yellow: Expansion
- Green: Heat rejection
State points are marked using black filled circles. This improves readability.
plot([V1 V2 V3 V4], [P1 P2 P3 P4], 'ko', 'MarkerFaceColor','k');
The script adds light dashed lines to improve interpretation.
Vertical guides
- At
V2,V3, andV1 - Show key volume transitions
Horizontal guides
- At
P2,P4, andP1 - Help compare pressure levels
lineColor = [0.6 0.6 0.6 0.6];
Full code for MATLAB Scripting
clc;clear;close all;% Parametersgamma = 1.4; % specific heat ratior = 18; % compression ratio (V1/V2)rc = 3; % cut-off ratio (V3/V2)% State 1V1 = 1;P1 = 1;% State 2 (after isentropic compression)V2 = V1 / r;P2 = P1 * r^gamma;% State 3 (after constant pressure heat addition)V3 = rc * V2;P3 = P2;% State 4 (after isentropic expansion)V4 = V1;P4 = P3 * (V3 / V4)^gamma;% Process curves% 1-2: isentropic compressionV_12 = linspace(V1, V2, 100);P_12 = P1 * (V1 ./ V_12).^gamma;% 2-3: constant pressureV_23 = linspace(V2, V3, 100);P_23 = P2 * ones(size(V_23));% 3-4: isentropic expansionV_34 = linspace(V3, V4, 100);P_34 = P3 * (V3 ./ V_34).^gamma;% 4-1: constant volumeV_41 = V1 * ones(1,100);P_41 = linspace(P4, P1, 100);% Plotfigure;hold on;plot(V_12, P_12, 'b', 'LineWidth', 2);plot(V_23, P_23, 'r', 'LineWidth', 2);plot(V_34, P_34, 'y', 'LineWidth', 2);plot(V_41, P_41, 'g', 'LineWidth', 2);% Mark pointsplot([V1 V2 V3 V4], [P1 P2 P3 P4], 'ko', 'MarkerFaceColor','k');% Labelsxlabel('Volume');ylabel('Pressure');title('Diesel Cycle P-V Diagram');grid on;% Light guide lines (like in your image)lineColor = [0.6 0.6 0.6 0.6];% Vertical lines at V2 and V3plot([V2 V2], [0 P2], '--', 'Color', lineColor, 'LineWidth', 1);plot([V3 V3], [0 P3], '--', 'Color', lineColor, 'LineWidth', 1);plot([V1 V1], [0 P4], '--', 'Color', lineColor, 'LineWidth', 1);% Horizontal lines at P2 and P4plot([0 V2], [P2 P2], '--', 'Color', lineColor, 'LineWidth', 1);plot([0 V1], [P4 P4], '--', 'Color', lineColor, 'LineWidth', 1);plot([0 V1], [P1 P1], '--', 'Color', lineColor, 'LineWidth', 1);legend('1-2 Compression','2-3 Heat Addition','3-4 Expansion','4-1 Heat Rejection');hold off;
