Otto Cycle using MATLAB
- AIM :
- To write a program to solve an Otto cycle and make plots for it using MATLAB.
- OBJECTIVE :
- The objective of this project is to plot a Pressure vs Volume diagram of Otto Cycle which indicates the volume trace inside an internal combustion engine during its different strokes.
- FORMULA USED :
a = Stroke / 2
R = Connecting Rod Length / a
`η` = `1- 1/((C.R)^(γ-1) )`
`V/V_c = 1+0.5*(C.R-1)*(R+1- cosθ )- √(R^2 -sinθ^2 )`
4. BODY OF CONTENT :
- Inputs :
- We start the program by providing some inputs such as initial pressure (p1) & temperature (t1).
- Engine parameters such as bore, stroke, connecting rod length and compression ratio are also specified.
- The swept volume and clearance volume can be calculated by the above data provided.
- The value of is assumed to be 1.4 and the temperature (t3) at state 3 is also specified.
b. Equations :
- For state 1, volume (v1) is the sum of clearance and swept volumes.
- For state 2, volume (v2) is equal to the clearance volume. The pressure (p2) & temperature (t2) can be computed by equation for isentropic compression and the ideal gas equation respectively.
- For state 3, volume (v3) = volume (v2) and temperature (t3) is already mentioned. The pressure (p3) can be is evaluated using the ideal gas equation.
- For state 4, volume (v4) = volume (v1) and the pressure (p4) can be determined using equation for isentropic expansion.
c. Function :
- In order to get a curved path for both isentropic compression and expansion process, we need to use a function command. After defining this function, we can call it in our above program to get a curved path joining state 1, state 2 and state 3, state 4.
- The function includes all the engine parameters mentioned above along with the start and end crank angle.
- The crank angle theta can be defined as an array of values varying from 0 to 180. The crank angle varies from 180 to 0 in case of compression stroke while it varies from 0 to 180 in expansion stroke.
- We use a formula for volume trace in I.C Engine. The equation is split up into 3 different terms – term 1, term 2 and term 3 respectively for our convenience.
- We store the value of this function in two different variables V_compression and V_expansion respectively for different ranges of crank angle (180 to 0 and 0 to 180).
- We can insert V_compression after state 2 and V_expansion after state 3 to get the appropriate result.
- We also create two variables named P_compression and P_expansion respectively using the equation p*v = constant.
d. Plotting :
- We can plot all the points using the values of volume and pressure at each state.
- The curved path can be obtained by plotting the variables of compression and expansion stroke which is stored from the function.
- The straight path joining state 2, state 3 and state 4, state 1 can be obtained just by plotting pressure and volume at each state.
- A hold on command must be used in order to plot all points in the same figure.
e. Thermal Efficiency :
- The thermal efficiency of Otto cycle increases with increase in compression ratio of the engine.
- Considering the compression ratio to be 12, using the above formula we can calculate the thermal efficiency of I.C Engine.
5. CODE :
Coding for Otto Cycle :
close all
clear all
clc
% Inputs
gamma = 1.4;
t3 = 2000;
% Initial parameters
p1 = 101325;
t1 = 500;
% Engine Kinematics parameters
bore = 0.2;
stroke = 0.25;
con_rod = 0.15;
cr = 12;
% Swept and clearance Volume
vs = (pi/4)*bore^2*stroke;
vc = vs/(cr-1);
% State 1 variables
v1 = vs + vc;
v2 = vc;
% State 2 Variables | p1*v1^gamma = p2*v2^gamma | cr = (v1/v2)
p2 = p1*(cr)^gamma;
% For isentropic compression process | p1*v1/t1 = p2*v2/t2
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gamma;
V_compression = otto_cycle_challenge(bore,stroke,con_rod,cr,180,0);
P_compression = constant_c./V_compression.^gamma;
% State 3 Variables | p3*v3/t3 = p2*v2/t2
v3 = v2;
p3 = p2*t3/t2;
constant_c = p3*v3^gamma;
V_expansion = otto_cycle_challenge(bore,stroke,con_rod,cr,0,180);
P_expansion = constant_c./V_expansion.^gamma;
% State 4 Variables | p3*v3^gamma = p4*v4^gamma
v4 = v1;
p4 = p3*(v3/v4)^gamma;
figure(1);
hold on
% Plotting
plot(v1,p1,'*','color','g');
plot([v2 v3],[p2 p3],'color','g');
plot(v2,p2,'*','color','g');
plot(V_compression,P_compression,'color','g');
plot(v3,p3,'*','color','g');
plot(V_expansion,P_expansion,'color','g');
plot(v4,p4,'*','color','g');
plot([v4 v1],[p4 p1],'color','g');
xlabel('Volume')
ylabel('Pressure')
% Thermal Efficiency Calculation
term4 = (cr)^(gamma-1);
thermal_eff = 1 - (1/term4);
Coding for function :
function [V] = otto_cycle_challenge(bore,stroke,con_rod,cr,start,ending)
a = stroke/2;
R = con_rod/a;
% Swept and clearance Volume
vs = (pi/4)*bore^2*stroke;
vc = vs/(cr-1);
theta = linspace(start,ending,180);
term1 = 0.5*(cr-1);
term2 = R + 1 - cosd(theta);
term3 = ((R^2 - sind(theta).^2).^0.5);
V = (1+(term1*(term2-term3)))*vc;
end
6. OUTPUT :
Initial plot :
Final plot :
f. Thermal Efficiency :