Project

Air standard Cycle

Aim

To write a code for solving Otto cycle and to plot the P_V diagram and also to solve the thermal efficiency of the cycle using MATLAB.

Procedure and Solution

code for creating plot of P_V diagram and to solve thermal efficiency as follow;

close all
clc

%constants  


bore = 0.25;
stroke = 0.375;
connecting_rod = 0.5625;
g = 1.4;                %adiabatic index 
v_c = 0.00263;          %clearence volume
p1 = 101325;
t1 = 323;
p3 = 2.5e+6;
d = bore;
l = stroke;


%needed
v_s = (pi/4)* l * d^2;  %swept volume
v1 = v_s + v_c;
v2 = v_c;
r = v1/v2;              %compression ratio
t2 = t1 * r^(g-1);
p2 = p1*(v1/v2)^g;

c = p1*v1^g;
v_compression = e_k(bore,stroke,connecting_rod,r,180,0);
p_compression = c./v_compression.^g;

t3 = (t2 * p3)/ p2;
v3 = v2;
v4 = v1;
p4 = p3 * (v3/v4)^g;
t4 = t3/r^(g-1);

c = p3*v3^g;
v_expansion = e_k(bore,stroke,connecting_rod,r,0,180);
p_expansion = c./v_expansion.^g;


%ploting P_V Diagram
figure(1)
hold on
xlabel 'Volume'
ylabel 'Pressure'
title 'P-V diagram'
plot(v1,p1,'r*')
plot(v_compression,p_compression)
plot(v2,p2,'r*')
plot([v2 v3],[p2 p3])
plot(v3,p3,'r*')
plot(v_expansion,p_expansion)
plot(v4,p4,'r*')
plot([v1 v4],[p1 p4])


% Thermal efficiency of Air standard cycle or Otto Cycle
neta_otto = 1 - (1/(r)^(g-1))
Thermal_efficiency_Of_otto_cycle = neta_otto * 100

In this problem the constant values like Bore diameter, Stroke length, connecting rod length ,initial pressure ,temperature and maximum temperature are taken from a problem given in my Thermal engineering book and the code is explained below.

Code Explanation

Based on Thermodynamic formulae, first swept volume is found here it is denoted by 'v_s'

v_s = (pi/4) * l * d^2

here l = stroke ,and d = bore

then volume at initial condition is found by

v1 = v_s + v_c

then compression volume 'v2' is determined by

v2 = v_c

from it is a constant volume process then,

v1 = v4 i,e volume at initial is volume at the final condition also volume compression is equal at volume at the beginning of the expansion therefore,

v2 = v3

then compression ratio it is denoted by 'r' is found by

r = v1/v2 (or) r = v4/v3 in the above coding r = v1/v2 is used

for finding pressure at compression p2 i have used reversible adiabatic process formula

p2/p1 = (v1/v2)^g

from this p2 = p1 * (v1/v2)^g

again by using same method i have find p4

p4 = p3 * (v3/v4)^g

then i have inserted a function of piston kinematics based on it's geometric function and that code is inserted below

function [A] = e_k(bore,stroke,con_rod,c_r,start_ang,end_ang)

      a = stroke/2;
      r = con_rod/a;

      v_s = (pi/4)*bore^2*stroke;
      v_c = v_s/(c_r - 1);

      theta = linspace(start_ang,end_ang,100);
      e1 = 0.5*(c_r - 1);
      e2 = r + 1 - cosd(theta);
      e3 = (r^2 - sind(theta).^2).^0.5;

      A = (1 + e1*(e2 - e3)).*v_c;


end

here the actual equation is splitted into three terms they are e1,e2 and e3

here V = A;Vc = v_c;rc=c_r;R = r

e1 = 0.5*(c_r - 1)

e2 = r + 1 -cosd(theta)

e3 = (r^2 - sind(theta).^2).^0.5

by doing this all in the a form of function and this function is saved and called in the otto cycle coding to get the value of volume and pressure during compression from v1,p1 to v2,p2;

here by using the reversible adaibatic compression process p*v^g = constant;

I acquire 'c' and then from the above function we get v_compression value and by using ths value in the same reversible adaibatic compression process formula i found that p_compression value;by using this same condition value of volume and pressure during expansion is found.

Next moving on to Ploting the P_V diagram

Plot P_V Diagram

In the X-axis Volume is taken and it is coded as {xlabel 'Volume'} and in Y-axis Pressure is taken and it is coded as {ylabel 'Pressure'} and the Title of the plot is coded as {title 'P_V Diagram'},

then moving on to plot and joining them by using 'plot' command all the point initial,final and intermediate points are as follow

plot(v1,p1,'r*')

plot(v2,p2,'r*')

plot(v3,p3,'r*')

plot(v4,p4,'r*') (note: here the r denote color of the point and it is in red color and * indicates the style of the point)

and for joining the points for getting the cure i used the values of v_compression,p_compression for compression process and v_expansion and,p_expansion for expansion process

plot(v_compression,p_compression)

plot(v_expansion,p_expansion)

(note: here i don't mention any color and line style and linewidth to the curve)

then for joining the points v2 and v3,v1 and v4 i used the following

plot([v1 v4],[p1 p4])

plot([v2 v3],[p2 p3])

(note: here i don't mention any color and line style and linewidth to the curve)

from the above two plot the plot command consider v1 and v4 as a matrix an forms a straight line based on value,

then finally the plot as like below

After completing this plot moving on to compute the value of thermal efficiency of Air standard cycle or Otto cycle are follow

Finding Thermal Efficiency

based on the formula for finding the efficiency of otto cycle are as follow

from this formula i found the thermal efficiency of the above otto cycle problem and the results are inserted in the form of image and Thermal_efficiency_Of_otto_cycle is obtained by multipliying the value obtained from the neta_otto with 100 to get it in percentage.

Errors:

I don't even get any error from the above code but i got error while coding the code which was used in the video by instructor and then just tried my own by using the concept which was taught by the instructor and the error which I faced during the code taught by the instructor, that the plot is not like the actual it is like a triangle and i don't have any screen short about that error due to those error i just delete that codes and started a new code.but i have a graph that is irregular not like the actual one which is shown below,

The error plot

Result:

Finally, by overcome those above errors the challenge for solving Otto cycle problem and to plot on the P_V diagram is done and also i find the thermal efficiency of the otto cycle using MATLAB code.

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.