VISUALIZATION OF P-V DIAGRAM OF AN OTTO CYCLE USING MATLAB
AIM:
Our aim is to write a code in matlab to visualize the P-V diagram of an Otto cycle and to provide the output of thermal efficiency of the engine
CODE FOR VISUALIZATION OF P-V DIAGRAM AND THERMAL EFFICIENCY OF OTTO CYCLE
clear all
close all
clc
%input
gamma=1.4;
t3=2300;
%state variables at point1
p1=101325;
t1=500;
%geometric parameters
bore=0.1;
stroke=0.1;
con_rod=0.15;
cr=12;
%calculating v_s and v_c
v_s=(pi/4)*bore^2*stroke
v_c=v_s/(cr-1)
%calculating v1 and v2
v1=v_s+v_c
v2=v_c
%thermodynamic relation
constant_c=p1*v1^gamma
v_compression=engine_kinematics(bore,stroke,con_rod,cr,180,0)
p_compression=constant_c./v_compression.^gamma
%state variables at point2
%p2v2^gamma=p1v1^gamma | p2=p1*cr^gamma
p2=p1*cr^gamma
%p2v2/t2=p1v1/t1 | t2=p2*v2*t1/(p1*v1)
t2=p2*v2*t1/(p1*v1)
%state variables at point 3
v3=v2
%p3v3/t3=p2v2/t2 | p3=p2*t3/t2
p3=p2*t3/t2
%thermodynamic relation
constant_c=p3*v3^gamma
v_expansion=engine_kinematics(bore,stroke,con_rod,cr,0,180)
p_expansion=constant_c./v_expansion.^gamma
%state variables at point 4
v4=v1
%p4v4^gamma=p3v3^gamma | p4=p3*(v3/v4)^gamma
p4=p3*(v3/v4)^gamma
%p4v4/t4=p3v3/t3 | t4=p4*v4*t3/(p3*v3)
t4=p4*v4*t3/(p3*v3)
%calculating thermal efficiency
thermal_efficiency=(1-(1/(cr)^(gamma-1)))*100
%plotting
figure(1)
hold on
plot(v1,p1,'*','color','r')
plot(v2,p2,'*','color','r')
plot(v3,p3,'*','color','r')
plot(v4,p4,'*','color','r')
plot([v_compression v2 v_expansion v4 v_compression],[p_compression p2 p_expansion p4 p_compression],'color','b')
xlabel('volume')
ylabel('pressure')
CODE FOR AN FUNCTION NAMED ('engine_kinematics')
function [V]= engine_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank)
%inputs
a=stroke/2;
R=con_rod/a;
%calculating v_s and v_c
v_s=(pi/4)*bore^2*stroke;
v_c=v_s/(cr-1);
%thermodynamic relation
theta=linspace(start_crank,end_crank,180);
term1=0.5*(cr-1);
term2=R+1-cosd(theta);
term3=(R^2-sind(theta).^2).^0.5;
V=(1+term1*(term2-term3)).*v_c
end
INPUTS:
STEP 1:
The inputs values for gamma,bore dia,stroke length,connecting rod length,compression ratio etc have been assumed to calculate the values of swept volume and clearance volume. Then the values of state variables such as pressure, volume, temperature at all the four points (1,2,3,4) are calculated using the ideal gas formulas provided in the coding.
STEP 2:
Followed by our 1st step our next step is to plot the values using plot command to visualize the P-V diagram of an air standard cycle. To plot the line for adiabatic compression (1-2) and adiabatic expansion (3-4) process is their original path we are using a thermodynamic relation.
STEP 3:
Hence a function named 'engine_kinematics' is inserted into our original coding by calling a function for accurate plotting of paths of processes (1-2) and (3-4). The function named 'engine_kinematics' is framed using a proper thermodynamic logic.
STEP 4:
Now the points and the paths between the points are plotted using the plot command.
ERRORS OCCURED DURING PROGRAMMING
1.Error due to typo such as 'r' in place of 'cr' for mentioning compression ratio
STEPS TAKEN TO OVERCOME THE ERROR
1.By looking at the red hint popped in the command window.
2.By recaping the instructions provided by the instructor.
OUTPUT:
1.P-V DIAGRAM OF OTTO CYCLE
2.THERMAL EFFICIENCY OF OTTO CYCLE
CONCLUSION:
Thus the code is coded in matlab and executed successfully to visualize the p-v diagram and thermal efficiency of an otto cycle.