PV Diagram Visualizer for OTTO cycle
Piston Kinematics
function [v] = pistonkinematics(bore,stroke,cr_rod,cr,startcrank,endcrank)
cradius = stroke/2; R = cr_od/cradius;
%calculating the swept volume and clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
theta = linspace(startcrank,endcrank,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_clearance;
endfunction
Otto cycle
%Otto Cycle
clear all
close all
clc
%static variables
p1=202650;
t1=300;
t3=3000;
gamma=1.3;
%engine parameters
bore=0.3;
stroke=0.15;
cr_rod=0.15;
cr=13;
%calculations
sweptv=(pi*bore^2*stroke)/4;
clearv=sweptv/(cr-1);
v1=sweptv + clearv;
v2=clearv;
p2=p1 * cr^gamma;
t2=(p2 * v2 * t1)/(p1 * v1);
v3=v2;p3=(p2 * v2 * t3)/(v3 * t2);
v4=v1;
p4=p3*(v3/v4)^gamma;
t4=(p4 * v4 * t3)/(p3 * v3);
constant1=p1*v1^gamma;
v_comp=pistonkinematics(bore,stroke,cr_rod,cr,180,0);
p_comp=constant1./v_comp.^gamma;
constant2=p3 * v3^gamma;
v_exp=pistonkinematics(bore,stroke,cr_rod,cr,0,180);
p_exp=constant2./v_exp.^gamma;
figure(1)
hold on;
plot(v1,p1,'color','r');
plot(v_comp,p_comp);
plot(v2,p2,'color','r');
plot([v2 v3],[p2 p3]);
plot(v3,p3,'color','r');
plot(v_exp,p_exp);
plot(v4,p4,'color','r');
plot([v4 v1],[p4 p1]);
ylabel('pressure');
xlabel('volume');
%calculate Efficency
n=(1-cr^(1-gamma))*100;
fprintf("Efficency = %d" ,n)
PV DIAGRAM