PLOTING of OTTO CYCLE using MATLAB CODES
Aim :
- To plot the PV diagram for an Otto cycle using MATLAB code.
- To find the thermal efficiency of the engine.
Governing Equations:
The Otto cycle is a gas power cycle used in spark ignition engine. A very common example is a modern petrol engine. The compression ratio in these engines ranges between 7 to 10. The cycle consists of four processes which basically represents the movement and position of the piston in the combustion chamber of an ICE.
It consists of four process as follows:
- Isentropic (reversible adiabatic) compression
- Constant volume (Isochoric) heat addition
- Isentropic (reversible adiabatic) Expansion
- Constant volume heat rejection
The P-V diagram and the T-S diagram of the Otto cycle can be seen below:
Here,
P1, P2, P3, P4 are pressures at stages 1, 2, 3, 4 respectively
V1, V2, V3, V4 are volumes at stages 1, 2, 3, 4 respectively
T1, T2, T3, T4 are temperatures at stages 1, 2, 3, 4 respectively
S1, S2, S3, S4 are entropies at stages 1, 2, 3, 4 respectively
Compression Ratio is given as:
`r=frac{V1}{V2}`
For process 1-2:
`frac{P1){P2}=r^γ`
Also,
`frac{T2}{T1}=r^γ`
For process 2-3:
`frac{P2V2}{T2}=frac{P3V3}{T3}`
Also,
`V2=V3`
For process 3-4:
`frac{P3}{P4}=r^γ`
Also,
`frac{T3}{T4}=r^γ`
For Process 4-1:
`frac{P4V4}{T4}=frac{P1V1}{T1}`
Also,
`V4=V1`
The thermal efficiency is given as:
`η=1-frac{(T4-T1)}{(T3-T2)}`
Or as,
`η=1-frac{1}{r^(γ-1)}`
Objective of the project:
- To understand the basic working and application of Otto Cycle
- To plot the P-V diagram using the MATLAB codes
- To implement the above formulas into MATLAB to get the thermal efficiency calculated
Body of the content:
Here we are going to see the use of MATLAB codes and the logics use in it for our objectives to be achieved. Here we are going to first create a function to define some inputs data which we are going to use a few times for our functions to work and this reduces our work as well. The function codes is used to determine the intermediate cylinder volumes at different stages. We will use the same above list of formulas as logics to generate the codes lines in MATLAB.
Below you can find the Function Code:
function[V]=engine_kinamatics(bore, stroke, con_rod, cr, start_crank, end_crank)
a=stroke/2;
R=con_rod/a;
%calculating the swept volume and clearance volume
v_s=(pi/4)*bore^2*stroke;
v_c=v_s/(cr-1);
theta=linspace(start_crank,end_crank,100);
term1=0.5*(cr-1);
term2=R+1-cosd(theta);
term3=(R^2-sind(theta).^2).^0.5;
V=(1+term1*(term2-term3))*v_c;
end
Below are the codes for calculating thermal efficiency and plotting the PV diagram:
clear all
close all
clc
%inputs : intial datas to start with
gamma=1.4;
T3=2300;
P1=101325;
T1=500;
%engine gometric parameters
bore=0.1;
stroke=0.1;
con_rod=0.15;
cr=12;
% formulas for swept volume and clearence volume
v_swept=(pi/4)*bore^2*stroke;
v_clerance=v_swept/(cr-1);
%Stroke 1: Intake
% total air volume in the cylinder:V1
V1=v_swept+v_clerance;
% air in the cylinder head chamber:V2
V2=v_clerance;
%stroke 2: Compression
P2=P1*cr^gamma;
T2=P2*V2*T1/(P1*V1);
constant_c=P1*V1^gamma;
V_compression=engine_kinamatics(bore, stroke, con_rod,cr, 180,0);
P_compression=constant_c./V_compression.^gamma;
% stroke 3:Expansion
V3=V2;
P3=P2*T3/T2;
constant_c=P3*V3^gamma;
V_expansion=engine_kinamatics(bore, stroke, con_rod,cr, 0,180);
P_expansion=constant_c./V_expansion.^gamma;
% stroke 4: Exhaust
V4=V1;
P4=P3*(V3/V4)^gamma;
% thermal efficiency
Thermal_Efficieny_of_the_Engine= (1-(1/(cr^(gamma-1))))*100
figure(1)
hold on
plot(V1,P1,'*','color','r')
plot(V_compression,P_compression,'g')
plot(V2,P2,'*','color','r')
plot([V2 V3],[P2 P3],'b')
plot(V3,P3,'*','color','r')
plot(V_expansion,P_expansion,'r')
plot(V4,P4,'*','color','r')
plot([V4 V1],[P4 P1],'b')
xlabel('Volume')
ylabel('Pressure')
title('Otto cycle')
We can see the following outputs after we run the codes
Also the PV diagram can be seen as:
And the Thermal efficient as:
Errors and Remedies:
While running the codes I had encountered some errors which were mostly because of wrong deceleration of the variables and improper use of parentheses.
The Screen shots for the errors prompted can be seen below.
These errors can be resolved by resing the errors displayed in the command window by line by line corrections.