I have (or, rather, a friend whom I'm trying to help has) a very messy differential equation, which I thought I'd try to solve numerically. However, I'm a little confounded as to what approach to use when doing this.

The equation is on the form

$\ddot\alpha(t) = f(\dot\alpha(t), \alpha(t), \dot\varphi(t), \varphi(t))$

where $\alpha(t)$ and $\varphi(t)$ are both unknown functions of time, to be determined (and $f$ is a crazy beast1...). I have initial values for both the functions and their first derivatives, so it should just be a matter of choosing an integrator and start to iterate.

However, all of the examples I find on e.g. Wikipedia are all for first-order equations, and I'm a little unsure what integrator to use. It's too long ago I took a basic course in numerical methods so even if they are applicable to this problem anyway, I don't remember how to adapt them :p

Is there a good integrator that works on a problem such as the one stated above? If so, pointers to some good explanation of it would be appretiated =)

Upon asking my friend for an expression for $\ddot\varphi$, in order to make a substitution and transform this into a first-order problem, it turned out that she had such an expression. However, when trying to transform the equations, I end up with a system on the form

$\dot\beta = f(\beta,\alpha,\gamma,\varphi,\dot\gamma)$
$\dot\gamma = g(\beta,\alpha,\gamma,\varphi,\dot\beta)$
$\dot\alpha = \beta$
$\dot\varphi = \gamma$

because, as you can see in the original problem2, the second order derivatives also depend on each other. How do I tackle this? Another substitution? Or can I somehow decouple these equations first, so the second order derivatives are independent of each other?

1The full problem, as it was originally stated for me:

$\displaystyle \ddot\alpha = \frac{(l\dot\alpha\cos(\alpha+\varphi)-g\sin\varphi)\sin(\alpha+\phi)+mlh\dot\varphi^2\cos(\alpha+\varphi)+V\cos\alpha}{E-Ml^2\sin^2(\alpha+\varphi)}$

All quantities except $\alpha$ and $\varphi$, and their derivatives, are known constants.

2The full problem, but now stated in a different form:

$I\ddot\alpha = Mlh\ddot\varphi\sin(\alpha+\varphi)+Mlh\dot\varphi^2\cos(\alpha+\varphi)+V\cos\alpha$
$h\ddot\varphi = l\ddot\alpha\sin(\alpha+\varphi)+l\dot\alpha^2\cos(\alpha+\varphi)-g\sin\varphi$

  • $\begingroup$ If you are going to determine $\varphi(t)$ you need an equation of the form $\ddot \varphi(t)=g((\dot\alpha(t), \alpha(t), \dot\varphi(t), \varphi(t))$ as well. Do you have it? Then you define a pair of auxiliary variables, $\beta(t)=\dot \alpha(t)$ and $\gamma(t)=\dot \varphi(t)$ and your equations become $\dot\beta(t) = f(\beta(t), \alpha(t), \gamma(t), \varphi(t))$ and the corresponding one for $\dot \gamma(t)$. Now you have four first order equations in four unknowns and can use a first order integrator. $\endgroup$ – Ross Millikan Apr 24 '13 at 21:19
  • $\begingroup$ @Thomas Lycken: you said $\varphi(t)$ is an unknown function and will need it (and its derivative) to calculate $\ddot \alpha (t)$. I was guessing where you might get them. $\endgroup$ – Ross Millikan Apr 24 '13 at 21:24
  • $\begingroup$ @RossMillikan: As it turns out, I do have an equation for $\ddot\varphi$ as well - but that was not in the form the problem was given to me. I'll give it a try and get back =) $\endgroup$ – Tomas Aschan Apr 24 '13 at 21:25
  • $\begingroup$ @RossMillikan: It was a good approach, but there is more to be done before I know how to solve the problem. Please see my update for the details. $\endgroup$ – Tomas Aschan Apr 24 '13 at 21:44

This problem wasn't so hard to solve, after all, as soon as I remembered how to classify it; it's implicit, which is the biggest part of the reason I struggled. This is how to solve it:

  1. Rewrite it as a first-degree problem, using substitutions as suggested by Arkamis. I had a system of two second-degree equations, so I ended up with four first-degree equations.

    $ \left\{\begin{array}{rcl} I\dot\alpha-Mlh\dot\beta\sin(\theta+\phi)-Mlh\beta^2\cos(\theta+\phi)-V\cos\theta & = & 0 \\ h\dot\beta-l\dot\alpha\sin(\theta+\phi)-l\alpha^2\cos(\theta+\phi)+g\sin\phi & = & 0 \\ \dot\theta-\alpha & = & 0 \\ \dot\phi - \beta & = & 0 \end{array}\right. $

  2. This system s on the form $f(t,y,\dot y)=0$, with $y=(\alpha,\beta,\theta,\phi)$, and can be solved with any implicit ODE solver, such as Matlab's ode15i. That's what I did =)


All second-order problems can be converted into a system of first order problems.

$$\ddot{y} = f(t,y) \longrightarrow y_1 = y,\ y_2 = \dot{y_1} \longrightarrow \dot{y_1} = y_2,\ \dot{y_2} = f(t,y_1)$$


If you're just looking for a numerical integration, you've done all the decoupling you need to. First, you have to assign values for your initial $\beta$, $\alpha$, $\gamma$, and $\phi$, as well as your initial $\dot{\beta}$, $\dot{\alpha}$, $\dot{\gamma}$, and $\dot{\phi}$. Note that initial $\dot{\beta}$, $\dot{\alpha}$, etc. cannot be derived from initial $\beta$, $\alpha$,etc. You have to decide what they are. Now you are ready to plug all of these into your favorite numerical integrator along with your formulae, and run it a time step to get your next set of values, and then plug them in again etc. For numerical methods, you might Google the "leapfrog" method to start with, and once you're confortable with that, try 4th order Runge-Kutta.

  • $\begingroup$ All of the initial conditions, both $\alpha(0)$ etc and $\dot\alpha(0)$ etc are known - but I'm still uncertain on how to tackle the interdependence of $\ddot\alpha$ and $\ddot\phi$ (i.e. $\dot\beta$ and $\dot\gamma$) in the equations. If I plug all the initial values into, say, the leapfrog integrator, I'm still short of one parameter. How do I handle that? Do I need initial values for those as well? $\endgroup$ – Tomas Aschan Apr 24 '13 at 23:38
  • $\begingroup$ And how do I calculate them in my integrator? Since they're interdependent, I can't calculate either without first knowing the other... $\endgroup$ – Tomas Aschan Apr 24 '13 at 23:43
  • $\begingroup$ As for choice of integrator, I'll probably just use Matlab's ode45, if I can - it's an easy way to avoid unecessary bugs :P $\endgroup$ – Tomas Aschan Apr 25 '13 at 0:00
  • $\begingroup$ OK, I see your point. I'm not going to have time to think about this much. Two things come to mind: 1) If $f(...)$ and $g(...)$ are at all tractable, then the equations for $\dot{\beta}$ and $\dot{\gamma}$ put together will allow you to solve for your missing parameter. 2) If they are complicated, you could run an iterative scheme: take your best guess for all parameters, plug them in, and use your equations to get values for for $\dot{\beta}$ and $\dot{\gamma}$, then plug those in again, and get new values etc. until convergence. $\endgroup$ – bob.sacamento Apr 25 '13 at 0:01
  • $\begingroup$ Ran out of characters. The second option I was suggesting is something you would do for, I don't know, a thesis or something, not a homework assignment. Mind if I ask what the context of this thing is? $\endgroup$ – bob.sacamento Apr 25 '13 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.