Week 2.1 - Air standard Cycle
Objective: To solve an Otto cycle and plot the PV diagram along with Thermal efficiency calculation using Matlab.
Drive File Link:
Main File Link : https://drive.google.com/file/d/1fymHWnRGYAKNGAWOp4f4NazFv8x7i8Sz/view?usp=sharing
Function File Link : https://drive.google.com/file/d/1nkS07s6tP-PHEeybTXwPMPj9SENHAYGo/view?usp=sharing
Code:
clear all
close all
clc
%Inputs
gamma = 1.4;
%Engine geometry parameters
bore = 0.1;
stroke = 0.1;
con_rod = 0.15;
cr = 9;
%Calculating the swept volume and the clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
%State variable at state point 1
p1 = 101325;
t1 = 500;
v1 = v_swept + v_clearance;
v2 = v_clearance;
%State varialbe at state point 2
% p2v2^gamma = p1v1^gamma
% p2 = p1*(v1v2)^gamma = p1*cr^gamma
p2 = p1*cr^gamma;
%p1v1/t1 = p2v2/t2 | t2 = p2*v2*t1(p1*v1)
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gamma;
v_compression = Otto_Cycle_Challenge_Func(bore, stroke, con_rod,cr, 180 ,0);
p_compression = constant_c./v_compression.^gamma;
% State variable at state point 3
t3 = 2300;
v3 = v2;
%p3v3/t3 = p2v2/t2 | p3 = p2*t3/t2
p3 = p2*t3/t2;
constant_c = p3*v3^gamma;
v_expansion = Otto_Cycle_Challenge_Func(bore, stroke, con_rod,cr ,0, 180);
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;
%Plotting
figure(1)
hold on
plot([v2,v3] ,[p2,p3])
plot(v_compression, p_compression)
plot(v_expansion, p_expansion)
plot([v4,v1],[p4,p1])
%Calculating Thermal Efficiency
Thermal_Efficiency = (1-(cr^(gamma-1))^-1)*100
/////Function File///
%Function Code
function [V] = Otto_Cycle_Challenge_Func(bore, stroke,con_rod, cr, start_crank, end_crank)
a = stroke/2;
R = con_rod/a;
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
Code Explanation:
We give the initial dimensions of the cyclinder like bore, stroke,con_rod and cr( compression ratio), along with gamma value.
The Otto cycle is divided into 4 state points
In state point 1 we will calculate the v_swept and _v_clearance and used it to find v1 and v2. p1 and t1 are already given inputs.
In state point 2 we find the t2 and constant_c using formulae. To find v_compression we use the function call statement to call the function named " Otto_Cycle_Challenge_Func" by send parameter to be calculated inside the function.
We also find p_compresion in state 2
In state point 3 we find p3 and find v_expansion by using function call statement to the call "Otto_Cycle_Challenge_Func" by sending parameters to it.
We also find p_expansion in state 3.
In state point 4 we find only p4.
After finding all the points we plot these numbers to represent the PV diagram.
We also calculate the Thermal Efficiency of the System under (cr) compression ratio 9, which gives us a result of 58.4756%
Output:

Error Faced:
1. Forgot to give the same name to Function name and File name which took some time to figure it out.

2. Did usual Case Sensitive Typo Errors when naming Variables.
