# [pstricks] Searching for a numeric solution for coupled differential equation systems of order 2

Alexander Grahn A.Grahn at hzdr.de
Fri May 25 11:15:11 CEST 2012

On Thu, May 24, 2012 at 10:21:06PM +0200, Juergen Gilg wrote:
>Dear PSTricks list,
>
>is there anybody out there, knowing about how to generate a PS code for
>"Runge-Kutta 4" to solve a "coupled differential equation system of
>order 2"?
>
>There is the need for such a code to animate a double-pendulum in real
>time, following the coupled differential equations with the variables
>(\varphi_1, \varphi_2) and their derivatives like:
>
>(1)
>l_1\ddot{\varphi}_1+\frac{m_2}{m_1+m_2}l_2\ddot{\varphi}_2\cos(\varphi_1-\varphi_2)-\frac{m_2}{m_1+m_2}l_2\dot{\varphi}_2^2\sin(\varphi_1-\varphi_2)+g\sin\varphi_1=0
>
>(2)
>l_2\ddot{\varphi}_2+l_1\ddot{\varphi}_1\cos(\varphi_1-\varphi_2)-l_1\dot{\varphi}_1^2\sin(\varphi_1-\varphi_2)+g\sin\varphi_2=0

I'd first transform this set of DEs of second order into a set of four
DEs of first order, since Runge-Kutta only works on first order DE sets,
as far as I know.

However, it may still not be amenable to Runge-Kutta, because the right
hand sides of the resulting four equation set of DEs, put into normal
form, still contain derivatives:

\begin{align}
\dot\varphi_{11}& = \varphi_{12}\\
\dot\varphi_{12}& = f(\varphi_{11}, \varphi_{21}, \varphi_{22}, \dot\varphi_{22})\\
\dot\varphi_{21}& = \varphi_{22}\\
\dot\varphi_{22}& = f(\varphi_{11}, \varphi_{12}, \dot\varphi_{12}, \varphi_{21})
\end{align}

Perhaps, an iteration procedure is required to determine $\dot\varphi_{12}$
and $\dot\varphi_{22}$ on the right hand sides of the equations above?

An implementation of the Runge-Kutta 4 method is given in the animate
package documentation (Lorenz attractor example). It writes the solution
vector into a file, that can be read out for plotting by other PSTricks
utilities. The DE system for calculating the right hand sides must be
written in PS syntax.

Alexander