Project

Solving and making plot of otto cycle in MATLAB

AIM: To write a code in MATLAB that can solve otto cycle and make plots for it.

THEORY:

  1. Otto cycle is also known as constant volume cycle as heat is added and rejected at constant volume processes. It consists of four processes.
  2. Process 1-2: Isentropic compression which is also called as reversible adiabatic compression since entropy being constant.
  3. Process 2-3: Constant volume heat addition, where heat is being added.
  4. Process 3-4: Isentropic expansion which is also called as reversible adiabatic expansion since entropy being constant.
  5. Process 4-1: Constant volume heat rejection, where heat is being rejected.

EQUATIONS INVOLVED:

We need to assume the geometric parameters such as

Bore

Stroke

Connecting rod length

compression ratio

Swept volume = `Π/4`× bore^2 × stroke

The above formula is used to find the cylinder volume (V) at different crank positions.

MATLAB CODE:

% CODE_1: Function to compute volume variation for isentropic processes

function [V] = piston_kinematics(bore,stroke,con_rod,cr,start_crank,end_crank)

a = stroke/2;
R = con_rod/a;

V_swept =( pi/4)*bore^2*stroke;
V_clearance = V_swept/(cr-1);

theta = linspace(start_crank,end_crank,100);

term1 = 0.5*(cr-1)
term2 = R+1-cosd(theta)
term3 = (R^2-sind(theta).^2).^0.5

V = (1 + term1*(term2-term3)).* V_clearance
end



% CODE_2: For plotting P-V diagram and calculating efficiency of air standard cycle
clear all
close all
clc

% inputs
gamma = 1.4
T3 = 2300; % temperature at state point 3 in kelvin

% defining variables at state no 1
P1 = 101325 % pressure at state point 1 in bar
T1 = 500

% engine geometric parameters
bore = 0.1; % diameter of the cylinder
stroke = 0.1; % length of the stroke
con_rod = 0.15; % connecting rod length
cr = 12; % compression ratio

% calculating the swept volume and clearance volume
V_swept = (pi/4)*bore^2*bore;
V_clearance = V_swept/(cr-1);

V1 = V_swept + V_clearance;
V2 = V_clearance

% variables at state no 2
% P2*V2^gamma = P1*V1^gamma
% P2 = P1*(V1/V2)^gamma
P2 = P1*cr^gamma
T2 = (((P2*V2)/(P1*V1))*T1)

constant_c = P1*V1^gamma
V_compression = piston_kinematics(bore,stroke,con_rod,cr,180,0)
P_compression = constant_c./V_compression.^gamma


% state variables at 3
V3 = V2
P3 = P2*(T3/T2)

constant_c = P3*V3^gamma
V_expansion = piston_kinematics(bore,stroke,con_rod,cr,0,180)
P_expansion = constant_c./V_expansion.^gamma

% state variables at 4
V4 = V1
P4 = P3*(1/cr)^gamma
T4 = (((P4*V4)/(P3*V3))*T3)

% efficiency of otto cycle
efficiency_otto_cycle = (1-(1/cr^(gamma-1)))*100


figure(1)
hold on

plot(V_compression,P_compression,'linewidth',2,'color','r');
line([V2 V3],[P2 P3],'linewidth',2,'color','g');
plot(V_expansion,P_expansion,'linewidth',2,'color','b');
line([V4 V1],[P4 P1],'linewidth',2,'color','y');
legend('Iscentropic Compression','CV Heat Addition','Iscentropic Expansion','CV Heat Rejection')
xlabel('volume')
ylabel('pressure')
title('PV diagram of otto cycle');
grid on

ERRORS:

The errors which I have faced during coding for plotting of P-V diagram in MATLAB are as follows:

The above error has occured because of the typo where capital 'V' has to be considered for V_compression instead of 'v'

EXPLANATION:

The coding for the P-V diagram for the otto or the air standard cycle is done in two parts in MATLAB:

  1. The starting part of the code 1 defines the function which is created for mapping the data obtained from the cylinder volume at different crank positions, for which a mathematical relation has been used as shown in the equations involved.
  2. It is used inorder to accurately predict the variations in the plot i.e., isentropic compression and isentropic expansion processes respectively.
  3. The function is then invoked into the code 2 where all the geometric parameters such as bore, stroke, connecting rod length, compression ratio have been considered and the thermodynamic parameters such as pressure, temperature, volume are evaluated at each end state.

RESULT:

The plot which is generated by the above code is as follows:

Efficiency of the otto cycle has been calculated as 62.9893%

CONCLUSION:

Hence, plot of P-V and thermal efficiency of the otto cycle has been calculated in MATLAB.

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.