# Solving an initial value problem for a system of first- and second-order differential equations

Given the following system of differential equations (my actual system is $$10$$ times more complicated), I will need to find values of $$x_1, x_2, x_3, \ldots, z_3$$ at a given time, $$t$$.

$$\dfrac{dx_1}{dt} = -k_1x_1+k_2x_2-(K_R)x_1y_1$$

$$\dfrac{dx_2}{dt} = k_1x_1-k_2x_2-k_3x_2-(K_R)x_2y_2$$

$$\dfrac{dx_3}{dt} = k_3x_3$$

$$\dfrac{dy_1}{dt} = -k_1y_1+k_2y_2-(K_R)x_1y_1$$

$$\dfrac{dy_2}{dt} = k_1y_1-k_2y_2-k_3y_2-(K_R)x_2y_2$$

$$\dfrac{dy_3}{dt} = k_3y_3$$

$$\dfrac{dz_1}{dt} = -k_1z_1+k_2z_2+(K_R)x_1y_1$$

$$\dfrac{dz_2}{dt} = k_1z_1-k_2z_2-k_3z_2+(K_R)x_2y_2$$

$$\dfrac{dz_3}{dt} = k_3z_3$$

The initial conditions at $$t = 0$$, is $$x_2 = 1$$ and $$y_2 = 10$$. Everything else is zero at $$t = 0$$. The value of $$K_R$$ is 1e-3.

To help visualize, here's the system:

$$\require{extpfeil} \Newextarrow{\xrightleftharpoons}{5,5}{0x21CC} \begin{array}{} x_1 & \xrightleftharpoons[k_2]{k_1} \enspace & x_2 &\xrightarrow[]{k_3} & x_3 \\ + & \ & + \\ y_1 & \xrightleftharpoons[k_5]{k_4} \enspace & y_2 &\xrightarrow[]{k_6} & y_3 \\ \downarrow^{k_R} & \ & \downarrow^{k_R} \\ z_1 & \xrightleftharpoons[k_8]{k_7} \enspace & z_2 &\xrightarrow[]{k_9} & z_3 \\ \end{array}$$

The values of $$k_1, k_2, k_3, k_4, k_5, k_6, k_7, k_8, k_9,$$ are $$1, 0.25, 0.3, 1, 0.25, 0.3, 1, 0.25, 0.3.$$

I have used Python to solve a system of first order differential equations using matrix methods, which does not seem to work for a system of first- and second-order differential equations.

• in $x_2$ are you sure it's $-k_2x_2- k_3x_2$ and not $-k_2x_2- k_3x_3$? the same for $y_2$ and $z_2$...
– Mick
Mar 31, 2020 at 15:12
• Yes, please see if the box-and-arrow system makes sense.
– DPdl
Mar 31, 2020 at 15:23
• @Moo, yes please. Really struggling with this.
– DPdl
Mar 31, 2020 at 15:41

Here is a numerical solution using Mathematica, but you should be able to do this with Python, Matlab, Maple V, SAGE and many others.

 k1 = 1;
k2 = 0.25;
k3 = 0.3;
kr = 1 10^(-3);

{a,b,c,d,e,f,g,h,i}=NDSolveValue[{x1'[t]==-k1 x1[t]+k2 x2[t]-(kr)x1[t]y1[t],x2'[t]==k1 x1[t]-k2 x2[t]-k3 x2[t]-(kr) x2[t] y2[t],x3'[t]==k3 x3[t],y1'[t]==-k1 y1[t]+k2 y2[t]-(kr) x1[t] y1[t],y2'[t]==k1 y1[t]-k2 y2[t]-k3 y2[t]-(kr)x2[t] y2[t],y3'[t]==k3 y3[t],z1'[t]==-k1 z1[t]+k2 z2[t]+(kr) x1[t] y1[t],z2'[t]==k1 z1[t]-k2 z2[t]-k3 z2[t]+(kr)x2[t] y2[t],z3'[t]==k3 z3[t],x1[0]==0,x2[0] == 1, x3[0]==0, y1[0]==0,y2[0]==10, y3[0]== 0, z1[0] ==  0, z2[0] == 0, z3[0]==0},{x1, x2, x3, y1, y2, y3, z1, z2, z3},{t,-5,5}]

Plot[Evaluate[{a[t],b[t],c[t],d[t],e[t],f[t],g[t],h[t],i[t]}],{t,-5,5},PlotLegends->"Placeholder",PlotStyle->Thickness[0.01],  ImageSize->Large]


Here are the resulting graphs ($$1 = x1, 2 = x2...$$).

Note that three of the graphs are zero. The reason for this is that you have three of equations decoupled from the rest and they each result in something like

$$x_3' = \dfrac{3}{10} x_3, x_3(0) = 0 \implies x3(t) = 0$$

This is also true for $$y_3(t)$$ and $$z_3(t)$$.

Here is data from $$(-5, 5)$$ in steps of $$0.5$$ for each of the nine functions.The columns are $$(t, x_1(t), x_2(t), x_3(t), y_1(t), y_2(t), y_3(t), z_1(t), z_2(t), z_3(t))$$

$$\left( \begin{array}{cccccccccc} -5. & -102.864 & 750.148 & 0. & -1629.81 & 2752.71 & 0. & -66.7969 & -527.64 & 0. \\ -4.5 & -62.6326 & 200.726 & 0. & -848.138 & 1241.48 & 0. & -24.6458 & -85.0869 & 0. \\ -4. & -37.6416 & 80.0207 & 0. & -440.819 & 623.686 & 0. & -7.15583 & -19.6135 & 0. \\ -3.5 & -21.1229 & 37.2184 & 0. & -227.248 & 323.673 & 0. & -1.77987 & -5.39013 & 0. \\ -3. & -11.2592 & 18.6747 & 0. & -115.91 & 171.774 & 0. & -0.368699 & -1.66372 & 0. \\ -2.5 & -5.77925 & 9.86226 & 0. & -58.253 & 93.5828 & 0. & -0.0511651 & -0.559979 & 0. \\ -2. & -2.86044 & 5.46903 & 0. & -28.5741 & 52.8843 & 0. & 0.00335988 & -0.200667 & 0. \\ -1.5 & -1.34486 & 3.21088 & 0. & -13.3964 & 31.4409 & 0. & 0.00579917 & -0.0742138 & 0. \\ -1. & -0.5726 & 2.0186 & 0. & -5.70484 & 19.9456 & 0. & 0.00235167 & -0.026712 & 0. \\ -0.5 & -0.186919 & 1.36903 & 0. & -1.86521 & 13.6196 & 0. & 0.000442068 & -0.00785549 & 0. \\ 0. & 0. & 1. & 0. & 0. & 10. & 0. & 0. & 0. & 0. \\ 0.5 & 0.0856937 & 0.778327 & 0. & 0.85889 & 7.81397 & 0. & 0.000217037 & 0.00341098 & 0. \\ 1. & 0.12043 & 0.635708 & 0. & 1.20974 & 6.40144 & 0. & 0.000603757 & 0.00492809 & 0. \\ 1.5 & 0.129983 & 0.536819 & 0. & 1.30842 & 5.41844 & 0. & 0.000954418 & 0.00558321 & 0. \\ 2. & 0.1275 & 0.4632 & 0. & 1.28588 & 4.68431 & 0. & 0.001209 & 0.00581169 & 0. \\ 2.5 & 0.11964 & 0.405066 & 0. & 1.2087 & 4.10293 & 0. & 0.00136682 & 0.00580832 & 0. \\ 3. & 0.109736 & 0.357111 & 0. & 1.11037 & 3.62212 & 0. & 0.00144582 & 0.00566817 & 0. \\ 3.5 & 0.099422 & 0.316361 & 0. & 1.00742 & 3.2126 & 0. & 0.00146631 & 0.00544324 & 0. \\ 4. & 0.0894677 & 0.281071 & 0. & 0.907688 & 2.8572 & 0. & 0.00144561 & 0.00516559 & 0. \\ 4.5 & 0.0802052 & 0.250147 & 0. & 0.814626 & 2.54518 & 0. & 0.00139714 & 0.00485685 & 0. \\ 5. & 0.0717494 & 0.222855 & 0. & 0.729471 & 2.26935 & 0. & 0.00133081 & 0.00453248 & 0. \\ \end{array} \right)$$