Challenge_Air_standard _cycle
1. AIM: To code for otto cycle and make plots
2. EQUATION :
- Compression Volume, `V=1+1/2 (cr-1)[R+1-cosθ-(R^2-(sinθ )^2 )^(1/2) ]`
Where,
V = Compression volume, `m^3`
cr = Compression ratio
R = Ration of connecting rod length and crank pin radius
`θ` = Crank angle, degrees
3. OBJECTIVES:
- To create Pressure-Volume Diagram of Otto cycle
- Calculate the Thermal efficiency of the engine
4. BODY OF CONTENT:
Code:
% Program to plot PV diagram of otto cycle and calculate Thermal efficiency
% of otto cycle
clear all
close all
clc
% Inputs
gamma = 1.4;
t3 = 2300;
% State variables at state point 1
p1 = 101325;
t1 = 500;
% Engine geometric parameters
bore = 0.1; % bore diameter, m
stroke = 0.1; % stroke length, m
con_rod = 0.15; % connecting rod length, m
cr = 12; % compression ratio
% Calculating the swept volume and the clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
v1 = v_swept+v_clearance;
v2 = v_clearance;
% State variables 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/(p1*v1)
t2 = p2*v2*t1/(p1*v1);
% Calculating Constant
constant_c = p1*v1^gamma;
% Calculating compression volume from the function template, engine_kinematics
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0);
% Calculating compression pressure from formula, p*v^gamma = constant
P_compression = constant_c./V_compression.^gamma;
% State variables at state point 3
v3 = v2;
% p3v3/t3 = p2v2/t2 | p3 = p2*(t3/t2)
p3 = p2*(t3/t2);
% Calculating Constant
constant_c = p3*v3^gamma;
% Calculating expansion volume from the function template, engine_kinematics
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180);
% Calculating expansion pressure from formula, p*v^gamma = constant
P_expansion = constant_c./V_expansion.^gamma;
% State variables at state point 4
v4 = v1;
%p3v3^gamma = p4v4^gamma | p4 = p3*(v3/v4)^gamma
p4 = p3*(v3/v4)^gamma;
t4 = p4*t1/p1;
% Plotting PV diagram
figure(1)
hold on
plot(v1,p1,'*','color','r') % State point 1
plot(V_compression,P_compression,'color','r') % Isentropic compression curve
plot(v2,p2,'*','color','r') % State point 2
line([v2,v3],[p2,p3],'color','r') % Isochoric heat addition curve
plot(v3,p3,'*','color','r') % State point 3
plot(V_expansion,P_expansion,'color','r') % Isentropic expansion curve
plot(v4,p4,'*','color','r') % State point 4
line([v4,v1],[p4,p1],'color','r') % Isochoric heat rejection curve
title('PV diagram of Otto cycle')
xlabel('Volume')
ylabel('Pressure')
% Calculating Thermal efficiency of otto cycle
Thermal_efficiency = 1-1/(cr^(gamma-1))
Function template to calculate volume
% Function template to calculate Compression and Expansion Volume(V)
function [V] = engine_kinematics( bore, stroke, con_rod, cr, start_crank_angle, end_crank_angle)
% a : crank pin radius
a = stroke/2;
% R : ratio of 'connecting rod length' and 'crank pin radius'
R = con_rod/a;
% v_s : swept volume
% v_c : clearance volume
v_s = pi/4*bore^2*stroke;
v_c = v_s/(cr -1);
% Creating an array(theta) to store crank angle values
% theta : crank angle
theta = linspace(start_crank_angle,end_crank_angle,100);
% breaking the equation of compression volume into multiple terms
term1 = 0.5*(cr-1);
term2 = R+1-cosd(theta);
term3 = (R^2-sind(theta).^2).^0.5;
% V : Compression volume | Expansion volume
V = (1+term1*(term2-term3)).*v_c;
end
Code explanation:
- This code gives the PV diagram and value of Thermal efficiency as output
- Initially Inputs are provided such as gamma - specific heat ratio of gas, and some state variables such as t3 - temperature at state point 3, p1 and t1 – pressure and temperature at state point 1 respectively
- Then the engine geometric parameters are defined such as bore diameter, stroke length, connecting rod length and compression ratio which is ratio of volumes of state point 1 and 2 or state point 4 and 3
- Then the swept volume and clearance volume are calculated, from which volumes of state points 1 and 2 are obtained
- Following the state point variables of 2,3 and 4 such as p2,t2,v3,p3,v4,p4 and t4 are calculated
- A function template, engine_kinematics has been created to calculate the compression and expansion volume
- Compression and Expansion values of volume are calculated by calling the function engine_kinematics
- Where Compression and Expansion values of Pressure has been calculated using the ideal gas equation,
- Then the state points have been plotted using the values of volume and pressure of different state points and the isentropic compression and expansion curves has been plotted using the values of compression and expansion of both volume and pressure
- Then the isochoric heat addition and rejection curves are plotted using the state points, here the curve is straight line
- Then the title and axis labels are given
- Lastly the Thermal efficiency is calculated, whose value depends on the compression ratio
5. ERRORS:

- Here the error is due to using common brackets while specifying variables inside "line" command
- Using parentheses in place of common brackets eliminates the error
6. OUTPUTS:
1. PV diagram:-

- Above figure is the graphical representation of the changes in pressure with respect to volume in a system
- The four points in the above figure represents four states of gas with values of volume and pressure
- The four states are,
(1). 1-2 Isentropic compression
(2). 2-3 Isochoric heat addition
(3). 3-4 Isentropic expansion
(4). 4-1 Isochoric heat rejection
2. Command window output of Thermal efficiency

- This is the command window output of the Thermal efficiency of the engine
- The thermal efficiency of the engine depends on the compression ratio of the engine
7. CONCLUSION:
- The PV diagram has been plotted for the Otto cycle
- The Thermal efficiency of the engine has been generated