How to solve system of non-linear differential equations for numerical values

12 次查看(过去 30 天)
I am trying to model the change in concentration of chemical species over an hour long period. This requires a system of differential equations (shown in the code below). I am not sure what function to use to complete this. I tried dsolve but it did not work. Any tips would be greatly appreciated.
syms t k1 k2 k3 k4 k5 k6 k7 k8 NO(t) NO2(t) C8H18(t) O2(t) OH(t) HO2(t) O(t) O3(t) C8H17(t) OC8H17(t) O2C8H17(t) C7H17CHO(t) H2O(t)
ode1 = diff(NO,t) == k1*NO2 - k3*O3*NO - k4*HO2*NO - k7*O2C8H17*NO;
ode2 = diff(NO2,t) == k3*O3*NO + k4*HO2*NO + k7*O2C8H17*NO - k1*NO2;
ode3 = diff(O,t) == k1*NO2 - k2*O2*O;
ode4 = diff(O3,t) == k2*O2*O - k3*O3*NO;
ode5 = diff(O2,t) == k3*O3*NO - k2*O2*O - k6*C8H17*O2 - k8*OC8H17*O2;
ode6 = diff(OH,t) == k4*HO2*NO - k5*C8H18*OH;
ode7 = diff(HO2,t) == k8*OC8H17*O2 - k4*HO2*NO;
ode8 = diff(C8H18,t) == -k5*C8H18*OH;
ode9 = diff(H2O,t) == k5*C8H18*OH;
ode10 = diff(C8H17,t) == k5*C8H18*OH - k6*C8H17*O2;
ode11 = diff(O2C8H17,t) == k6*C8H17*O2 - k7*O2C8H17*NO;
ode12 = diff(OC8H17,t) == k7*O2C8H17*NO - k8*OC8H17*O2;
ode13 = diff(C7H17CHO,t) == k8*OC8H17*O2;
odes = [ode1; ode2; ode3; ode4; ode5; ode6; ode7; ode8; ode9; ode10; ode11; ode12; ode13];
cond1 = NO(0) == 0.0675;
cond2 = NO2(0) == 0.0075;
cond3 = C8H18(0) == 0.15;
cond4 = O2(0) == 210000;
cond5 = OH(0) == 4.59E-08;
cond6 = HO2(0) == 4.07E-06;
cond7 = O(0) == 0;
cond8 = O3(0) == 0;
cond9 = C8H17(0) == 0;
cond10 = OC8H17(0) == 0;
cond11 = O2C8H17(0) == 0;
cond12 = C7H17CHO(0) == 0;
cond13 = H2O(0) == 0;
conds = [cond1; cond2; cond3; cond4; cond5; cond6; cond7; cond8; cond9; cond10; cond11; cond12; cond13];
k1=0.4;
k2=21.83;
k3=26.6;
k4=12000;
k5=5272.43;
k6=1476.87;
k7=8551.09;
k8=3662.64;
timespan = [0 60]
  1 个评论
Christopher McCausland
Hi Emily,
If you are using the latest version of MATLAB (R2023b) there is a new function which maybe quite helpful called ode.
I hope this helps!
Christopher

请先登录,再进行评论。

回答(1 个)

Udit06
Udit06 2023-11-16
Hi Emily,
I understand that you want to solve a system of non-linear differential equations with the given initial conditions. You can use MATLAB's "ode45" function to achieve the same. You can refer to the following MathWorks documentation to understand more about "ode45" solver.
A general approach to solve a system of differential equations with "ode45" is as follows:
1) Define your system using a function that takes time "t" and vector "y" of dependent variables as input and returns a vector containing the derivatives of the dependent variables with respect to time.
2) Create a vector containing the initial conditions for the dependent variables.
3) Define the timespan for which the system needs to be solved.
4) Call the "ode45" solver to solve the system.
You can refer to the following MATLAB answer which solves a system of non-linear differential equations using "ode45" function.
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Chemistry 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by