OTTO CYCLE (P-V diagram and calculation of thermal efficiency )

clear all
close all
clc
%input
gamma=1.4
t3=1926
% state variables at state point 1
p1=100000
t1=293
% engine geometric parameter
bore=.1;
stroke=.1;
cr=9;
co_rod=.15;
%calculating the swept volume and clearance volume
v_swept=pi/4*bore^2*stroke;
v_clearance=v_swept/(cr-1);
v1=v_swept+ v_clearance;
v2=v_clearance;
% state variable at state point 2
%p2v2^gamma= p1v1^gamma
%p2=p1*(v1/v2)^gamma =p1*cr^gamma
p2=p1*(cr)^gamma;
%p1v1/t1=p2v2/t2 t2=p2*v2*t1/(p1v1)
t2=p2*v2*t1/(p1*v1)
constant_c=p1*v1^gamma;
V_compression=engine_kinematics(bore,stroke,cr,co_rod,180,0);
P_compression=constant_c./V_compression.^gamma;
% state variable at state point 3
v3=v2
%p3v3/t3=p2v2/t2 p3=p2*t3/t2
p3=p2*t3/t2
constant_c=p3*v3^gamma;
V_expansion=engine_kinematics(bore,stroke,cr,co_rod,0,180);
P_expansion=constant_c./V_expansion.^gamma;
% state variable at state point 4
v4=v1
%p3v3^gamma= p4v4^gamma p4=p3*(v3/v4)^gamma
p4=p3*(v3/v4)^gamma
hold on
plot (v1,p1,'*','Color','b')
plot (v2,p2,'*','Color','b')
plot (v3,p3,'*','Color','b')
plot (v4,p4,'*','Color','b')
plot(V_compression,P_compression,'Color','r')
plot ([v2,v3],[p2,p3],'Color','g')
plot(V_expansion,P_expansion,'Color','r')
plot ([v4,v1],[p4,p1],'Color','g')
% Thermal efficiency of ottocycle
efficieny_ottoengine=(1-1/(cr^(gamma-1)))*100

















To write the program to create p-v diagram and thermal efficiency of otto cycle:
STEP-I Clear all (to clear all the stored data to a variable, close all (to close all Matlab fig. window),clc (to clear the command window) commands are used.
A suitable program name is given
STEP-II Inputs are given
gamma=1.4(adiabatic index)
t3=1926(in k temperature at point 3)
state variables are inputted
p1=100000 (in N/m2)
t1=293 (in k temperature at point 1)
engine geometric parameters are inputted
bore=.1
stroke=.1
cr=9; (compression ratio)
co_rod=.15 (length of connecting rod)
STEP-III To calculate the swept volume and clearance volume following formulas are inputted
v_swept=pi/4*bore^2*stroke (swept volume)
v_clearance=v_swept/(cr-1) (clearance volume)
v1=v_swept+ v_clearance (volume at state 1)
v2=v_clearance (volume at state 2)
STEP-IV state variables at state point 2 are inputted
p2v2^gamma= p1v1^gamma
p2=p1*(v1/v2)^gamma =p1*cr^gamma
p2=p1*(cr)^gamma;
p1v1/t1=p2v2/t2 t2=p2*v2*t1/(p1v1)
t2=p2*v2*t1/(p1*v1)
constant_c=p1*v1^gamma
STEP-V calling the function engine _kinematics for compression
function [v]= engine_kinematics(bore,stroke,cr,co_rod,start_crank,end_crank)
a=stroke/2;
R=co_rod/a;
v_swept=(pi/4)*bore^2*stroke
v_clearance=v_swept/(cr-1)
theta =linspace(start_crank,end_crank,100)
term1= .5*(cr-1);
term2=R+1-cosd(theta);
term3=(R^2 -sind(theta).^2).^0.5;
v=(1+term1*(term2-term3)).*v_clearance
end
where engine_kinematics is a function
a=stroke/2 (crankpin radius)
R=co_rod/a (ratio of stroke to crank pin radius)
start_crank =start_crank angle
end_crank= end_crank angle
to create value of theta linspace command is used(upto 100 )
to find the output v:
v=(1+term1*(term2-term3)).*v_clearance
where,
term1= .5*(cr-1)
term2=R+1-cosd(theta)
term3=(R^2 -sind(theta).^2).^0.5
d:degree
*:multiplication
V/Vc=1 + ½(rc-1)[R+1-cosθ (R2 -sin2 θ)1/2]
V_compression=engine_kinematics(bore,stroke,cr,co_rod,180,0);
start_ crank 180 degrees and end _crank angle 0 degrees are inputted.
P_compression=constant_c./V_compression.^gamma
STEP -VI state variable at state point 3 are inputted
v3=v2
p3v3/t3=p2v2/t2 p3=p2*t3/t2
p3=p2*t3/t2
constant_c=p3*v3^gamma
calling the function engine _kinematics for expansion
V_expansion=engine_kinematics(bore,stroke,cr,co_rod,0,180);
P_expansion=constant_c./V_expansion.^gamma;
start_ crank 0 degrees and end _crank angle 180 degrees are inputted.
STEP -VII state variables at state point 4 are inputted
v4=v1
p3v3^gamma= p4v4^gamma p4=p3*(v3/v4)^gamma
p4=p3*(v3/v4)^gamma
STEP-VIII To plot the p-v diagram
hold on command is inputted
Plot command is inputted for to find the state points and to plot the diagram
for :p1,v1;p2,v2;p3,v3;p4,v4
plot (v1,p1,'*','Color','b')
plot (v2,p2,'*','Color','b')
plot (v3,p3,'*','Color','b')
plot (v4,p4,'*','Color','b')
plot(V_compression,P_compression,'Color','r')
plot ([v2,v3],[p2,p3],'Color','g')
plot(V_expansion,P_expansion,'Color','r')
plot ([v4,v1],[p4,p1],'Color','g')
STEP-IX To find the thermal efficiency of the engine:
The following formula is inputted
efficieny_ottoengine=(1-1/(cr^(gamma-1)))*100
efficieny_ottoengine=58.4756%
[xlabel,ylabel and arrow in the plot are inserted through insert option in figure]
ERROR 1:while putting relation between p4,p3,v4 and v3
Array indices must be positive integers or logical values.
Error in c5 (line 57)
p4=p3(v3/v4)^gamma

Error1 resolved : by putting * between p3 and (v3/v4)
p4=p3*(v3/v4)^gamma

ERROR 2: thermal efficiency calculation
Error using /
Arguments must be numeric, char, or logical.
Error in c5 (line 70)
efficieny_ottoengine=(1-1/{cr^(gamma-1)})*100

Error 2 resolved : by making the follwing correction
% Thermal efficiency of ottocycle
efficieny_ottoengine=(1-1/(cr^(gamma-1)))*100
