% state variable
gamma = 1.4;
p1 = 101325;
t1 = 500;
t3 = 2000;
% engine parameters
bore = 100;
stroke = 100;
con_rod = 150;
cr = 12;
%calculate swept and clearance volume
v_swept = (pi/4)*bore^2*stroke;
v_clearance = v_swept/(cr-1);
% variables @1&2
v1 = v_swept+v_clearance;
v2 = v_clearance;
p2 = p1*(cr^gamma);
t2 = p2*v2*t1/(p1*v1);
constant_c = p1*v1^gamma;
v_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0);
p_compression = constant_c./v_compression.^gamma;
% variable @3
v3=v2;
p3 = p2*t3/t2;
constant_c = p3*v3^gamma;
v_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180);
p_expansion = constant_c./v_expansion.^gamma;
%state variable @ 4
v4 = v1;
p4 = p3*(v3/v4)^gamma;
t4 = p4*v4*t3/(p3*v3);
figure(1)
hold on
plot(v1,p1,'*')
plot(v_compression,p_compression)
plot(v2,p2,'*')
plot(v3,p3,'*')
plot(v_expansion,p_expansion)
plot(v4,p4,'*')
line([v2 v3],[p2 p3])
line([v4 v1],[p4 p1])
y=(cr)^(gamma-1);
x = 1-(1/y);
fprintf('thermal efficiency %d\n',x);