Otto cycle - PV diagram visualizer
AIM: write a MatLab code that can solve an otto cycle and make pv diagram.
SOLUTION:
Coding:
%Given
%Engine geometric parameters
bore=0.1;
stroke=0.1;
connecting_rod_length=0.15;
cr=12; %Compression ratio
%Given state variables
p1=101325;
t1=500;
t3=2300;
gamma=1.4;
%Find v1,v2,v3,v4 and p1,p2,p3,p4 and draw PV diagram
%Solution
%First of all calulating swept volume(sv) and clearance volume(cv)
sv=(pi/4)*bore^2*stroke;
cv=sv/(cr-1);
%Variables at point1
v1=sv+cv;
%Variables at point2
v2=cv;
p2=p1*(cr)^gamma; %w.k.t p2v2^gamma=p1v1^gamma
t2=(p2*v2*t1)/(p1*v1); %w.k.t p1v1/t1=p2v2/t2
%Variables at point3
v3=v2;
p3=(p2*t3)/t2; %w.k.t p3v3/t3=p2v2/t2
%Variables at point4
v4=v1;
p4=p3*(v3/v4)^gamma; %w.k.t p3v3^gamma=p4v4^gamma
%Calculating the values of volumes and pressures changes during compression and expansion
%This give a correct PV diagram
crank_pin_radius=stroke/2;
R=connecting_rod_length/crank_pin_radius;
%w.k.t v=(1+0.5(cr-1)(R+1-cosd(theta)-(R^2-sind(theta)^2)^0.5))*cv
%Values of volumes and pressures changing during compression
theta1=linspace(180,0,180);
v_compression=(1+0.5*(cr-1)*(R+1-cosd(theta1)-(R^2-sind(theta1).^2).^0.5)).*cv
constant_c=p1*v1^gamma;
p_compression=constant_c./v_compression.^gamma;
%Values of volumes changing during expansion
theta2=linspace(0,180,180);
v_expansion=(1+0.5*(cr-1)*(R+1-cosd(theta2)-(R^2-sind(theta2).^2).^0.5)).*cv
constant_e=p3*v3^gamma;
p_expansion=constant_e./v_expansion.^gamma;
%Now plotting PV diagram
hold on
xlabel('volume')
ylabel('pressure')
plot(v_compression,p_compression,'color','r')
plot([v2,v3],[p2,p3],'color','b')
plot(v_expansion,p_expansion,'color','g')
plot([v4,v1],[p4,p1],'color','b')
%Calculating Thermal efficiency of engine
thermal_efficiency=1-(1/(cr^gamma-1))
while running the above code I did not get any errors, it runs successfully.
Output:
* PV diagram
* Thermal_efficiency=0.9682
Report:
* Initally get the values of engine geometric parameters and initial state variables
* Then calculating swept volume and clearance volume
* Find out the state variables at each point
* Plotting only state variables give wrong pv diagram
* So we must find out the values of volume and pressure changing during compression and expansion
*Now plot the state variables and values of volume and pressure changing during compression and expansion.
* It give a correct pv diagram
* Finally calculate the thermal efficiency of the engine.