otto cycle
%otto_cycle
clear all
close all
clc
%inputs
gamma=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;
a=stroke/2;
r=con_rod/a;
%calculating swept volume and clearance volume
v_swept=(pi/4)*bore^2*stroke;
v_clearance=v_swept/(cr-1);
%state variables at state one
v1=v_swept+v_clearance;
v2=v_clearance;
%state variables between point one and two
theta1=linspace(0,180,180);
term1=0.5*(cr-1);
term2=r+1-cosd(theta1);
term3=(r^2-sind(theta1).^2).^0.5;
v1_2=(1+term1*(term2-term3))*v_clearance;
c1_2=p1*v1^gamma;
p1_2=c1_2./(v1_2).^gamma;
%state variables at state point two
p2=p1*cr^gamma;
t2=(p2*v2*t1)/(p1*v1);
%state variable at state point three
v3=v2;
p3=(p2*t3)/(t2);
%state variables between point three and four
theta2=linspace(180,360,180);
term1=0.5*(cr-1);
term2=r+1-cosd(theta2);
term3=(r^2-sind(theta2).^2).^0.5;
v3_4=(1+term1*(term2-term3))*v_clearance;
c3_4=p3*v3^gamma;
p3_4=c3_4./(v3_4).^gamma;
%state variable at state point four
v4=v1;
p4=p3*(v3/v4)^gamma;
%plotting
figure(1)
hold on
plot(v1,p1,\'.\',\'color\',\'r\')
plot(v1_2,p1_2,\'color\',\'g\',\'linewidth\',2)
plot(v2,p2,\'.\',\'color\',\'r\')
plot(v3,p3,\'.\',\'color\',\'r\')
plot(v3_4,p3_4,\'color\',\'g\',\'linewidth\',2)
plot(v4,p4,\'.\',\'color\',\'r\')
plot([v2 v3],[p2 p3],\'linewidth\',2)
plot([v4 v1],[p4 p1],\'linewidth\',2)
grid on
xlabel(\'volume\')
ylabel(\'pressure\')
%thermal efficiency
efficiency=(1-(1/cr^(gamma-1)))*100
disp(efficiency)