1
$\begingroup$

I have the following two equations ($a,b,c,d,e,f,g$ are constants)

$$\frac{dx_{1}}{dt}=-a-b\sin(c-x_{2})$$

$$(d+x_{1}^{3})\frac{d^{2}x_{2}}{dt^{2}}+ex_{1}^{2}\frac{dx_{1}}{dt}\frac{dx_{2}}{dt}=f(g-x_{1}^{2})\cos (x_{2})$$

and want to integrate it numerically as an initial value problem.

Is the right way to convert this into a first order system of ordinary differential equations (for Runge Kutta integration say) to have 4 first order equations for $x_{1},dx_{1}/dt,x_{2},dx_{2}/dt$? This would mean having to differentiate the first equation above to generate $d^{2}x_{1}/dt^{2}$.

Or the right way is to have 3 first order equations for $x_{1},x_{2},dx_{2}/dt$?

2 Answers 2

1

Let's introduce $$x_3 = \frac{dx_2}{dt}.$$ Then:

$$(d+x_{1}^{3})\frac{d^{2}x_{2}}{dt^{2}}+ex_{1}^{2}\frac{dx_{1}}{dt}\frac{dx_{2}}{dt}=f(g-x_{1}^{2})\cos (x_{2}) = \\ (d+x_{1}^{3})\frac{dx_{3}}{dt}+ex_{1}^{2}\frac{dx_{1}}{dt}x_3=f(g-x_{1}^{2})\cos (x_{2}). $$

Isolating $\frac{dx_{3}}{dt}$ on the left, you get:

$$\frac{dx_{3}}{dt}=\frac{f(g-x_{1}^{2})\cos (x_{2}) - ex_{1}^{2}\frac{dx_{1}}{dt}x_3}{d+x_{1}^{3}} \Rightarrow \\ \frac{dx_{3}}{dt}=\frac{f(g-x_{1}^{2})\cos (x_{2}) - ex_{1}^{2}\left(-a-b\sin(c-x_{2})\right)x_3}{d+x_{1}^{3}}. $$

Finally, your system of first order differential equations is:

$$\begin{cases} \displaystyle\frac{dx_{1}}{dt}=-a-b\sin(c-x_{2})\\ \displaystyle\frac{dx_2}{dt} = x_3\\ \displaystyle\frac{dx_{3}}{dt}=\frac{f(g-x_{1}^{2})\cos (x_{2}) - ex_{1}^{2}\left(-a-b\sin(c-x_{2})\right)x_3}{d+x_{1}^{3}} \end{cases}.$$

1

No, you do not have to harmonize the order of differentiation of the variable. You only need to address the derivatives that actually occur.

Thus using x1,x2,Dx2 as variables you can evaluate

Dx1 = -a−b*sin(c−x2)
D2x2 = (-e*x1^2*Dx1*Dx2+f*(g−x1^2)*cos(x2))/(d+x1^3)

and return Dx1, Dx2, D2x2 as derivative vector.