% my otto cycle
clear al;
close all;
clc;
% engine parameters
p1=101325;
t1=500;
t3=2000;
bore=0.07;
stroke=0.09;
conrod=0.1;
cr=7.25;
gamma = 1.4;
%estimation of swept vol and clearence vol
v_s = (pi/4)*bore^2*stroke;
v_c = v_s/(cr-1);
%for first point
v1 = v_s + v_c;
% p1 = 101325;
%for second point
v2 = v_c;
p2 = p1 *(v1/v2)^gamma;
t2 = (p2* v2 * t1)/(p1 * v1);
v_comp=volume_trace(0.07,0.09,0.15,7.25,180,0);
const_1=p2*v2^gamma;
p_comp=const_1./v_comp.^gamma;
%for third point
v3 = v2;
p3 = p2*t3/t2;
v_exp=volume_trace(0.07,0.09,0.15,7.25,0,180);
const_2=p3*v3^gamma;
p_exp=const_2./v_exp.^gamma;
%for fourth point
v4 = v1;
p4 = p3 * (v3/v4)^gamma;
hold on
figure(1)
plot(v1,p1,'*','color','r')
plot(v2,p2,'*','color','r')
plot(v_comp,p_comp,'color','b')
plot(v_exp,p_exp ,'color','b')
plot(v3,p3,'*','color','r')
plot(v4,p4,'*','color','r')
plot([v2 v3],[p2 p3],'color','b')
plot([v1 v4],[p1 p4],'color','b')
grid on
xlabel('Volume (m3)')
ylabel('Pressure (N/m2)')
title('PV Diagram of Otto Cycle')
%To calculate Thermal Efficiency
%Thermal Efficiency of otto cycle =1-(1/( cr^(gamma-1)))
efficiency =1-(1/( cr^(gamma-1)))
function [V] = volume_trace (bore,stroke,conrod,cr,start_crank,end_crank)
a=stroke/2;
R=conrod/a;
theta=linspace(start_crank,end_crank,180);
v_s = (pi/4)*bore^2*stroke;
v_c = v_s/(cr-1);
m=0.5*(cr-1);
n=R+1-cosd(theta);
p=((R^2)-(sind(theta).^2)).^0.5;
V = v_c*(1+m*(n-p))