Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views24 pages

Matlab Program

The document outlines a program for calculating the velocity, acceleration, gas pressure, and engine torque of a piston engine using mathematical models based on crank angle. It includes multiple sections with plots demonstrating the relationships between crank angle and various engine parameters, such as piston velocity, acceleration, gas pressure, and torque for one, two, and four cylinders. The calculations involve trigonometric functions and pressure-volume relationships to simulate engine behavior across different crank angles.

Uploaded by

basilmjd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views24 pages

Matlab Program

The document outlines a program for calculating the velocity, acceleration, gas pressure, and engine torque of a piston engine using mathematical models based on crank angle. It includes multiple sections with plots demonstrating the relationships between crank angle and various engine parameters, such as piston velocity, acceleration, gas pressure, and torque for one, two, and four cylinders. The calculations involve trigonometric functions and pressure-volume relationships to simulate engine behavior across different crank angles.

Uploaded by

basilmjd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Velocity and acceleration program

clear all
clc
w=376.99;
r=0.022225;
L=0.079375;
d=0:720;
a=d*pi/180;
l=r/L;
V=r*w*(sin(a)+0.5*l*sin(2*a));
A=r*w^2*(cos(a)+l*cos(2*a));
subplot(1,2,1);
plot(a,V,'r');
xlabel('crank angle in radians');
ylabel( 'Velocity of Piston (m/rad^2)');
title('Velocity of Piston Vs Crank angle in radians');
legend('Velocity of Piston (m/rad^2)');
grid on
box on
hold on

subplot(1,2,2);
plot(a,A,'b');
xlabel('Crank angle in radians');
ylabel('Acceleration of piston (m/rad^2)');
title('Acceleration of piston Vs Crank angke');
legend('Acceleration of piston (m/rad^2)');
grid on
box on
hold on
Gas pressure inside the cylinder
m=[];
n=[];
r=0.022225;
L=0.079375;
Q=r/L;
Vc=0.0000192482453744;
Ap=0.002858123316;
for u=0:720
if u>0&&u<180
p=0.093;
end
if u>180&&u<360
n1=1.37;
B=asind(Q*(sind(u)));
Sx=(r*(1-cosd(u)))+(L*(1-cosd (B)));
Vx=Ap*Sx;
Ex=1+((Vx)/(Vc));
p1=0.093*((Ex)^n1);
p=0.093*((((u-180)*18)/180)^1.37);
end
if u>360&&u<375
p=10.866;
end
if u>375&&u<540
n2=1.27;
B=asind(Q*(sind(u)));
Sx=(r*(1-cosd(u)))+(L*(1-cosd (B)));
Vx=Ap*Sx;
Ex=1+((Vx)/(Vc));
p=10.866/((Ex)^n2);
end
if u>540&&u<720
p=0.105;
end
m=[m,u];
n=[n,p];
end
plot(m,n)
grid on
title('Gas pressure inside the cylender')
xlabel('angle of crank shaft')
ylabel('gas pressure')
Engine Torque of one cylinder

m=[];
n=[];
o=[];
u=[];
a=0.868;
b=0.032;
c=272^2;
w=a*b*c;
h=0.23;
z=-53000;
area=108.68;
for i=0:720;
if i>0&&i<180;
p=0.093;
p1=w*(cos(i*pi/180)+h*cos(2*i*pi/180));
B=asin(h*sin(i*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((i*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>180&&i<360
p=0.093*((((1+540)*18)/180)^1.37);
p1=w*(cos(i*pi/180)+h*cos(2*i*pi/180));
B=asin(h*sin(i*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((i*pi/180)+B);
f=p1/cos(B);
fT2=1*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>360&&i<375;
p=9.75;
p1=w*(cos(i*pi/180)+h*cos(2*i*pi/180));
B=asin(h*sin(i*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((i*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>375&&i<540;
p=9.75*((((i-360)*13.85)/180)^1.27);
p1=w*(cos(i*pi/180)+h*cos(2*1*pi/180));
B=asin(h*sin(i*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((i*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>540&&i<720;
p=0.105;
p1=w*(cos(i*pi/180)+h*cos(2*i*pi/180));
B=asin(h*sin(i*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((i*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
m=[m,i];
n=[n,M];
end
plot(m,n,'b')
grid on
title('Engine Torque of one cylinder')
xlabel('Angle of crank shaft')
ylabel('Engine Torque')
'Gas pressure Torque of two cylinder
m=[];
n=[];
o=[];
u=[];
r=[];
A=[];
H=[];
X=[];
a=0.868;
b=0.032;
c=272^2;
w=a*b*c;
h=0.23;
z=-53000;
area=108.68;
for E=0:720;
if E>0&&E<180;
p=0.2619;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>180&&E<360
p=0.2619*((((E+180)*16)/180)^1.366);
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>360&&E<375;
p=8;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>375&&E<540;
p=13.07*((((E-360)*10.81)/180)^1.27);
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>540&&E<720;
p=0.3422;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
o=[o;E];
u=[u;(fT1*b)];
end
for i=0:720;
if i>360&&i<540;
p=0.2619;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>540&&i<720
p=0.2619*(((((i+360)-540)*16)/180)^1.366);
pl=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>0&&i<15;
p=8;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>15&&i<180;
p=13.07*(((((i+360)-360)*10.81)/180)^1.27);
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>180&&i<360;
p=0.3422;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
FT2=f*sin((i*pi/180)+8);
total=fT1+fT2;
M=total*b;
end
m=[m;i];
n=[n;(fT1*b)];
end
H=[H;i];
X=[X;(fT1*b)];
plot(o,u,r,A,m,n,H,X);
grid on;
title('Gas pressure Torque of two cylinder')
xlabel('Angle of crank shaft')
ylabel('Torque')
legend('Cy(1)','Cy(2)')
'Engine Torque of four cylinder
m=[];
n=[];
o=[];
u=[];
r=[];
A=[];
H=[];
X=[];
a=0.868;
b=0.032;
c=272^2;
w=a*b*c;
h=0.23;
z=-53000;
area=108.68;
for E=0:720;
if E>0&&E<180;
p=0.2619;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>180&&E<360
p=0.2619*((((E+180)*16)/180)^1.366);
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>360&&E<375;
p=8;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>375&&E<540;
p=13.07*((((E-360)*10.81)/180)^1.27);
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if E>540&&E<720;
p=0.3422;
p1=w*(cos(E*pi/180)+h*cos(2*E*pi/180));
B=asin(h*sin(E*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin((E*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((E*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
o=[o,E];
u=[u,M];
end
for V=0:720;
if V>180&&V<360;
p=0.2619;
pl=w*(cos((V+180)*pi/180)+h*cos(2*(V+180)*pi/180));
B=asin(h*sin((V+180)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((V+180)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((V+180)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if V>360&&V<540
p=0.2619*(((((V+180)-180)*16)/180)^1.366);
p1=w*(cos((V+180)*pi/180)+h*cos(2*(V+180)*pi/180));
B=asin(h*sin((V+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((V+180)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((V+180)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if V>540&&V<555;
p=8;
p1=w*(cos((V+180)*pi/180)+h*cos(2*(V+180)*pi/180));
B=asin(h*sin((V+180)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((V+180)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((V+180)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if V>555&&V<720;
p=13.07*(((((V+180)-720)*10.81)/180)^1.27);
p1=w*(cos((V+180)*pi/180)+h*cos(2*(V+180)*pi/180));
B=asin(h*sin((V+180)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((V+180)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((V+180)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if V>0&&V<180;
p=0.3422;
p1=w*(cos((V+180)*pi/180)+h*cos(2*(V+180)*pi/180));
B=asin(h*sin((V+180)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((V+180)*pi/180)+B);
f=p1/cos(B);
fT2=1*sin(((V+180)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
r=[r,V];
A=[A,M];
end
for i=0:720;
if i>360&&i<540;
p=0.2619;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>540&&i<720
p=0.2619*(((((i+360)-540)*16)/180)^1.366);
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>0&&i<15;
p=8;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>15&&i<180;
p=13.07*(((((i+360)-360)*10.81)/180)^1.27);
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((i+360)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if i>180&&i<360;
p=0.3422;
p1=w*(cos((i+360)*pi/180)+h*cos(2*(i+360)*pi/180));
B=asin(h*sin((i+360)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((i+360)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin((i*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
m=[m,i];
n=[n,M];
end
for l=0:720;
if l>540&&l<720;
p=0.2619;
p1=w*(cos((l+540)*pi/180)+h*cos(2*(l+540)*pi/180));
B=asin(h*sin((l+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((l+540)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((l+540)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if l>0&&l<180
p=0.2619*(((((l+540)-180)*16)/180)^1.366);
p1=w*(cos((l+540)*pi/180)+h*cos(2*(l+540)*pi/180));
B=asin(h*sin((l+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((l+540)*pi/180)+B);
f=pl/cos(B);
fT2=f*sin(((l+540)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if l>180&&l<195;
p=8;
p1=w*(cos((l+540)*pi/180)+h*cos(2*(l+540)*pi/180));
B=asin(h*sin((l+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((l+540)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((l+540)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if l>195&&l<360;
p=13.07*(((((l+540)-720)*10.81)/180)^1.27);
pl=w*(cos((l+540)*pi/180)+h*cos(2*(l+540)*pi/180));
B=asin(h*sin((l+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((l+540)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((l+540)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
if l>360&&l<540;
p=0.3422;
pl=w*(cos((l+540)*pi/180)+h*cos(2*(l+540)*pi/180));
B=asin(h*sin((l+540)*pi/180));
pg=p*area;
F=pg/cos(B);
fT1=F*sin(((l+540)*pi/180)+B);
f=p1/cos(B);
fT2=f*sin(((l+540)*pi/180)+B);
total=fT1+fT2;
M=total*b;
end
H=[H,l];
X=[X,M];
end
plot(o,u,r,A,m,n,H,X)
grid on;
title('Engine Torque of four cylinder')
xlabel('Angle of crank shaft')
ylabel('Torque')
legend('Cy(1)','Cy(2)','Cy(3)','Cy(4)')
'FREE VIBRATION RESPONSE FOR FOUR CYLENDER'
I=[100 0 0 0 0;0 150 0 0 0;0 0 100 0 0;0 0 0 150 0;0 0 0 0 100];
k=[200 -200 0 0 0;-100 600 -400 0 0;0 -400 700 -300 0;0 0 -300 800 -500;0 0
0 -500 500];
N=5;
R=chol(I);
L=R';
A=inv(L)*k*inv(L');
[x,W]=eig(A);
v=inv(L')*x;
for i=1:N;
w1(i)=sqrt(W(i,i));
end
[w,z]=sort(w1);
disp('The first five natural frequencies are')
disp(w(1))
disp(w(2))
disp(w(3))
disp(w(4))
disp(w(5))
n=[1:N];
disp('The corresponding inertia-orthonormalized modes shapes are')
for j=1:N;
U(:,j)=v(:,z(j));
U(:,j)=U(:,j)/(U(:,j)'*I*U(:,j));
disp('mode-')
disp(j)
disp(U(:,j))
end
t=1:100;
w(1)
x=U(:,j)*sin(w(1)*t);
plot(t,x)
grid on
title('FREE VIBRATION RESPONSE FOR FOUR CYLENDER')
xlabel('time(seconds)')
ylabel('Response(rad)')
'FREE RESPONSE'

clear
clc
I1=2.7225*10^-4;%mass
I2=I1;
I3=1.80352*10^-4;
K1=26015.76;
K2=15485.57;
M=[I1 0 0;0 I2 0;0 0 I3]; % mass matrix
K=[K1 -K1 0;-K1 K1+K2 -K2;0 -K2 K2];%stiffiness matrix
[u,W]=eig(K,M); %eigenvalue problem
%W=eigenvalues
u(:,1)=u(:,1)/max(u(:,1)); %normalization
u(:,2)=u(:,2)/max(u(:,2));
u(:,3)=u(:,3)/max(u(:,3));
[w(1),I1]=min(max(W));
[w(2),I2]=max(max(W));
[w(3),I3]=min(max(W));
w(1)=sqrt(w(1)); %lowest natural frequency
w(2)=sqrt(w(2)); %highest natural frequency
w(3)=sqrt(w(3));
U(:,1)=u(:,I1); %relabelling of the eigenvectors
U(:,2)=u(:,I2);
U(:,3)=u(:,I3);
X=u(:,I1);
Y=u(:,I2);
Z=u(:,I3);
t=0:0.5:20;
X1=X*exp(i*w(1)*t);
Y1=Y*exp(i*w(2)*t);
Z1=Z*exp(i*w(3)*t);
plot(t,X1,t,Y1,t,Z1),grid on
title('FREE RESPONSE');
legend('X1','Y1', 'Z1');
xlabel('t(seconds)')
ylabel('(response(rad)')
'Otto Cycle on T-P Diagram'
gamma = 1.4; % Ratio of specific heats (Cp/Cv) for air
T1 = 300; % Initial temperature in Kelvin (start of compression)
P1 = 101325; % Initial pressure in Pa (start of compression)
r = 10; % Compression ratio (V1/V2)

% Calculate the temperatures and pressures at key points


T2 = T1 * (1 + (gamma - 1) / 2 * (r - 1)); % End of compression (adiabatic)
P2 = P1 * (T2 / T1)^(gamma / (gamma - 1)); % End of compression

T3 = T2 * (1 + (gamma - 1) / 2); % End of combustion (isochoric)


P3 = P2 * (T3 / T2); % End of combustion
T4 = T3 / (1 + (gamma - 1) / 2); % End of expansion (adiabatic)
P4 = P3 * (T4 / T3)^(gamma / (gamma - 1)); % End of expansion
% Efficiency calculation
efficiency = 1 - 1 / r^(gamma - 1);
% Display results disp('Thermodynamic Cycle Calculations:');
disp(['Temperature at state 1 (T1): ', num2str(T1), ' K']);
disp(['Pressure at state 1 (P1): ', num2str(P1), ' Pa']);
disp(['Temperature at state 2 (T2): ', num2str(T2), ' K']);
disp(['Pressure at state 2 (P2): ', num2str(P2), ' Pa']);
disp(['Temperature at state 3 (T3): ', num2str(T3), ' K']);
disp(['Pressure at state 3 (P3): ', num2str(P3), ' Pa']);
disp(['Temperature at state 4 (T4): ', num2str(T4), ' K']);
disp(['Pressure at state 4 (P4): ', num2str(P4), ' Pa']);
disp(['Thermal Efficiency (?): ', num2str(efficiency)]);
hold on;
plot([T1, T2, T3, T4, T1], [P1, P2, P3, P4, P1], 'o-');
title('Otto Cycle on T-P Diagram');
xlabel('Temperature (K)');
ylabel('Pressure (Pa)');
grid on;
hold off;
P V diagram

clear all
close all
clc

%The ratio of speci?c heats 'gamma' value is assumed to be 1.4


gamma = 1.4;

%Input state variables: P1(pascals), T1 and T2(kelvins)


p1 = 101325;
t1 = 500;
t3 = 2300;

%Sample input engine geometric parameters


bore = 0.1;
stroke = 0.1;
cr = 12;
con_rod = 0.15;

%Calculating the state variables in State 1


swept_volume = pi/4*(bore*stroke);
clearance_volume = swept_volume/(cr-1);
v1 = swept_volume + clearance_volume;
v2 = clearance_volume;

%Calculating the state variables in State 2

%Extracting P2 from isentropic compression process expressed as P1V1^gamma


= P2V2^gamma
p2 = p1*cr^gamma;

%Extracting T2 from the ideal gas law that is expressed as PV/T = constant.
t2 = (p2*v2*t1)/(p1*v1);

%Calculating the state variables in State 3:


%At the end of constant volume compression, we have the following relation
v3 = v2;

%Extracting P3 from the ideal gas law that is expressed as PV/T = constant.
p3 = p2*(t3/t2);

%Calculating the state variables at State 4

%At the end of constant volume expansion, we have the following relation
v4 = v1;

%Extracting P4 from the isentropic expansion process expressed as


P3V3^gamma = P4V4^gamma
p4 = p3*(v3/v4)^gamma;

%Calling the engine kinematics function to get the points to plot at


compression

V_compression = engine_kinematics(bore,stroke,con_rod,12,180,0);
constant1 = p1*v1^gamma;
P_compression = constant1./V_compression.^gamma;

%Calling the engine kinematics function to get the points to plot at


expansion
V_expansion = engine_kinematics(bore,stroke,con_rod,12,0,180);
constant2 = p3*v3^gamma;
P_expansion = constant2./V_expansion.^gamma;

%Following set of commands are used to plot the PV diagram for an ideal
Otto cycle
figure(1)

hold on
plot(v1,p1,'*','color','r');
plot(V_compression,P_compression);
plot(v2,p2,'*','color','r');
plot(v3,p3,'*','color','r');
plot(V_expansion,P_expansion);
plot(v4,p4,'*','color','r');
plot([v2 v3],[p2 p3]);
plot([v1 v4],[p1 p4]);
xlabel('Volume(m^3)')
ylabel('Pressure(N/m^2)')
grid on;

%The percentage of Thermal Efficiency is calculated as follows


thermal_efficiency = (1 - 1/(cr^(gamma - 1)))*100;

You might also like