To solve an Otto cycle, create a PV diagram and output the Thermal efficiency of the engine using MATLAB
AIM: To write a program in MATLAB that can solve an Otto cycle, create a PV diagram and output the Thermal efficiency of the engine.
THEORY:
Formulas used are :
- Swept volume = (π/4)*bore^2*stroke
- Clearance volume = swept_volume/(compression_ratio - 1)
- Ideal gas equation is given by,
pressure*volume=universal_gas_constant*temperature
- For an Isentropic process, pressure*(volume^gamma) = constant
- Efficiency of the ottocycle = 1-(1/compression_ratio)^(gamma-1)
- Volume between top deck center and bottom deck center = (1+ (0.5*(cr-1)).*((r+1-cosd(theta))- ((r^2-sind(theta).^2).^0.5))).*vc
Where, cr = compression ratio
r = ratio of connecting
rod and crank fin radius
theta = array containing angles between start crank angle and end crank angle
vc = clearance volume
- Crank fin radius = stroke/2
CODE:
Main code:
clear all
close all
clc
%inputs
gamma=1.4;
p1=101426; %pressure at point 1
t1=600; %temperature at point 1
t3=2450; %temperature at point 3
bore=0.1;
stroke=0.1;
con_rod=0.15; %connecting rod
cr=12; %compression ratio
%calculation
vcompression=ottocycle_pistonkinematics(bore,stroke,con_rod,cr,180,0); %compression volume values
vexpansion=ottocycle_pistonkinematics(bore,stroke,con_rod,cr,0,180); %expansion volume values
vswept=(pi/4)*bore^2*stroke; %swept volume
vclearance =vswept/(cr-1); %clearance volume
v1=vswept + vclearance; %volume at point 1
v2=vclearance; %volume at point 2
p2=p1*(cr)^gamma; %pressure at point 2
t2=(p2*v2*t1)/(p1*v1); %temperature at point 2
v3=v2; %volume at point 3
p3=t3*p2*v2/(t2*v3); %pressure at point 3
v4=v1; %volume at point 4
p4=p3*(v3/v4)^gamma; %pressure at point 4
constantc=p1*v1^gamma; %for compression line
pcompression=constantc./vcompression.^gamma; %compression pressure values
constante=p3*v3^gamma; %for expansion line
pexpansion=constante./vexpansion.^gamma; %expansion pressure values
%plotting
figure(1)
hold on %to avoid overwrite
plot(v1,p1,'*','color','r') %pointing the point 1
plot(vcompression,pcompression,'color','g') %pointing the values between point 1 and point 2
plot(v2,p2,'*','color','r') %pointing the point 2
plot([v2 v3],[p2 p3],'color','magenta') %joining the point 2 and point 3
plot(v3,p3,'*','color','r') %pointing the point 3
plot(vexpansion,pexpansion,'color','yellow') %pointing the values between point 3 and point 4
plot(v4,p4,'*','color','r') %pointing yhe point 4
plot([v4 v1],[p4 p1],'color','black') %joining of point 1 and point 4
title('P-V diagram of otto cycle') %title of the plot
xlabel('Volume')
ylabel('Pressure')
%output
Efficiency_of_the_ottocycle=1-(1/cr)^(gamma-1) %calculating the efficiency of the otto cycle
Function:
function [v]=ottocycle_pistonkinematics(bore,stroke,conrod,cr,startcrank,endcrank)
a=stroke/2; %crank fin radius
r=conrod/a; %ratio of conrod and crank fin radius
vs=pi/4*bore^2*stroke; %swept volume
vc =vs/(cr-1); %clearance volume
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)).*vc; %volume between top deck center and bottom deck center
end
OUTPUT:
Command window
PV diagram
EXPLANATION OF THE CODE AND THE OUTPUT:
In the main code, at first I have taken the required inputs. Then I calculated the values of volume during compression using the user-defined function ‘ottocycle_pistonkinematics’ and stored them in the array ‘vcompression’. Similarly, the values of volume during expansion are stored in the array ‘vexpansion’. This volume is the volume between top deck center and bottom deck center at different values of ‘theta’. Then , I calculated different parameters at different points using the formulas given above in theory. Then I calculated the values of pressure during compression using the user-defined function ‘ottocycle_pistonkinematics’ and stored them in the array ‘pcompression’. Similarly, the values of pressure during expansion are stored in the array ‘pexpansion’. While plotting, I plotted the four points and marked them by ‘*’. I plotted the lines of isentropic compression , constant volume heat addition, isentropic expansion and constant volume heat rejection processes using green, magneta, yellow and black colours respectively. At last, I calculated the Thermal efficiency of the engine using the formula given in theory above.
In the user-defined function ‘ottocycle_pistonkinematics’, I calculated the volume between the top deck center and the bottom deck center at different values of theta which are stored in the array ‘v’.
In the output, I displayed the Thermal efficiency of the engine in the command window. I plotted the PV diagram of otto cycle showing isentropic compression , constant volume heat addition, isentropic expansion and constant volume heat rejection processes using green, magneta, yellow and black colours respectively.
ERROR:
Error 1. I encountered the following error in line no. 44 , stating that ‘invalid colour or line style’.
Error 1
STEPS TAKEN TO OVERCOME THE ERROR:
In the main code (line no. 44, 46, 48 and 50), I wrote ‘*’ in the place of point1,point2,point3 and point 4. This removed my error.
RESULT:
A program in MATLAB that can solve an Otto cycle, create a PV diagram and output the Thermal efficiency of the engine is created.