% TÓM TẮT SỐLIỆU
S = 0.9893; % S/D=1, don vi dm
D = 0.9026;
R = S/2; %dm
lambda = 2/7; %thong so ket cau
% rho = 1.396;
Fp = (pi*(D^2))/4;
Va = 0.682; %Don vi the tich: lit
Vc = 0.049;
Vz = 0.068404; %Vc.*rho, rho=1.406;
Vb = Va;
Vr = Vc;
n1 = 1.3659; %Chi so nen da bien trung binh
n2 = 1.317; %Chi so dan no da bien trung binh
P0 = 0.1013; %Don vi ap suat: MN/m^2
Pa = 0.1672;
Pc = 6.148;
Pz = 10.452;
Pb = 0.502;
Pr = 0.113;
n = 4500; %vong/phut
w = (pi*n)/30; %rad/s
mnp = 10; %don vi g/cm2
mtt = 20;
mk = 20;
mA = 0.3 * mtt;
mB = 0.7 * mtt;
mj = mA + mnp;
mr = mB + mk;
%% ve do thi cong chi thi
% hieu chinh rr'
a1hc = linspace (0,9,100); % dong muon xupap thai = 9
x1hc = R.*((1-cosd(a1hc))+(lambda/4).*(1-cosd(2.*a1hc)));
J1hc = R*(w^2).*(cosd(a1hc)+lambda.*cosd(2.*a1hc));
Vt1hc = R*w*(sind(a1hc) + (lambda/2).*sind(2*a1hc));
V1hc = x1hc*Fp + Vc;
Vr1 = max (V1hc);
Prr1 = linspace (Pr,Pa,100); % khoang ap suat trong doan hieu chinh
Vrr1 = linspace (Vc,Vr1,100); % khoang the tich trong doan hieu chinh
P1hc = interp1 (Vrr1,Prr1,V1hc,'spline');
% qua trinh nap
a1 = linspace (9,180,100);
x1 = R.*((1-cosd(a1))+(lambda/4).*(1-cosd(2.*a1)));
J1 = R*(w^2).*(cosd(a1)+lambda.*cosd(2.*a1));
Vt1 = R*w*(sind(a1) + (lambda/2).*sind(2*a1));
Fp = (pi*(D^2))/4;
V1 = x1*Fp + Vc;
P1 = linspace (Pa,Pa,100);
% qua trinh nen (goc danh lua som = 10)
% doan 1
a2 = linspace (180,350,100);
x2 = R.*((1-cosd(a2))+(lambda/4).*(1-cosd(2.*a2)));
J2 = R*(w^2).*(cosd(a2)+lambda.*cosd(2.*a2));
Vt2 = R*w*(sind(a2) + (lambda/2).*sind(2*a2));
V2 = x2*Fp + Vc;
P2 = Pa.*(Va./V2).^n1;
% qua trinh chay - gian no
% hieu chinh doan c'-c"
a2hc = linspace (350,360,100);
x2hc = R.*((1-cosd(a2hc))+(lambda/4).*(1-cosd(2.*a2hc)));
J2hc = R*(w^2).*(cosd(a2hc)+lambda.*cosd(2.*a2hc));
Vt2hc = R*w*(sind(a2hc) + (lambda/2).*sind(2*a2hc));
V2hc = x2hc*Fp + Vc;
Pchc = Pa.*(Va./V2hc).^n1;
% xac dinh toa do diem c'
Vc1 = max (V2hc);
Pc1 = min (Pchc);
% xac dinh toa do diem c"
Pz1 = Pz; % z1 la diem z'
Pcz1 = Pz1 - Pc; %cz'
Pc2 = Pcz1/3 + Pc; %pc''
Vc2 = Vc; %Vc''
% ve doan c'-c"
Vc1c2 = linspace (Vc1,Vc2,100);
Pc1c2 = linspace (Pc1,Pc2,100);
P2hc = interp1(Vc1c2,Pc1c2,V2hc,'spline');
% hieu chinh c"-z"
a3hc = linspace(360,370,100);
x3hc = R.*((1-cosd(a3hc))+(lambda/4).*(1-cosd(2.*a3hc)));
J3hc = R*(w^2).*(cosd(a3hc)+lambda.*cosd(2.*a3hc));
Vt3hc = R*w*(sind(a3hc) + (lambda/2).*sind(2*a3hc));
VZ = x3hc*Fp + Vc;
PZ= Pz.*(Vz./VZ).^n2;
% xac dinh diem z"
Vz2 = max (VZ);
Pz2 = min (PZ);
% xac dih diem zhc
azhc = 369;
xzhc = R.*((1-cosd(azhc))+(lambda/4).*(1-cosd(2.*azhc)));
Jzhc = R*(w^2).*(cosd(azhc)+lambda.*cosd(2.*azhc));
Vtzhc = R*w*(sind(azhc) + (lambda/2).*sind(2*azhc));
Vzhc = xzhc*Fp + Vc;
Pzhc = Pz.*( Vz./Vzhc).^n2;
% ve doan c"-z"
Vz1z2 = [Vc2,Vzhc,Vz2];
Pz1z2 = [Pc2,Pzhc,Pz2];
V3hc = linspace(Vc2,Vz2,100);
P3hc = interp1(Vz1z2,Pz1z2,V3hc,'spline');
% gian no
a3 = linspace (370,479,100);
x3 = R.*((1-cosd(a3)+(lambda/4).*(1-cosd(2.*a3))));
J3 = R*(w^2).*(cosd(a3)+lambda.*cosd(2.*a3));
Vt3 = R*w*(sind(a3) + (lambda/2).*sind(2*a3));
V3 = x3*Fp + Vc;
P3 = Pz.*(Vz./V3).^n2;
% qua trinh thai
% hieu chinh b'b"
a4hc = linspace (479,540,100); %mo som xupap thai = 61
x4hc = R.*((1-cosd(a4hc))+(lambda/4).*(1-cosd(2.*a4hc)));
J4hc = R*(w^2).*(cosd(a4hc)+lambda.*cosd(2.*a4hc));
Vt4hc = R*w*(sind(a4hc) + (lambda/2).*sind(2*a4hc));
V1b = x4hc*Fp + Vc;
P1b = Pz.*(Vz./V1b).^n2;
% xac dinh diem b'
Vb1 = min (V1b);
Pb1 = max (P1b);
% xac dinh diem b"
Pb2 = ((Pb-Pr)/2)+Pr;
Vb2 = Va;
% xac dinh bhc1
abhc1 = 478.9;
xbhc1=R.*((1-cosd(abhc1))+(lambda/4).*(1-cosd(2.*abhc1)));
Jbhc1 = R*(w^2).*(cosd(abhc1)+lambda.*cosd(2.*abhc1));
Vtbhc1 = R*w*(sind(abhc1) + (lambda/2).*sind(2*abhc1));
Vbhc1 = xbhc1*Fp + Vc;
Pbhc1 = Pz.*(Vz./Vbhc1).^n2;
% ve doan b'b"
Vb1b2 = [Vb1,Vbhc1,Vb2];
Pb1b2 = [Pb1,Pbhc1,Pb2];
V4hc = linspace(Vb1,Va,100);
P4hc = interp1(Vb1b2,Pb1b2,V4hc,'spline');
% hieu chinh b"
a5hc = linspace(540,564,100);
x5hc = R.*((1-cosd(a5hc))+(lambda/4).*(1-cosd(2.*a5hc)));
J5hc = R*(w^2).*(cosd(a5hc)+lambda.*cosd(2.*a5hc));
Vt5hc = R*w*(sind(a5hc) + (lambda/2).*sind(2*a5hc));
V2b = x5hc*Fp + Vc;
%xac dinh diem b'''
Pb3 = Pr;
Vb3 = min(V2b);
%xac dinh diem bhc2
abhc2 = 552;
xbhc2=R.*((1-cosd(abhc2))+(lambda/4).*(1-cosd(2.*abhc2)));
Jbhc2 = R*(w^2).*(cosd(abhc2)+lambda.*cosd(2.*abhc2));
Vtbhc2 = R*w*(sind(abhc2) + (lambda/2).*sind(2*abhc2));
Vbhc2 = xbhc2*Fp + Vc;
Pbhc2 = 0.235;
% ve doan cong sau b"
Vb2b4 = [Vb2,Vbhc2,Vb3];
Pb2b4 = [Pb2,Pbhc2,Pb3];
V5hc = linspace(Vb2,Vb3,100);
P5hc = interp1(Vb2b4,Pb2b4,V5hc,'spline');
% doan cuoi
a4 = linspace (564,720,100);
x4 = R.*((1-cosd(a4))+(lambda/4).*(1-cosd(2.*a4)));
J4 = R*(w^2).*(cosd(a4)+lambda.*cosd(2.*a4));
Vt4 = R*w*(sind(a4) + (lambda/2).*sind(2*a4));
V4 = x4*Fp + Vc;
P4 = linspace (Pr,Pr,100);
% do thi cong P-V
xtong = [x1hc,x1,x2,x2hc,x3hc,x3,x4hc,x5hc,x4];
vttong = [Vt1hc,Vt1,Vt2,Vt2hc,Vt3hc,Vt3,Vt4hc,Vt5hc,Vt4];
atong = [a1hc,a1,a2,a2hc,a3hc,a3,a4hc,a5hc,a4];
jtong = [J1hc,J1,J2,J2hc,J3hc,J3,J4hc,J5hc,J4];
Vtong = [V1hc,V1,V2,V2hc,VZ,V3,V1b,V2b,V4];
Ptong = [P1hc,P1,P2,P2hc,P3hc,P3,P4hc,P5hc,P4];
% ve do thi P-V
figure(1);
plot (V1hc,P1hc,'k','linewidth',2);
hold on;
plot (V1,P1,'k','linewidth',2);
hold on;
plot (V2,P2,'r','linewidth',2);
hold on;
plot (V2hc,P2hc,'y','linewidth',2);%cc'
hold on;
plot (VZ,P3hc,'r','linewidth',2);
hold on;
plot (V3,P3,'g','linewidth',2);%xb'
hold on;
plot (V1b,P4hc,'b','linewidth',2);
hold on;
plot (V2b,P5hc,'b','linewidth',2);
hold on;
plot (V4,P4,'m','linewidth',2);
hold on;
title('DO THI CONG CHI THI P-V');
xlabel('The tich V (lit)');
ylabel('Ap suat P (MN/m2)');
grid on;
% Đồthị P-phi
figure(2);
plot(atong,Ptong,'b','linewidth',1.5);
title('ĐỒTHỊ CÔNG TRIỂ N KHAI P-PHI');
xlabel('Góc quay trục khuỷu alpha (độ)');
ylabel('Áp suất (MN/m2)');
grid on;
%chuyển vị
figure(3);
a0 = [a1hc,a1,a2,a2hc];
x0 = [x1hc,x1,x2,x2hc];
v0 = [Vt1hc,Vt1,Vt2,Vt2hc];
j0 = [J1hc,J1,J2,J2hc];
plot(a0,x0,'k','linewidth',1.5);
title('ĐỒTHỊ CHUYỂ N VỊ X');
xlabel('Góc quay trục khuỷu alpha (độ)');
ylabel('Chuyển vị (dm)');
grid on;
%đồthị vận tố c
figure(4);
plot(a0,v0,'r','linewidth',1.5);
title('ĐỒTHỊ VẬN TỐ C V');
xlabel('Góc quay trục khuỷu alpha (độ)');
ylabel('Vận tốc (m/s)');
grid on;
%gia tốc
figure(5);
plot(a0,j0,'r','linewidth',1.5);
title('ĐỒTHỊ GIA TỐ C J');
xlabel('Góc quay trục khuỷu alpha (độ)');
ylabel('Gia tốc (m/s2)');
grid on;