Documentos de Académico
Documentos de Profesional
Documentos de Cultura
MATEMTICAS AVANZADAS
EXAMEN PARCIAL 2
ELABOR:
196656-6
PROFESOR:
DR. ANTONIO FLORES
Universidad Iberoamericana
Matemticas Avanzadas
Armando Beltrn Snchez
Partial Exam 2
Two chemical compounds named x1 and x4 are initially mixed and charged to a batch
reactor where previously an initial amount of reactant x2 has also been charged. A set of
isothermal chemical reactions take a place, where y stands for the valuable compound and
x3 , x5 are intermediate reaction compounds. The dynamic mathematical model which
describes the time behaviour of the reaction system is given by the following system od
DAEs:
Carry out the numerical integration of the above DAE system for the first 200 minutes using:
PART 1: The MATLAB DAE numerical integration facilities
PART 2: The orthogonal collocation on finite elements method
2.1.
PARTE 1 CDIGO MATLAB: The MATLAB DAE numerical integration
facilities
function dae4
clear , clc, format short g , format compact
mass_matrix = [1 0 0 0 0 0; 0 1 0 0 0 0 ; 0 0 1 0 0 0; 0 0 0 1 0 0 ; 0 0
0 0 1 0; 0 0 0 0 0 0];
x0
= [0.444; 0.00123 ; 0 ; 0.007; 0 ; 0.36];%initial conditions
time
= linspace(0,200,30);
options
= odeset('Mass',mass_matrix);
=
=
=
=
=
=
x(:,1);
x(:,2);
x(:,3);
x(:,4);
x(:,5);
x(:,6);
%Individual plots
figure(1)
subplot(2,3,1)
plot(t,x1,'r-','LineWidth',2)
legend ('x_1',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,2)
plot(t,x2,'b.-','LineWidth',2)
legend ('x_2',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,3)
plot(t,x3,'m.-','LineWidth',2)
legend ('x_3',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,4)
plot(t,x4,'y.-','LineWidth',2)
legend ('x_4',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,5)
plot(t,x5,'k.-','LineWidth',2)
legend ('x_5',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,6)
plot(t,y,'co-','LineWidth',2, 'markeredgecolor','b')
legend ('y',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
%plot 2
figure(2)
plot(t,x1,'r-','LineWidth',2), hold
plot(t,x2,'b.-','LineWidth',2)
plot(t,x3,'m.-','LineWidth',2)
plot(t,x4,'y.-','LineWidth',2)
plot(t,x5,'k.-','LineWidth',2)
plot(t,y,'co-','LineWidth',2, 'markeredgecolor','b')
legend ('x_1','x_2', 'x_3', 'x_4', 'x_5','y',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
=
=
=
=
=
=
x(1);
x(2);
x(3);
x(4);
x(5);
x(6);
%Reaction parameters
k1 = 18.7;
k2 = 0.58;
k3 = 0.09;
k4 = 0.42;
Initial
%x1
%x2
%x3
%x4
conditions
= 0.444;
= 0.00123;
= 0;
= 0.007;
K = 34.4;
KLA = 3.3;
Ks = 115.83;
pco2 = 0.9;
H = 737;
%x5 = 0;
%y = 0.36;
FIGURA (1)
FIGURA (2)
2.1.
PARTE 1 CDIGO MATLAB: The orthogonal collocation on finite elements
method
%PART 2
%The orthogonal collocation on finite elements method
clear all; clc; format short g; format compact;
global nfe npc a l x1_initial x2_initial x3_initial x4_initial...
x5_initial y_initial h
nfe =17;
% Number of finite elements
npc =3;
% Number of internal collocation pints
timep=200;
a = [0.19681547722366
-0.06553542585020
0.02377097434822
roots(1) =
roots(2) =
roots(3) =
0.39442431473909
0.29207341166523
-0.04154875212600
0.37640306270047;
0.51248582618842;
0.11111111111111];
0.15505102572168;
0.64494897427832;
1;
l = nfe*npc;
for i = 1:nfe
h(i) = timep/nfe;
end
%size step
%initial conditions
x1_initial = 0.444;
x2_initial = 0.00123;
x3_initial = 0;
x4_initial = 0.007;
x5_initial = 0;
y_initial = 0.36;
for i = 1:l
x1_vector(i) = x1_initial;
x2_vector(i) = x2_initial;
x3_vector(i) = x3_initial;
x4_vector(i) = x4_initial;
x5_vector(i) = x5_initial;
y_vector(i) = y_initial;
end
x_initial = [x1_vector'; x2_vector'; x3_vector';x4_vector';x5_vector';
y_vector'];
hsize= timep/nfe;
index= 0;
for i = 1:nfe
for j =1:npc
index= index+1;
time(index)=(i-1)*hsize+hsize*roots(j);
end
end
options= optimset('display','iter', 'Algorithm','Levenberg-Marquardt');
[x, fval, exitflag] = fsolve('function_partial_2_2', x_initial,
options);
x1= x(1:l);
x2= x(l+1:2*l);
x3= x(2*l+1:3*l);
x4= x(3*l+1:4*l);
x5= x(4*l+1:5*l);
y = x(5*l+1:6*l);
time = time';
%Individual plots
figure(1)
subplot(2,3,1)
plot(time,x1,'r-','LineWidth',2)
legend ('x_1',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,2)
plot(time,x2,'b.-','LineWidth',2)
legend ('x_2',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,3)
plot(time,x3,'m.-','LineWidth',2)
legend ('x_3',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,4)
plot(time,x4,'y.-','LineWidth',2)
legend ('x_4',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,5)
plot(time,x5,'k.-','LineWidth',2)
legend ('x_5',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
figure(1)
subplot(2,3,6)
plot(time,y,'co-','LineWidth',2, 'markeredgecolor','b')
legend ('y',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
%plot 2
figure(2)
plot(time,x1,'r-','LineWidth',2),hold
plot(time,x2,'b.-','LineWidth',2)
plot(time,x3,'m.-','LineWidth',2)
plot(time,x4,'y.-','LineWidth',2)
plot(time,x5,'k.-','LineWidth',2)
plot(time,y,'co-','LineWidth',2, 'markeredgecolor','b')
legend ('x_1','x_2', 'x_3', 'x_4', 'x_5','y',0)
xlabel('Time'), ylabel('Concentration'), title('Time Vs Concentration')
%---End partial_exam_2_part_2_2_ABS
2.1.
index=index+1;
x4(i,j)=x_initial(index);
end
end
index=4*l;
for i= 1:nfe
for j=1:npc
index=index+1;
x5(i,j)=x_initial(index);
end
end
index=5*l;
for i= 1:nfe
for j=1:npc
index=index+1;
y(i,j)=x_initial(index);
end
end
%Derivatives of the math model
for i= 1:nfe
for j = 1:npc
dx1(i,j)=(-2*k1)*(x1(i,j)^4)*(x2(i,j)^0.5) + (k2*x3(i,j)*x4(i,j))((k2/K)*x1(i,j)*x5(i,j))-(k3*x1(i,j)*(x4(i,j)^2));
dx2(i,j)=(-1/2)*k1*(x1(i,j)^4)*(x2(i,j)^0.5)-(k3*x1(i,j)*(x4(i,j)^2))
-(1/2)*k4*(y(i,j)^2)*(x2(i,j)^0.5)+(KLA*((pco2/H)-x2(i,j)));
dx3(i,j)=k1*(x1(i,j)^4)*(x2(i,j)^0.5) (k2*x3(i,j)*x4(i,j))+((k2/K)*x1(i,j)*x5(i,j));
dx4(i,j)=(-k2*x3(i,j)*x4(i,j))+((k2/K)*x1(i,j)*x5(i,j))(2*k3*x1(i,j)*(x4(i,j)^2));
dx5(i,j)=(k2*x3(i,j)*x4(i,j))((k2/K)*x1(i,j)*x5(i,j))+(k4*(y(i,j)^2)*(x2(i,j)^0.5));
end
end
%Continuity equations
x1_c(1)=x1_initial;
x2_c(1)=x2_initial;
x3_c(1)=x3_initial;
x4_c(1)=x4_initial;
x5_c(1)=x5_initial;
for i=2:nfe
sum1 = 0; sum2= 0; sum3 = 0; sum4= 0; sum5 = 0;
for k = 1:npc
sum1 = sum1+ a(k,npc)*dx1(i-1,k);
sum2 = sum2+ a(k,npc)*dx2(i-1,k);
sum3 = sum3+ a(k,npc)*dx3(i-1,k);
sum4 = sum4+ a(k,npc)*dx4(i-1,k);
sum5 = sum5+ a(k,npc)*dx5(i-1,k);
end
x1_c(i)=x1_c(i-1)+h(i-1)*sum1;
x2_c(i)=x2_c(i-1)+h(i-1)*sum2;
x3_c(i)=x3_c(i-1)+h(i-1)*sum3;
x4_c(i)=x4_c(i-1)+h(i-1)*sum4;
x5_c(i)=x5_c(i-1)+h(i-1)*sum5;
end
%Equations Model from NLE System
for i = 1:nfe
for j =1:npc
sumx1d = 0; sumx2d= 0; sumx3d = 0; sumx4d= 0; sumx5d = 0;
for k = 1:npc
sumx1d = sumx1d + a(k,j)*dx1(i,k) ;
sumx2d = sumx2d + a(k,j)*dx2(i,k) ;
sumx3d = sumx3d + a(k,j)*dx3(i,k) ;
sumx4d = sumx4d + a(k,j)*dx4(i,k) ;
sumx5d = sumx5d + a(k,j)*dx5(i,k) ;
end
fx1(i,j)= x1(i,j)-x1_c(i)-h(i)*sumx1d;
fx2(i,j)= x2(i,j)-x2_c(i)-h(i)*sumx2d;
fx3(i,j)= x3(i,j)-x3_c(i)-h(i)*sumx3d;
fx4(i,j)= x4(i,j)-x4_c(i)-h(i)*sumx4d;
fx5(i,j)= x5(i,j)-x5_c(i)-h(i)*sumx5d;
fy(i,j)= (Ks*x1(i,j)*x4(i,j))-y(i,j);
end
end
%Vector solution generation
index=0;
for i= 1:nfe
for j=1:npc
index=index+1;
fx1_vect(index)=fx1(i,j);
fx2_vect(index)=fx2(i,j);
fx3_vect(index)=fx3(i,j);
fx4_vect(index)=fx4(i,j);
fx5_vect(index)=fx5(i,j);
fy_vect(index)=fy(i,j);
end
end
fx= [fx1_vect'; fx2_vect'; fx3_vect';fx4_vect'; fx5_vect'; fy_vect'];
end
FIGURA (1)
FIGURA (2)