Project

Otto cycle using MATLAB

Aim: To plot pressure vs volume of an otto cycle using Matlab.

Governing equation:
for Isentropic process 1-2 and 3-4
P1V1^gamma = P2V2^gamma
(P1V1)/T1 = (P2V2)/T2
change of volume inside the combustion chamber is given by     
(V/V_compression)=1+0.5*(cr-1)[R+1-cosd(theta)-((R^2 - sind(theta))^2)^0.5]

Input parameters:
gamma = 1.8
T3 = 5000
P1 = 1005
T1 = 430

Geometric parameters:
bore = 0.2
stroke = 0.6
con_rod = 4
cr = 10

MATLAB Code:
%code for the function to determine the piston kinematics
function [V]=otto_cycle_piston_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank)
%engine geometric parameters
a = stroke/2
R = con_rod/a

%caluclating swept volume and clearence volume
v_swept = (pi/4)*bore^2*stroke
v_clearence = v_swept/(cr-1)

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_clearence
end

Code explanation:
*a function is called named otto_cycle_piston_kinematics whose output is V with input                   parameters bore,stroke,con_rod,cr,start_crank,end_crank
*the importance to call the function is to use it in the main program 

Main code:
close all
clear all
clc

%input parameters
gamma = 1.8
T3 = 5000

%state variables
P1 = 1005
T1 = 430

%engine geometric parameters
bore = 0.2
stroke = 0.6
con_rod = 4  
cr = 10

%caluclating swept volume and clearence volume
v_swept = (pi/4)*bore^2*stroke
v_clearence = v_swept/(cr-1)
V1 = v_swept+v_clearence
V2 = v_clearence

%state variables at state point 2
%P1V1^gamma = P2V2^gamma
P2 = P1*cr^gamma

%p1v1/t1 = p2v2/t2
constant_c = P1*V1^gamma
T2 = P2*V2*T1/(P1*V1)
v_compression =  otto_cycle_piston_kinematics(bore,stroke,con_rod,cr,180,0)
p_compression = constant_c./v_compression.^gamma

%state variable at state point 3
V3 = V2
%p3v3/t3 = p2v2/t2
P3 = P2*V2*T3/(T2*V3)

%state variable at state point 4
V4 = V1
%p4v4^gamma = p3v3^gamma
P4 = P3*(V3/V4)^gamma
constant_c = P3*V3^gamma
v_expansion =  otto_cycle_piston_kinematics(bore,stroke,con_rod,cr,0,180)
p_expansion = constant_c./v_expansion.^gamma

%thermal efficency 
t_eff = 1-(1/cr^(gamma-1))

figure(1)
hold on
plot(V1,P1,'*','color','red')
plot(v_compression,p_compression)
plot(V2,P2,'*','color','blue')
plot(V3,P3,'*','color','yellow')
plot(v_expansion,p_expansion)
plot(V4,P4,'*','color','green')
line([V2 V3],[P2 P3],'linewidth',3)
line([V1 V4],[P1 P4],'linewidth',4)

Maincode Explaination
1.Assumed input parameters, state variables at point 1 and engine geometric parameters
2.using the formula we have caluclated swept volume and clearence volume 
3. using the governing equation we have calculated P2 and T2
4. we have called the function V that we have created and calculated v_compression and p_compression 
5. using the same steps we have calculated P4 and v_expansion and p_expansion 
6.p-v diagram is plotted using all the state points 
7.the thermal efficiency of the otto cycle is caluclated 

Error faced:
*the element-wise operator is missing in the command
*the error was rectified using the element-wise operator 


Output:
1.P-v Plot of otto cycle is plotted in Matlab.
2. Thermal efficiency of Otto cycle is 0.8415 or 84.15%

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.