Plotting a PV curve for Otto cycle and calculating its thermal efficiency
Aim: - To write code in MATLAB that can create a PV diagram for an otto cycle and give thermal efficiency of the engine.
Governing physics and formulae: - The Otto cycle is a set of processes used by spark ignition internal combustion engines (2-stroke or 4-stroke cycles). It consists of four processes added with intake of air fuel mixture at constant pressure pressure and exhaust at the same. The steps of the cycle is as follow
- Air fuel mixture enters the engine block through point 1 at constant pressure.
- From 1-2 ,the mixture is compressed as isentropic process which raises the temperature and pressure governed by equation:- `PV^γ=mRT`
Where P is pressure is volume, is specific heat ratio (Cp/Cv) ,m is mass of Air fuel mixture is gas constant and T is temperature
Where Q is heat added and Cv is specific heat at constant volume.
Also, since isochoric process P∝T
-
From 2-3, the mixture is ignited by spark ignition and chemical energy of fuel is converted into mechanical energy at constant volume. The amount of heat added is given by
-
From 3-4, expansion stroke takes place and the piston is pushed due to increase in pressure by combustion and it is a isentropic process
-
From 4-1, heat is rejected from the engine block at constant volume. the temperature and pressure decreases. The heat loss in this process is given by
-
Then the exhaust gas is released in the atmosphere at constant pressure

The starting point is the general expression for the thermal efficiency of a cycle:

The convention, as previously, is that heat exchange is positive if heat is flowing into the system or engine, so QL is negative. The heat absorbed occurs during combustion when the spark occurs, roughly at constant volume. The heat absorbed can be related to the temperature change from state 2 to state 3 as:
The heat rejected is given by (for a perfect gas with constant specific heats)

Substituting the expressions for the heat absorbed and rejected in the expression for thermal efficiency yields

We can simplify the above expression using the fact that the processes from 1 to 2 and from 3 to 4 are isentropic:

The quantity V1/V2 = cr is called the compression ratio. In terms of compression ratio, the efficiency of an ideal Otto cycle is:

The expression for finding intermediate value of volume and pressure in isentropic process is
`V/(V_c)=1+1/2 (cr-1)[R+1-cosƟ-(R^2-(sinƟ)^2 )^(1/2)`
Here V is the intermediate volume, Vc is clearance volume is the compression ratio, R is ratio of connecting rod and crank length (i.e. half of stroke length) and Ɵ is instantaneous crank angle.
Since `PV^gamma`= constant
Putting the value of volume, gamma (i.e. 1.4) and constant we can get the instantaneous pressure.
Objective: - the program will provide following data
- A PV plot for otto cycle.
- Calculate Pressure, temperature and volume at all thermodynamic state.
- It also gives thermal efficiency of the cycle.
Content:-The programming language used is C and the program is written in MATLAB.The code for the program is-
%program to solve a otto cycle ,get pv plot and thermal efficiency
close all
clear all
clc
%input data given in problem
cr=9;
p1=100000; %pressure in pascal
t1=293; %temp in kelvin scale
t4=800;
gamma=1.4;
%dimension of cylinder and rod
bore=.08;
st_len=.1;
conn_rod=.15;
%calculating swept volume
vs=(pi/4)*bore^2*st_len
vc= vs/(cr-1)
%calculating data of 1st state
v1=vc+vs;
%calculating data of 2nd state
v2=vc;
p2=p1*cr^gamma;
t2=t1*cr^(gamma-1);
%values for isentropic curve between 1and 2
const1=p1*v1^gamma;
v_compression = v_variation(.08,.1,.15,9,180,0);
p_compression=const1./(v_compression.^gamma);;
%calculating data of 4th state
v4=vc+vs;
p4=(t4/t1)*p1;
%calculating data of 3rd state
v3=vc;
p3=p4*cr^gamma;
t3=t4*cr^(gamma-1);
%values of isentropic curve between 3 and 4
const2=p3*v3^gamma;
v_expansion = v_variation(bore,st_len,conn_rod,cr,0,180);
p_expansion=const2./(v_expansion.^gamma);
%displaying state into table
pv=[v1 v2 v3 v4;p1 p2 p3 p4;t1,t2,t3,t4];
PV=array2table(pv,'RowNames',{'volume','pressure','temperature'},'VariableNames',{'state1','state2','state3','state4'})
%calculating thermal efficiency
eff=(1-((t4-t1)/(t3-t2)))*100;
fprintf('The thermal efficiency of the otto cycle is %.2f%%',eff)
figure(1)
hold on
%plotting the points
plot(v1,p1,'.','color','k')
plot(v2,p2,'.','color','k')
plot(v3,p3,'.','color','k')
plot(v4,p4,'.','color','k')
%giving respective points to the stages
text([v1,v2,v3,v4],[p1,p2,p3,p4],{'1','2','3','4'})
xlabel('volume')
ylabel('pressure')
title('otto cycle plot')
%ploting lines and curve between stages representing the process
z1=plot(v_compression,p_compression,'color','c');
z2=plot([v2,v3],[p2,p3],'color','m');
z3=plot(v_expansion,p_expansion,'color','r');
z4=plot([v4,v1],[p4,p1],'color','k');
legend([z1,z2,z3,z4],{'1-2 -> isentropic compression','2-3 -> const vol. heat addition','3-4 -> isentropic expansion','4-1 -> const vol. heat rejection'})
A function is called in this program which return the values of intermediate volumes point inbetwwen the isentropic process
the code for the function is:-
function [V]=v_variation(bore,st_len,conn_rod,cr,st_crnk,end_crnk)
a=st_len/2;
R=conn_rod/a;
%calculating swept volume
vs=(pi/4)*bore^2*st_len;
vc= vs/(cr-1);
th=linspace(st_crnk,end_crnk,180);
%formulae for volume vs crank angle is
%v/vc=1+.5(cr-1)[R+1-cosd(th)-(r^2-sin(th)^2)^.5]
V = (1+.5*(cr-1)*(R+1-cosd(th)-(R^2-sind(th).^2).^.5)).*vc;
end
For the above code to run we are provided with pressure and temperature for 1st state and temperature of 4th state is provided. The compression ratio along with the dimension of the IC engine is also provided ie bore dia ,stroke length ,connecting rod length.
Using the dimension of engine we first calculate the swept volume ie
Vs = `pi/4 D^2 L`
Vc(clearence volume)=`V_s/(cr-1)`
Then we calculate pressure ,temperature and volume of each state to mark the end point on the plot as well as to display the values in a table format on the command window.
To plot the process we use the function v_variation which takes bore dia ,stroke length,cr,starting crank angle and end crank angle .this function is used twice once for isentropic compression and other for isentropic expansion.
Results:-
After running the code we get following output on command window

In the above figure we can see the values of clearence volume,swept volume,tabular form of the pressure ,temp.,volume of each state and finally we get the efficiency of the engine
The plot of the otto cycle is :-

ERROR FACED WHILE WRITING THE CODE AND COMPILING IT:-
1.while calling the function the output argument was not assigned a value the valued was assigned to a different variable hence the problem was caused

Problem was solved when the the output value is assigned to correct variable
- while calculating the instantaneous volume and pressure of expansion process, the values of constant was taken same as the compression therefore both overlap and following plot was in th result
once the errors are rectified the correct plot and values are obtained
CONCLUSION:- The plot for the otto cycle is made and the efficiency of the cycle is 58.48%.