OTTO CYCLE ANALYSIS IN MATLAB
AIM - To simulate an Otto Cycle using MATLAB
OBJECTIVE :-
- Write codes in MATLAB that can solve an otto cycle
- Create a PV diagram
- Output the thermal efficiency of the engine.
THEORY:-
- An Otto cycle is an idealized thermodynamic cycle that describes the functioning of a spark ignition/petrol engine.
- The Otto cycle is a description of what happens to a mass of gas as it is subjected to changes of pressure, temperature, volume, addition of heat, and removal of heat.
- The above figure shows the pressure vs volume or PV diagram of an ideal Otto cycle.
- The whole process occur between four states or conditions of the gas which can be described by its properties such as pressure, temperature and volume. at each of these four points.
- As shown in the figure, the gas undergoes isentropic compression during the process 1-2, constant volume combustion during 2-3, isentropic expansion during 3-4 and constant volume heat rejection during process 4-1
- The compression and expansion processes occur in a piston cylinder arrangement between its top dead centre (TDC) or bottom dead centre (BDC).These were the limits for the movement of the piston.
- State point 3 describes the maximum pressure and temperature of the gas during the cycle.
- From this cycle, one can find the thermal efficiency of the petrol engine with the help of following formula:
- The thermal efficiency is basically the fraction of supplied heat energy which is converted to net work output.It is the parameter to compare the performance of same type of heat engines or as in our case the petrol engines.
CODES :-
%A program to simulate an Otto cycle
clear all
close all
clc
%Inputs = State variables (pressure=pascal,temperature=kelvin)
p1 = 101325;
t1 = 500;
t3 = 2300;
gamma = 1.4;
%Engine parameters (bore=m^2,stroke=m,connecting rod length=m)
%(compression ratio=unitless)
bore = 0.1;
stroke = 0.1;
con_len = 0.15;
cr = 12;
%swept volume & clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clear = v_swept/(cr - 1);
%v1,v2
v1 = v_swept+v_clear;
v2 = v_clear;
%State variables at state point 2
%p1*v1^gamma=p2*v2^gamma, v1/v2 = cr
p2 = p1*cr^gamma;
%(p1*v1)/t1 = (p2*v2)/t2
t2 = (p2*v2*t1)/(p1*v1);
cons_c = p1*v1^gamma;
v_comp = piston_kinematics(bore,stroke,con_len,cr,0,180);
p_comp = cons_c./v_comp.^gamma;
%State variables at state point 3
v3 = v2;
%(p3/p2) = (t3/t2)
p3 = (p2*t3)/t2;
cons_c = p3*v3^gamma;
v_expan = piston_kinematics(bore,stroke,con_len,cr,0,180);
p_expan = cons_c./v_expan.^gamma;
%State variables at state point 4
v4 = v1;
%p3*v3^gamma = p4*v4^gamma
p4 = p3*(v3/v4)^gamma;
%Plotting
hold on
plot(v1,p1,'*','color','r')
plot(v_comp,p_comp,'color','r')
plot(v2,p2,'*','color','r')
plot(v3,p3,'*','color','r')
plot(v_expan,p_expan,'color','r')
plot(v4,p4,'*','color','r')
plot([v2 v3],[p2 p3],'color','r')
plot([v4 v1],[p4 p1],'color','r')
%Output = Thermal efficiency of Otto Cycle
otto_efficiency = 1-(1/cr^(gamma-1))
CODE EXPLANATION:-
- In MATLAB, we started with providing the inputs that we have. which are pressure and temperature at state point 1, temperature at state point 3 which is the maximum temperature and value of 'gamma' which is fixed.
- Now, to find volume of state point 1, we need some engine parameters like bore, stroke, length of connecting rod and compression ratio. Hence, they are defined.
- These engine paramters gives the swept volume and clearance volume through some formulas which are defined. These volumes gave the volumes at state points 1 and 2.
- For state point 2, pressure and temperature are calculated by suitable formulas.
- Now, in order to show variation between states 1 & 2 as well as between 3 & 4, a new function is defined which is termed as piston_kinematics by another codes as shown below:
function [V] = piston_kinematics(bore,stroke,con_len,cr,start_crank,end_crank)
a = stroke/2;
R = con_len/a;
v_s = (pi/4)*bore^2*stroke;
v_c = v_s/(cr-1);
theta = linspace(start_crank,end_crank,180);
term1 = 0.5*(cr-1);
term2 = R+1-cosd(theta);
term3 = (R^2-sind(theta).^2).^0.5;
V=v_c*(1+term1*(term2-term3));
end
- It is a function which takes bore, stroke, length of connecting rod, compression ratio, initial crank angle and final crank angle as inputs.
- The function is defined with some relation in terms of angle 'theta'. The function shows the relation between volume and the angle. Here, as theta is taken in linspace command, it is basically 180 angles between initial and final crank angles.
- The above function is defined to show variation between compression (i.e.,1-2) and expansion (i.e., 3-4) states. It shows the variation of volume in terms of crank angles.
- After calculating properties at state point 4, plotting work is undertaken.
- Then, thermal efficiency is defined with suitable formula.
- On execution of the program, following result is obtained:-
- PV diagram is plotted and thermal efficiency is also calculated. All the points of PV diagram are connected.
ERRORS ENCOUNTERED :-
1)
- This error occured due to wrong order of the equation. In MATLAB, v2 = v3 says that v3 is the value assigned to the variable v2 & v3 is not defined previously.
- The correct code should be v3 = v2
2)
- This error occured due to use of '^' operator instead of elementary '.^' operator, which has to be used for matrix operations.
3)
- This error occured as the angle 'theta' is a taken a single scaler value.
- To plot 'theta' in terms of V, we need a number of values of 'theta'. So, it has to be used with linspace command. The correct code may be theta = linspace(0,180,180)
CONCLUSION - Thus, PV diagram of Otto cycle is plotted and its thermal efficiency is calculated using MATLAB.