Project

Program to solve and generate plots for otto cycle. As a dynamic program using for loop.

program to solve and generate plots for otto cycle.

clear all
close all
clc
clf
% program to solve and generate plots for otto cycle.


Inputs variables for program
% initial values of p1 pressure in pascals(pa) t1 temperature in kelvin(k)
% gmma in radians and t3 final temp in kelvins 
disp('If you wish to enter variables manually enter 1 else 2');

y = input('enter');
if (y==1)
    
    p1 = input('pressure in pascals (pa)');            % pressure in pascals (pa) at initial point
    t1 = input('Initial temperature in Kelvins (k)');  % temperature in Kelvins (k) at initial point
    t3 = input('Final temperature in Kelvins (k)');    % temperature in Kelvins (k) at final point
    gamma = input('specific heat ratio gamma');        % specific heat ratio is constant.

% bd bore length in m , stroke length in m , cr compression ratio, con_rd m

    bd = input('Bore diameter in meters (m)');       % Bore diameter in meters (m)
    stroke = input('stroke in meters(m)');           % length of cylinder stroke in meters(m) 
    con_rd = input('connecting rode in meters (m)'); % displacement by the connecting rode in meters (m)
    cr = input('compression ratio no units');        % compression ratio no units 

    else
    
        p1 = 100000; % pressure in pascals (pa) at initial point
        t1 = 500;    % temperature in Kelvins (k) at initial point
        t3 =2500;    % temperature in Kelvins (k) at final point
        gamma = 1.4; % specific heat ratio is constant.

% bd bore length in m , stroke length in m , cr compression ratio, con_rd m

        bd = 0.1;       % Bore diameter in meters (m)
        stroke = 0.1;   % length of cylinder stroke in meters(m) 
        con_rd = 0.15;  % displacement by the connecting rode in meters (m)
        cr = 12;        % compression ratio no units 
end

calculation for volume of chamber


%calculations of first stste point values.

 swept_vol = (pi/4)*bd^2*stroke ; % volume of cylinder 
 clearence_vol = swept_vol/(cr-1);% volume left at the end of stroke.
 v1 = swept_vol+clearence_vol;    % complete volume 
        
 disp(v1*10^6);   % displays the overall volume od cylinder 
 disp('in cm^3'); % in cm^3 for understanding purposes only 

%calculations of second stste point values.

 v2 = clearence_vol;        % calculation at point 2
 p2 = p1*(v1/v2)^gamma;     % pressure at point 2
 t2 = (p2*v2*t1)/(p1*v1);   % temperature at point 2

%calculation for v_compression

 v_compression = engine_kinematics(clearence_vol,stroke,con_rd,cr,180,0);

%calculations of constant

 c1 = p1*v1^gamma;

%calculation of p_compression 

 p_compression = c1./v_compression.^gamma;

%calculation of 3rd state point
 v3=v2;
 p3=(p2*t3)/t2;

%calculation of 4rd state point

v4 = v1;
p4 = p3*(v3/v4)^gamma;
t4 = (p4*v4*t3)/(p3*v3);

%calculation of v_expansion

v_expansion = engine_kinematics(clearence_vol,stroke,con_rd,cr,0,180);
c2 = p3*v3^gamma; % calculationof constant at the final point.
p_expansion = c2./v_expansion.^gamma;


Plots to generate PV diagram
hold on  % This is the command to generate the diagram seen in the output.
% the below plots mark the points of pressure and volume at all the stages.
plot(v1,p1,'*','color','b');  
plot(v2,p2,'*','color','b');
plot(v3,p3,'*','color','b');
plot(v4,p4,'*','color','b');
% The next four plots generate the lines and curves connecting the points.
plot(v_compression,p_compression,'color','r','LineWidth',4);
plot(v_expansion,p_expansion,'color','r','LineWidth',4);
plot([v2 v3],[p2 p3],'color','g','LineWidth',4);
plot([v1 v4],[p1 p4],'color','g','LineWidth',4);
% lables are generated for graph
title('PV diagram for OTTO cycle');
xlabel('pressure');
ylabel('volume');

grid on


Thermal efficiency calculations


effcal = 1-((t4-t1)/(t3-t2));
eff =effcal*100;


State point calculation.


data = [1 p1 v1 t1; 2 p2 v2 t2; 3 p3 v3 t3; 4 p4 v4 t4];

columnnames= {'state point', 'pressure(pa)', 'volume(m3)', 'temperature (k)'};
T= table(data(:,1), data(:,2), data(:,3), data(:,4), 'variablenames',columnnames );

%print final output

disp(T)
fprintf('The Thermal efficiency is \n = %d percent', round(eff)); % rounded off to the nearest value

%%End of program

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.