All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Aim: To demonstrate the working of an otto cycle and write a MATLAB code to plot the graphs and calculate the thermal efficiency. Theory: The Air-Standard cycles work on the principle that the working medium is air. These cycles gained became more and more popular in the theoretical analysis of an Internal Combustion Engine.…
ARTH SOJITRA
updated on 12 Jun 2020
Aim:
To demonstrate the working of an otto cycle and write a MATLAB code to plot the graphs and calculate the thermal efficiency.
Theory:
The Air-Standard cycles work on the principle that the working medium is air. These cycles gained became more and more popular in the theoretical analysis of an Internal Combustion Engine. The Otto cycle is the one in which the working fluid inside the engine is Petrol but is assumed as air for theoretical aspects i.e. to calculate the thermal efficiency and engine parameters.
Before diving into the detail of the analysis of the Otto cycle we need to be familiar with some of the terms related to the cylinder of an I.C. Engine. Consider the basic cylinder of a petrol engine.
The basic Otto cycle comprises of four main strokes.
1.) The intake Stroke: Which comprises of the piston moving from the topmost position to the bottommost position which sucking in the fresh charge.
2.) The Compression Stroke: It is the stroke in which the cylinder moves from the Bottom Dead Center (BDC) to the Top Dead Center (TDC) such that it compresses the fresh fuel charge mixture so that it's temperature rises sufficiently to ignite the fuel via a spark plug. Also in the compression stroke, the head of the piston plays a crucial role in creating turbulence for the fresh charge so as to ensure uniform mixing.
3.) The power Stoke: With the compressed fuel, the spark is initiated causing a huge release of energy which forces the piston down delivering the power to the engine.
4.) The Exhaust Stroke: After the transfer of power to the crankshaft the residual gases remain which needs to be excreted out so as to allow a new charge to come inside and the combustion to take place which is done in the expansion stroke.
Consider the following basic P-V Diagram representing the Ideal Otto cycle of an IC Engine.
Process 1-2 is the compression stroke which takes the state of the fuel from point 1 to 2 with an isentropic compression. Process 2-3 is the combustion process, in which the spark is assumed to be initiated and completed in an infinitesimal amount of time such that the combustion of the fuel is instantaneous without the loss of time. Process 3-4 is the Expansion process which delivers the energy obtained via the fuel burnt to the engine crankshaft. This process is also assumed to be isentropic. Process 4-1 is the exhaust stroke with throws away the residual gases out of the engine so as to allow the fresh intake of the new charge.
IDEA
The main idea behind coding this challenge is to understand how to find the state points 1,2,3 and 4 and how to join them with appropriate plots.
State point 1 is fairly simple as it is the initial condition of the engine at the time of intake and is known. So we know P1, T1 from the initial conditions. To calculate the state point 2 we use the principle of the isentropic process i.e.
P1Vγ1=P2Vγ2 where γ=CpCv.
We know V2 as the clearance volume of the engine will be provided and hence P2can be calculated from the equation above. Hence knowing P2&V2 we can easily calculate the Temperature at state point 2 i.e. T2
Process 2-3 which is assumed as a constant volume heat addition and knowing the Volume at state point 2 as V2 we can assert that V3=V2. Now generally in the engine thermodynamics, the temperature of the combusted products is provided or is set as an independent variable to facilitate the calculation of other variables. Hence assuming that T3 or P3 is known we can calculate the other by :
P3T3=P2T2
Now that we know the calculation of P3andT3 we can apply the isentropic governing equation between state points 3 and 4, and calculate the state variables at point 4.
Process 4-1 is a simple isochoric process hence joining points 4 and 1 with a straight line would do the job.
Now enough with the theoretical calculation of the state variables, we must also understand how to calculate the thermal efficiency of the engine as it plays a crucial role in the engine analysis and development.
Again consider the graph below:
Process 1-2:
Work done = Rγ−1(P1V1−P2V2)
Heat transfer = 0. ( Isentropic process )
Process 2-3:
Work done = 0 ( ΔV=0 )
Heat transfer = Cv(T3−T2). [ This is the energy that the fuel releases when it is burnt ]
Process 3-4:
Work done = Rγ−1(P3V3−P4V4)
Heat transfer = 0. ( Isentropic process )
Process 2-3:
Work done = 0 ( ΔV=0 )
Heat transfer = Cv(T1−T4). [ This is the energy that the residual gases reject ]
One important thing to note in our observation is that we assume constant volume heat addition and rejection. However, the reality is far beyond that. There are so many factors to be taken into consideration like the ignition delay, variable specific heat, etc. However, the scope of all this is beyond the scope of this project and we shall limit our observation and calculations to only the super ideal cases.
So in the overall process work output = Rγ−1(P3V3−P4V4)
And the overall heat addition = −Cv(T4−T1)+Cv(T3−T2)
So the overall thermal efficiency can be written as :
η=Work doneEnergy input
Substituting into the formula we get:
η=Q2−Q1Q2
where Q2 is the energy input and Q1 is the energy output
η=1−Q1Q2
Substituing the values we get:
η=1−Cv(T4−T1)Cv(T3−T2)
Simplifying we get:
η=1−T4T3⎡⎣1−T1T41−T2T3⎤⎦
Now using the isentropic process state equation we get :
TVγ−1=c
T3Vγ−13=T4Vγ−14→T4T3=(V3V4)γ−1=rγ−1c
so then we have ,
T2T1=(V2V1)γ−1 and
T3T4=(V4V3)γ−1
Now as :
V2V1=V3V4=rc(Compression ratio) we get
T2T1=T3T4 and hence
T1T4=T2T3
Substituting into the formula we get:
η=1−1(rc)γ−1⎡⎣1−T1T41−T1T4⎤⎦=1−1(rc)γ−1
Which is the thermal efficiency of the Engine:
Now we shall see how to implement the concepts discussed above in MATLAB Program:
First of all we create a basic script file defining all the initial parameters:
clear all;
close all;
clc;
%
% In this program I shall be demonstrating the Methodological Plotting of
% an Otto cycle
%
% Define the initial variable at point 1
P1 = 101325;
T1 = 500;
% Defining the engine geometric parameters
bore = 0.1; % bore
stroke = 0.1; % Stroke
con_rod_length = 0.15; % Connecting rod length
r_c = 12; % Compression ratio
v_swept = pi/4*bore^2;
v_clearance = v_swept/(r_c-1);
% Volume at point 1 is nothing but the total volume
V1 = v_clearance + v_swept ;
% Volume at state point 2 is nothing but the clearance volume
V2 = v_clearance;
Explanation: This MATLAB Code basically creates the initial variables of the engine parameters and the state variables
Now to facilitate the calculation and the plotting of curves between points 1 and 2 we must create a function that accurately describes the variation of the volume with respect to the crank angle. The following MATLAB function does this job:
function V_variation = V_with_theta(start_angle,end_angle,...
stroke,con_rod_length,r_c,v_clearance)
%
% THis function basically finds the variation of the Volume with respect to
% theta
%
% Creating a linearly spaced vector for the theta values
theta = linspace(start_angle,end_angle,100);
% Defining the variables of the equation
a = stroke/2;
R = con_rod_length/a;
% Defining the individual terms of the equation
term1 = 0.5*(r_c-1);
term2 = R + 1 - cosd(theta);
term3 = R^2 - (sind(theta)).^2;
term3 = term3.^(0.5);
% Calculating a vector of the volume elements
V_variation = ( 1 + term1 *(term2 - term3) ) * v_clearance;
end
Explanation: This code takes in input the engine parameters and the start of the crank angle and the end of the crank angle and creates a vector distribution of the volume variables as per the linear variation of theta which is a reasonable assumption to make. One crucial thing to note here is that the variation of V itself is not linear but is dependent upon the variation of the crank angle.
Now after the creation of the artilleries needed to attack this problem we are now ready to compute the state variables and the distributions. The following MATLAB Code does this job:
%
% Creating the variation of theta from the BDC to TDC for the compression
% process
%
% BDC - Bottom Dead Center
% TDC - Top Dead Center
%
V_variation_1_to_2 = V_with_theta(180,0,...
stroke,con_rod_length,r_c,v_clearance);
%
% Now using this variation I will calculate the values of the state
% variables at each individual points\
%
% using the isentropic governing equation
% PV^(gamma) = constant
%
P_variation_1_to_2 = (P1 * V1.^gamma ./ V_variation_1_to_2.^(gamma));
% Now that we knwo the state variables at point 2
P2 = P_variation_1_to_2(end); % last element
V2 = V_variation_1_to_2(end); % last element
T2 = T1*P2*V2/P1/V1; % using the ideal gas law
% To calculate the state variables at point 3
T3 = 2000; % Assume
V3 = V2; % Constant volume process
P3 = P2*T3/T2; % Assuming the ideal gas law with V = constant
%
% Creating the variation of theta from the TDC to BDC for the Expansion
% Process
%
% BDC - Bottom Dead Center
% TDC - Top Dead Center
%
V_variation_3_to_4 = V_with_theta(0,180,...
stroke,con_rod_length,r_c,v_clearance);
%
% Now using this variation I will calculate the values of the state
% variables at each individual points\
%
% using the isentropic governing equation
% PV^(gamma) = constant
%
P_variation_3_to_4 = (P3 * V3.^gamma ./ V_variation_3_to_4.^(gamma));
% state variables at point 4
P4 = P_variation_3_to_4(end); % last element
V4 = V_variation_3_to_4(end); % last element
T4 = P4*V4*T3/P3/V3; % Using the Ideal gas law
Explanation: The above MATLAB Code basically computes the state variables at all the 4 points and computes a vector of state variables between the points 1-2 and 3-4 as the variation between them is not linear and the variation between the points 2-3 and 4-1 is linear and hence doesn't require any extra computation of the points between them.
Now after the computation of the points we are now ready to plot them in a graph. This is achieved by the following MATLAB Code.
%
% Now all of out state variables have been calculated
%
% It is time to join them using appropriate curves
figure(1);clf;
% isentropic variation between 1-2
plot(V_variation_1_to_2 , P_variation_1_to_2 , 'linew' , 3);
hold on;
% Straight line with constant volume between 2-3
plot([V2 V3],[P2 P3], 'linew' , 3);
% isentropic variation between 3-4
plot(V_variation_3_to_4 , P_variation_3_to_4 , 'linew' , 3);
hold on;
% Straight line with constant volume between 4-1
plot([V4 V1],[P4 P1], 'linew' , 3);
hold off;
% Making the plot look a bit nicer
grid on;
grid minor;
% adding the labels
xlabel('Volume in m^3');
ylabel('Pressure in Pa');
% adding the title
title({'PV diagram of an IC engine';...
['Using the Compression ratio : ' num2str(r_c)]});
legend('Compression','Combustion','Expansion','Exhaust');
set(gca,'Fontsize',20);
Explanation: As the state variables are discreet functions and points we must use a clever technique of plotting them using the MATLAB hold on command which plots all the curves in a single graph with smooth variations locally. Legends are added to better visualize the processes occurring in the Engine.
The following plot was obtained:
To output the thermal efficiency of the engine the following code is implemented which is direct usage of the formula as derived above in the theory section:
% calculating the thermal Efficiency
thermal_efficiency = 1 - 1/r_c^(gamma-1);
% printing the thermal efficiency:
fprintf(['The thermal efficiency of the cycle is : ' ...
num2str(thermal_efficiency)]);
fprintf('\n');
The following output was obtained in the command window:
The above were the outputs considering the Compression ratio as 12. Let us look at a few different cases by changing the CR.
1.) Cr = 6
The following outputs were obtained:
The thermal efficiency obtained is:
2.) Cr = 3
The following outputs were obtained:
The thermal efficiency obtained is:
3.) CR = 15
The following outputs were obtained:
The thermal efficiency obtained is:
4.) Cr = 19
The following outputs were obtained:
The thermal efficiency obtained is:
5.) Cr = 29
The following outputs were obtained:
The thermal efficiency obtained is:
Observation: As we increase the Compression ratio we see that the thermal efficiency also increases. This can be directly confirmed from the formula as rc increases 1rc will decrease and hence the difference will increase thereby increasing the thermal efficiency of the engine. Also, it is imperative to note that Thermal efficiency is only a function of the compression ratio of the engine which makes it easy to do theoretical analysis regarding the same. One might tend to think that he can keep on increasing the CR to get higher and higher efficiency, however, as we increase the CR other factors start showing their impediment in compromising the efficiency. If we increase the CR means that we have to increase the size of the engine. A bigger engine means more mouse, more manufacturing cost to name a few. Also increased Cr results in a significant temperature rise which can cause harm to the components of the engine. Hence an optimum Cr is to be chosen while designing the IC Engine so as to compromise between the efficiency and the secondary factors.
Errors Faced while programming:
The following were the errors faced while coding of the challenge:
1.) One of the main errors was in the coding of the function to generate the vector of the Volume Values. As can be seen in the small segment of the code the user has written almost everything correctly however there is a subtle mistake.
% Defining the individual terms of the equation
term1 = 0.5*(r_c-1);
term2 = R + 1 - cosd(theta);
term3 = R^2 - (sind(theta)).^2;
term3 = term3^(0.5);
The term 3 is a vector and MATLAB fails to understand it to take the root of it. Any human will get confused if you ask him to take the square root of the vector.
This problem gives the following error in the Command Window:
The error is self-explanatory in the sense that we must make the matrix dimensions agree to allow the computation hence this issue can be resolved by using the element-wise operator as shown in the corrected code below:
% Defining the individual terms of the equation
term1 = 0.5*(r_c-1);
term2 = R + 1 - cosd(theta);
term3 = R^2 - (sind(theta)).^2;
term3 = term3.^(0.5);
And now the code works just fine.
2.) The second error made was the incorrect computation of the Volume vectors:
%
% Creating the variation of theta from the TDC to BDC for the Expansion
% Process
%
% BDC - Bottom Dead Center
% TDC - Top Dead Center
%
V_variation_3_to_4 = V_with_theta(180,0,...
stroke,con_rod_length,r_c,v_clearance);
%
% Creating the variation of theta from the BDC to TDC for the compression
% process
%
% BDC - Bottom Dead Center
% TDC - Top Dead Center
%
V_variation_1_to_2 = V_with_theta(0,180,...
stroke,con_rod_length,r_c,v_clearance);
The user has provided the incorrect passing inputs inside the function. Basically he has switched the inputs. It is a very common mistake that any novice guy tends to make. It doesn't provide any error as such as the computations will be carried out just fine. However, there will be an error in the final output graph obtained as is shown below:
As can be seen, the graph gives completely unphysical results. This issue can be corrected very easily by passing the inputs in the correct order.
3.) One more mistake that can be made by the user is the use of the incorrect plotting command as is shown below in the MATLAB Code:
%
% Now all of out state variables have been calculated
%
% It is time to join them using appropriate curves
figure(1);clf;
% isentropic variation between 1-2
plot(V_variation_1_to_2 , P_variation_1_to_2 , 'linew' , 3);
hold on;
% Straight line with constant volume between 2-3
plot([V2 P2],[V3 P3], 'linew' , 3);
% isentropic variation between 3-4
plot(V_variation_3_to_4 , P_variation_3_to_4 , 'linew' , 3);
hold on;
% Straight line with constant volume between 4-1
plot([V4 P4],[V1 P1], 'linew' , 3);
hold off;
Here we can clearly understand that the user wanted to plot the straight lines between the states 2-3 and 4-1 however the use of the plotting command is incorrect. This doesn't give any error but however, gives meaningless plot as is shown below:
This can be corrected by the plotting command wisely by passing the arguments to draw a line in the correct order.
4.) One more mistake that the user can make is the incorrect use of the formula to calculate the thermal efficiency as is shown in the code below:
% calculating the thermal Efficiency
thermal_efficiency = 1 - 1/r_c^gamma-1;
% printing the thermal efficiency:
fprintf(['The thermal efficiency of the cycle is : ' ...
num2str(thermal_efficiency)]);
fprintf('\n');
This doesn't give any errors as such but however, it results in completely unphysical efficiency as is shown in the output below:
The User may think what is the problem. The problem is basically how the user has defined formula to calculate the thermal efficiency. He has forgotten to put parenthesis in the denominator which allows the calculation of the term rγ−1c. One more way to check that the answer is completely unphysical is that the user is getting negative efficiency which is completely preposterous.
5.) One more place in which anyone can mistake is the definition and the calling of the function :
function V_variation = V_with_theta(start_angle,end_angle,...
stroke,con_rod_length,v_clearance)
%
% THis function basically finds the variation of the Volume with respect to
% theta
%
As can be seen in the definition of the function the user does not tend to include the compression ratio as input because he may have defined it inside the function. However, while calling the function the user tends to pass the input argument regarding the compression ratio which results in a fatal error as was obtained on running it in MATLAB as shown below:
The User tends to call the function using the following MATLAB code:
%
% Creating the variation of theta from the BDC to TDC for the compression
% process
%
% BDC - Bottom Dead Center
% TDC - Top Dead Center
%
V_variation_1_to_2 = V_with_theta(180,0,...
stroke,con_rod_length,r_c,v_clearance);
He is bound to get an error stating something about the arguments passed.
Well, this error is fairly easy to correct. The user needs to pass in the right set of arguments in the correct order to ensure the smooth running of the function.
6.) One more error that the user could make is in the calculation of state variable at individual points as is shown in the MATLAB Code below:
% Now that we knwo the state variables at point 2
P2 = P_variation_1_to_2(end); % last element
V2 = V_variation_1_to_2(end); % last element
T2 = T1*P2*V2/P2*V2;
% state variables at point 4
P4 = P_variation_3_to_4(end); % last element
V4 = V_variation_3_to_4(end); % last element
T4 = P4*V4*T3/P3*V3;
It is clearly visible that the calculation of the variation of the variable T_4 is not done properly and hence would give unphysical results which it indeed gives as is shown in the figure below:
We can see the pressure rise from the process 2-3 is humongous. This is clearly unacceptable and the user should get a hint from this that he/she has made a silly mistake in the calculation.
Conclusion:
In this report, the Otto cycle was studied and was plotted using MATLAB. Important insights are obtained on the efficiency and the plotting of the cycle. Some common errors are also seen that the user tends to make and it is seen how to overcome them. MATLAB is a very powerful tool especially when it comes to numerical computing.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Genetic Algorithm
Aim: To understand the concept of the genetic algorithm and write code in MATLAB to optimize the stalagmite function and find the global maxima of the function. Theory: The stalagmite function is a function with 4 components : 2 sine components in each of the axis direction 2 normal…
30 Jun 2020 10:42 PM IST
Curve fitting in MATLAB:
Aim: Perform the linear and cubic fit for a given set of data and then gain insights on the several parameters that can be used to identify a good fit. Theory: Curve fitting is the process of constructing a mathematical curve to fit the data points according to some criteria to get a mathematical formula…
19 Jun 2020 09:02 PM IST
FVM Literature
Objective : To study the theory behind the various interpolation schemes and the flux limiters in case of the Finite Volume Method. Why the need for FVM? In advanced CFD approaches with highly unstructured grids, we tend to use a method called as the finite Volume Method ( FVM ). While in the normal discretization…
18 Jun 2020 07:40 AM IST
Air standard Cycle
Aim: To demonstrate the working of an otto cycle and write a MATLAB code to plot the graphs and calculate the thermal efficiency. Theory: The Air-Standard cycles work on the principle that the working medium is air. These cycles gained became more and more popular in the theoretical analysis of an Internal Combustion Engine.…
12 Jun 2020 01:27 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.