PV Diagram Visualiser
First, we create the main program i.e otto.m
close all
clear all
clc
% Input Variables
bore_engine=0.1;
stroke_engine=0.1;
con_engine=0.15;
cratio_engine=12;
% Input
% gamma is ratio of specific heat used in efficiency formula
gamma=1.4;
t3=2300
%State Variables
p1=101325
t1=500
% Finding v1 and v2
v_s=(pi/4)*bore_engine^2*stroke_engine;
v_c=v_s/(cratio_engine-1);
v1=v_s+v_c
v2=v_c
% Main code, State Variable 2, p1*v1^gamma=p2*v2^gamma
% p1*v1/t1=p2*v2/t2
t2=p2*v2*t1/(p1*v1)
constant_e=p1*v1^gamma
V_compression=engine_kinematics2(bore_engine,stroke_engine,con_engine,cratio_engine,180,360)
% constant_e=P_compression*V_compression
P_compression=constant_e./V_compression.^gamma;
% State Variable 3
v3=v2
%p3*v3/t3=p2*v2/t2
% v3=v2
p3=p2*t3/t2
constant_e=p3*v3^gamma
V_expansion=engine_kinematics2(bore_engine,stroke_engine,con_engine,cratio_engine,0,180)
% constant_e=P_compression*V_compression
P_expansion=constant_e./V_expansion.^gamma;
% State Variable 4
v4=v1
p4=p3*(v3/v4)^gamma
% Thermal efficiency of engine is solely dependent on compression ratio and fixed value gamma.
thermaleff_e=1-1/(cratio_e^gamma-1);
figure(1)
hold on
plot(v1,p1,\'*\',\'color\',\'b\')
plot(V_compression,P_compression)
plot(v2,p2,\'*\',\'color\',\'b\')
plot(v3,p3,\'*\',\'color\',\'b\')
plot(V_expansion,P_expansion)
plot(v4,p4,\'*\',\'color\',\'b\')
% Joining Straight Lines
plot([v2 v3],[p2 p3])
plot([v4 v1],[p4 p1])
Now, we write for the function \'engine_kinematics2.m\' which has been called in the above program
function [v]=engine_kinematics2(bore_e,stroke_e,cond_e,cr_e,start_e,end_e)
a=stroke_e/2;
R=cond_e/a;
v_s=(pi/4)*bore_e^2*stroke_e;
v_c=v_s/(cr_e-1);
theta_e=linspace(start_e,end_e,100);
term1=0.5*(cr_e-1);
term2=R+1-cosd(theta_e);
term3=(R^2-sind(theta_e).^2).^0.5;
V=(1+term1*(term2-term3)).*v_c;
end