To calculate the thermal efficiency of Otto cycle and to plot P-V diagram of Otto Cycle in Matlab
Theory of Otto Cycle -
Otto cycle is basically used in describing the function of typical spark ignition piston engine.
Otto cycle is also known as constant volume cycle.
Otto Cycle is consist of following process;
Process (1-2) – It is an isentropic compression process in which piston moves from bottom dead centre to top dead centre.
Process (2-3) – It is a head addition process at constant volume
Process(3-4) – It is isentropic expansion process
Process (4-1) – Heat rejection at constant volume
Thermal Efficiency of Otto Cycle –
The theoratical thermal efficiency of otto cycle depends upon the compression ratio and specific heat ratio (gamma) of the gas in the combustion chamber.
Formula of thermal efficiency is as under;
Thermal efficiency = 1 /((compression ratio)^(gamma-1))
Main Code -
% Write a program of to plot PV diagram of Otto cycle using matlab
clear all;
close all;
clc;
% Inputs
gamma = 1.4;
t3= 2000;
% State variables at state point 1
t1=300;
p1=101325;
% Engine Geometric Parameters
bore = 0.1;
stroke = 0.1;
connec_rod_length = 0.15;
compression_ratio = 12;
% Calculate swept volume and clearance volume
swept_volume = (pi/4)*(bore^2)*stroke;
clearance_volume = swept_volume / (compression_ratio-1);
v1=clearance_volume+swept_volume;
v2=clearance_volume;
% State variables at state point 2
% Iscentropic compression for state 1-2 || p1*v1^gamma = p2*v2^gamma
p2 = p1*((compression_ratio)^gamma);
% Ideal Gas Relation - p1*v1/t1 = p2*v2/t2
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gamma;
compressed_volume = piston_kinematics_of_engine(bore,stroke,connec_rod_length,compression_ratio,180,0);
% Calculation of compressed pressure in an iscentropic process
% compressed_pressure*(compressed_volume)=constant_c
compressed_pressure = constant_c./compressed_volume.^gamma;
% State variables at state point 3
% Heat addition at constant volume for state 2-3
v3=v2;
% Ideal Gas Relation - p3/t3 = p2/t2
p3=p2*t3/t2;
% Calculation of expansion pressure in an iscentropic expansion process
% expansion_pressure*(expansion_volume^gamma)=constant_c1
expansion_volume = piston_kinematics_of_engine(bore,stroke,connec_rod_length,compression_ratio,0,180);
constant_c1 = p3*v3^gamma;
expansion_pressure = constant_c1./expansion_volume.^gamma;
% State variables at state point 4
% Heat addition at constant volume for state 1-4
v4=v1;
% Iscentropic expansion for state 3-4 || p3*v3^gamma = p4*v4^gamma
p4 = p3*(v3/v4)^gamma;
% Thermal Efficiency of otto cycle
thermal_efficiency = 1 - (1/(compression_ratio)^(gamma-1));
% Plotting
figure(1);
hold on;
plot(v1,p1,'marker','*','color','r');
plot(compressed_volume,compressed_pressure);
plot(v2,p2,'marker','*','color','r');
plot([v2 v3],[p2 p3],'color','g');
plot(v3,p3,'marker','*','color','r');
plot(expansion_volume,expansion_pressure);
plot(v4,p4,'marker','*','color','r');
plot([v4 v1],[p4 p1],'color','b' );
axis([0 9*10^-4 0 9*10^6]);
grid on;
xlabel('Volume(V)');
ylabel('Pressure(P)');
Function Code -
function [V]=piston_kinematics_of_engine(bore,stroke,connec_rod_length,compression_ratio,start_crank,end_crank)
%crank pin radius
a=stroke/2;
% R = ratio of connecting rod length/a;
R=connec_rod_length/a;
% Calculate swept volume & clearance volume
swept_volume = (pi/4)*(bore^2)*stroke;
clearance_volume = swept_volume/(compression_ratio-1);
theta =linspace(start_crank,end_crank,720);
term1=0.5*(compression_ratio-1);
term2=R+1-cosd(theta);
term3=(R^2 - (sind(theta).^2)).^0.5;
V = (1+term1*(term2-term3)).*clearance_volume;
end
Explanation of code :-
- We have to first initialize the value of engine parameters such as bore, stroke, connecting rod length, compression ratio. Thereafter, we have to define other input parameters such specific heat ratio(gamma), other state variables i.e. p1,t1 and t3.
- Further, we have calculated the swept volume and clearance volume with help of following equation;
swept_volume = (pi/4)*(bore^2)*stroke;
clearance_volume = swept_volume / (compression_ratio-1);
- Furthermore, states variables at state 1 & 2 were calculated.
- Since process(1-2)is isentropic expansion, we have used following equation to calculate the value of pressure p2
p1*v1^gamma = p2*v2^gamma
After re-arranging,
p2 = p1*((compression_ratio)^gamma)
- Further, by using the ideal gas law relation, we have calculated the value of temp t2.
t2 = p2*v2*t1/(p1*v1)
- We define the function piston_kinematics_of_engine in the function subscript and try to calculate the compression volume.
compressed_volume = piston_kinematics_of_engine(bore,stroke,connec_rod_length,compression_ratio,180,0). During compression process,crank angle start from 180 and end to 0 degrees.
- Again, we have used the same isentropic compression relation to calculate compression pressure.
- Since for process(2-3)is heat addition at constant volume, hence v3=v2;
- Further, using ideal gas relation, state variables at state 3 has been calculated.
- We call the function piston_kinematics_of_engine in the function subscript and try to calculate the expansion volume.
expansion_volume = piston_kinematics_of_engine(bore,stroke,connec_rod_length,compression_ratio,0,180).
During expansion process, crank angle start from 0 and end to 180 degrees.
- Similarly, we have used the same isentropic expansion relation to calculate expansion pressure.
- Thereafter, state variables at state 4 has been calculated.
- We have used the formula of thermal efficiency and the same has been computed and the value is thrown in command window.
- Thereafter, plot command has been used to plot all the state variables, colour of line, limit of plot.
- Tried to run the program and got the output as under;
Output P-V diagram plot :-
Thermal Efficiency -

Conclusion :-
- Thermal efficiency of Otto cycle was calculated as 62.99%.
- In P-V diagram of otto cycle, we observed that changes occurred in isentropic process is of curve.