具有边值的二阶耦合微分方程问题:催化转化器

时间:2020-05-24 21:27:45

标签: python-3.x matlab

三个耦合的微分方程:

y1'' + 2y1'/r = k1 * y1y3/(1 + K1y1 + K2y2)^2
y2'' + 2y2'/r = k2 * y2y3/(1 + K1y1 + K2y2)^2
y3'' + 2y3'/r = (k1 * y1y3 - k2 * y2y3) /(1 + K1y1 + K2y2)^2

边界条件是: dydr = 0 dydr = cons(ci-yi) 我试图在MATLAB和Python中解决它 但是我在绘图时得到了错误的答案。 参考:示例7-2 James Blake Rawlings的化学反应器书...催化转化器

使用Python解决此问题,我使用了scipy的bvp求解器。

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_bvp


def fun(r, y):
    return np.vstack((y[1], -2/r*y[0]-(50e+10*y[0]*y[4]/pow(1+1.7037e+07*y[0]+1.8224e+08*y[2],2)),
                      y[3], -2/r*y[2]-3.5426e+10*y[2]*y[4]/pow(1+1.7037e+07*y[0]+1.8224e+08*y[2],2),
                      y[5], -2/r*y[4]-(3.1550e+09*y[0]*y[4]-1.7253e+09*y[2]*y[4])/0.0469*pow(1+1.7037e+07*y[0]+1.8224e+08*y[2],2)))


# ---Boundary Conditions---#
def bc(ya, yb):
    return np.array([ya[1], yb[1]-80.0821*(0.02-yb[0]),
                     ya[3], yb[3]-80.0821*(0.0005-yb[2]),
                     ya[5], yb[5]-86.7804*(0.03*yb[4])])


eps=1e-30
r = np.linspace(eps, 0.175, 1000)
y_a = np.zeros((6, r.size))
y_b = np.zeros((6, r.size))
y_c = np.zeros((6, r.size))
res_a = solve_bvp(fun, bc, r, y_a)
res_b = solve_bvp(fun, bc, r, y_b)
res_c = solve_bvp(fun, bc, r, y_c)
x_plot = np.linspace(0, 0.175, 100)
y_plot_a = res_a.sol(x_plot)[0]
y_plot_b = res_b.sol(x_plot)[2]
y_plot_c = res_c.sol(x_plot)[4]
fig, ax=plt.subplots(2)
ax[0].plot(x_plot, y_plot_a, '--r', label='O2')
ax[0].plot(x_plot, y_plot_b, '--b', label='CO')
ax[0].plot(x_plot, y_plot_c, ':g', label='C3H6')
ax[0].legend(loc='best')
ax[0].set_ylabel("C (mol/cm^3)")
ax[0].grid('True')
ax[1].loglog(x_plot, y_plot_a, '--r', label='O2')
ax[1].loglog(x_plot, y_plot_b, '--b', label='CO')
ax[1].loglog(x_plot, y_plot_c, ':g', label='C3H6')
ax[1].legend(loc='best')
plt.xlabel("r")
plt.ylabel("Log C")
fig.suptitle('Concentration of species in a catalytic converter')
plt.grid()
plt.show()
print(sol)

使用MATLAB

S=[ 0  0 0  0 0  0
    0 -2 0  0 0  0
    0  0 0  0 0  0
    0  0 0 -2 0  0
    0  0 0  0 0  0
    0  0 0  0 0 -2];
options=bvpset('SingularTerm',S);
xmesh = linspace(0,0.175,1000);

solinit = bvpinit(xmesh,[0.175 2 0.175 3 0 2]);
sol=bvp4c(@SphericalODE,@SphericalBC,solinit,options);
x=linspace(0,0.175);

y=deval(sol,x)';
C1=y(:,1)';
C2=y(:,3)';
C3=y(:,5)';

figure(1)
plot(x,C1,':',x,C2,':',x,C3,':')
title('Concetration of CO O2 C3H6')
xlabel('Sphere radius (cm)')
ylabel('C mol/cm^3')
legend('CO','C3H6','O2','Location','west')
function f=SphericalODE(~,y)
P = 1.013e+05;       %N/m^2
T = 550;             %K
R = 0.175;           %cm
% R_gas = 1.987;          %cm^3*atm/mol.K
E_1 = 13108;         %K
E_2 = 15109;         %K
E_CO = -409;         %K
E_C3H6 = 191;        %K
c_COf = 0.02;        
c_O2f = 0.03;
c_C3H6f = 0.0005;
%V=4/3*pi*(0.175/2)^3;
k_1_0 = 7.07*10^19;     %mol/(cm^3 * s)
k_1 = k_1_0*exp(-E_1/(T));
k_2_0 = 1.47*10^21;     %mol/(cm^3 * s)
k_2 = k_2_0*exp(-E_2/(T));
K_CO_0 = 8.099e6;    %cm^3/mol
K_CO = K_CO_0*exp(-E_CO/T);
K_C3H6_0 = 2.579e8;  %cm^3/mol
K_C3H6 = K_C3H6_0*exp(-E_C3H6/T);
D_CO = 0.0487;       %cm^2/s
D_O2 = 0.0469;       %cm^2/s
D_C3H6 = 0.0487;     %cm^2/s
k_mCO = 3.90;        %cm/s
k_mO2 = 4.07;        %cm/s
k_mC3H6 = 3.90;      %cm/s
    f= [y(2)
        (k_1*y(1)*y(5))/(D_CO*power(1+K_CO*y(1)+K_C3H6*y(3),2))
        y(4)
        (k_2*y(3)*y(5))/(D_C3H6*power(1+K_CO*y(1)+K_C3H6*y(3),2))
        y(6)
        (0.5*(k_1*y(1)*y(5))+4.5*(k_2*y(3)*y(5)))/(D_O2*power(1+K_CO*y(1)+K_C3H6*y(3),2))];
end


%%----Boundary Conditions----%%
function res=SphericalBC(ya,yb)
P = 1.013e+05;       %N/m^2
T = 550;             %K
R = 0.175;           %cm
% R_gas = 1.987;          %cm^3*atm/mol.K
E_1 = 13108;         %K
E_2 = 15109;         %K
E_CO = -409;         %K
E_C3H6 = 191;        %K
c_COf = 0.02;        
c_O2f = 0.03;
c_C3H6f = 0.0005;
%V=4/3*pi*(0.175/2)^3;
k_1_0 = 7.07*10^19;     %mol/(cm^3 * s)
k_1 = k_1_0*exp(-E_1/(T));
k_2_0 = 1.47*10^21;     %mol/(cm^3 * s)
k_2 = k_2_0*exp(-E_2/(T));
K_CO_0 = 8.099e6;    %cm^3/mol
K_CO = K_CO_0*exp(-E_CO/T);
K_C3H6_0 = 2.579e8;  %cm^3/mol
K_C3H6 = K_C3H6_0*exp(-E_C3H6/T);
D_CO = 0.0487;       %cm^2/s
D_O2 = 0.0469;       %cm^2/s
D_C3H6 = 0.0487;     %cm^2/s
k_mCO = 3.90;        %cm/s
k_mO2 = 4.07;        %cm/s
k_mC3H6 = 3.90;      %cm/s
    res=[ya(2)
         yb(2)-(k_mCO/D_CO)*(c_COf - yb(1))
         ya(4)
         yb(4)-(k_mC3H6/D_C3H6)*(c_C3H6f - yb(3))
         ya(6)
         yb(6)-(k_mO2/D_O2)*(c_O2f - yb(5))];
end

该示例的答案应如下所示,但是当我运行它时,我得到了不同的结果 enter image description here

0 个答案:

没有答案