P-V diagram and solving for thermal efficiency of Otto Cycle in Matlab
clear all
close all
clc
%Inputs
gama = 1.4;
t3 = 2300;
%State Variables
p1 = 101325;
t1 = 500;
%Engine geometric parameters
bore = 0.1;
stroke = 0.1;
con_rod = 0.15;
cr = 12;
%Calculating the swep 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 varaiables at state point 2
%p2v2^gama = p1v1^gama
%p2 = p1*(v1/v2)*gama = p1*cr*gama
p2 = p1*cr^gama;
%p1v1/t1 = p2v2/t2 | t2 = p2*v2*t1/(p1*v1)
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gama;
V_compression = engine_kinematics(bore,stroke,con_rod,cr,180,0)
P_compression = constant_c./V_compression.^gama;
%State variables at state point 3
v3 = v2;
%p3v3/t2 = p2v2/t2 | p3 = p2*t3/t2
p3 = p2*t3/t2
constant_c = p3*v3^gama;
V_expansion = engine_kinematics(bore,stroke,con_rod,cr,0,180)
P_expansion = constant_c./V_expansion.^gama;
%State variables at point 4
v4 = v1;
%p3v3^gama = p4v4^gama | p4 = p3(v3/v4)^gama
p4 = p3*(v3/v4)^gama
figure(1)
hold on
plot(v1,p1,\'*\',\'color\',\'r\')
plot(V_compression,P_compression)
plot(v2,p2,\'*\',\'color\',\'r\')
plot([v2 v3],[p2 p3])
plot(v3,p3,\'*\',\'color\',\'r\')
plot(V_expansion,P_expansion)
plot(v4,p4,\'*\',\'color\',\'r\')
plot([v4 v1],[p4 p1])
xlabel(\'Volume\')
ylabel(\'Pressure\')
% Calculation of efficiency
Efficiency = 1 - (1/cr)^(gama-1)
In this challenge, we are visualizing the otto cycle by coding the parameters using Matlab.We use a function \'engine kinematics\' to define the engine parameters. We use the formula to define various values of pressure and temperature. Finally we plot the different values obtained.
The expansion and compression curves are also plotted. The value of expansion and compression volume is defined by the \'engine kinematics\' function and respective values o pressure is derived from it.
Lastly, we use the otto cycle formula to calculate the thermal efficiency of the cycle.