Determining the thermal efficiency of Otto cycle using MATLAB
Aim:
The aim of this project is to determine the thermal effeciency of Otto cycle using MATLAB by providing a known set of input values and to plot the variation of pressure with volume during the course of the cycle.
MATLAB Code:
Main Program:
% Program to create the PV diagram and determine the thermal effeciency of
% a gasoline engine (Otto Cycle)
clc
%Compression index
gamma=1.4 %Isentropic process
%Temperature at the end of combustion
t3=2000
% State variables at point 1
p1= 101325 % As atmospheric pressure is 1.01325 bar
t1= 400
% Enginer geometry ( Dimensions in m )
d=0.1; %Bore
l=0.25; %Stroke
con_rod=0.2;
rc=7;
vs=(pi/4)*d^2*l; %Volume swept by piston
vc=vs/(rc-1); % Clearence volume
v1=vs+vc;
v2=vc;
% State variables at point 2
% p2*v2^gamma=p1*v1^gamma
% p2=(p1*v1^gamma)/(v2^gamma)
p2=p1*rc^gamma;
% (p1*v1)/t1=(p2*v2)/t2
t2=((p2*v2)*t1)/(p1*v1)
contant_c=p1*v1^gamma
V_compression=engine_kinematics(d,l,con_rod,rc,180,0)
P_compression= contant_c./V_compression.^gamma
% State variables at point 3
v3=v2
% (p3*v3)/t3=(p2*v2)/t2
p3=(p2*t3)/t2
contant_c=p3*v3^gamma
V_expansion=engine_kinematics(d,l,con_rod,rc,0,180)
P_expansion= contant_c./V_expansion.^gamma
% State variables at point 4
v4=v1
% p4*v4^gamma=p3*v3^gamma
p4=p3*(v3/v4)^gamma
%t3=t4*cr^(gamma - 1)
t4= t3/((rc)^(gamma-1))
% Calculation of thermal effeciency
eta_thermal=1-((t4-t1)/(t3-t2))
figure(1)
hold on
plot(v1,p1,'*','color','r')
plot(V_compression,P_compression,'color','r')
plot(v2,p2,'*','color','r')
plot([v2 v3],[p2 p3],'color','r')
plot(v3,p3,'*','color','r')
plot(V_expansion,P_expansion,'color','r')
plot(v4,p4,'*','color','r')
plot([v4 v1],[p4 p1],'color','r')
ylabel('Pressure in N/m^2')
xlabel('Volume in m^3')
Function:
% Function to plot the p-v curves using piston kinematics
function [V]=engine_kinematics(d,l,con_rod,rc,start_crank,end_crank);
% Previous inputs
a=l/2;
R=con_rod/a;
vs=(pi/4)*d^2*l; %Volume swept by piston
vc=vs/(rc-1); % Clearence volume
%Crank angle
theta=linspace(start_crank,end_crank,120);
% Splitting up the formula
term1=0.5*(rc-1);
term2=R+1-cosd(theta);
term3=(R^2-sind(theta).^2).^0.5;
V=(1+term1*(term2-term3)).*vc;
end
Step-wiseExplanation for the code:
Initialization:
1. Firstly, known inputs such as initial Temperature and Pressure, temperature of the charge after combustion and the compression index and compression ratio are assigned to specific variables.
2. With the help of the engine geometric parameters, the swept volume and the clearence volume of the engine are calculated in order to find out the values of state point variables.
3. The state values are computed with the appropriate formulae for the points 2,3 and 4. Finally once the temperature at all points have been computed, the thermal effeciency of the cycle can be calculated.
Function implementation:
4. In order to plot the various points and join them using appropriate curves, we need to consider the Piston kinematics. (In case the piston kinematics are not considered, the points are joined by straight lines which is a poor approximatoion of the actual curve)The formula used is:
`frac{V}{Vc}=1+1/2(rc-1)[R+1-cos theta - (R^2-sin^2 theta)^(1/2)]`
5. Various values of crank angles are generated by using 'Linspace Command'.
Plotting:
6. This function 'engine_kinematics' is called with the parameters such as bore diameter, stroke length, connecting rod length, compression ratio, starting crank angle and ending crank angle. These parameters are passed as values and are substituted at the appropriate places and the volume is obtained for various crank angles.
7. Using the plot command the state points are plotted and are join using the characteristic compression and expansion curves. The compression occurs from crank angle 180 degree to 0 degrees. Whereas the expansion occurs from crank angle 0 degrees to 180 degrees.
Results:
1. Individual state points.
2. Variation of volume with crank angle.
3. Final plot of pressure vs volume.
Errors that were debugged:
1. Using 'clear all' inside the function posed an error message that a reference to a cleared variable has been used. This usually occurs because the variables inside a function are just local variables. This can be avoided by not using 'clear all' within a function.
2. When one of the parameters (Compression ratio) was accidentally missed while calling the function, a wrong plot was generated. This could be corrected by passing all the necessary paramaters of a funtion in the respective order.
Result:
The thermal effeciency of the cycle was found to be 54.08% for the given inputs and the variation of pressure with volume during the course of the cycle was plotted.