3

The ODE I'm working with is $$\dddot{x} + t^2\ddot{x} + 4x = 0$$ with $$x(0)=1, \dot{x}(0)=0, \ddot{x}=-1$$

I've written a very basic program in C++ to use the RK4 method to approximate a solution to first order ODEs. To get this particular ODE to be compatible with my code, I imagine I have to reduce the order to make this into a first order equation.

However, I don't really know how to go about this as generally I have only encountered this reduction issue with second order ODEs.

Can anyone help me get started or point me to somewhere with a thorough explanation/examples? I must admit my knowledge of ODEs is a bit rusty.

1 Answers1

5

Your suspicions are correct, you can convert an $n-th$ order differential equation into an n-dimensional system of first order equations.

Let $x_1 = x$, and then we have:

$$\begin{align} x_1' &= x' = x_2 \\ x_2' &= x'' = x_3 \\ x_3' &= x''' = -t^2 x_3 - 4 x_1 \end{align}$$

Our new system is:

$$\begin{align} x_1' &= x_2 \\ x_2' &= x_3 \\ x_3' &= -t^2 x_3 - 4 x_1 \end{align}$$

We are now left with converting the initial conditions, and we get:

$$x_1(0) = 1, x_2(0) = 0, x_3(0) = -1$$

Here are more examples-1 and examples-2.

Now you can apply the Runge-Kutta method to this first-order system of equations. You can see an example in Help with using the Runge-Kutta 4th order method on a system of 2 first order ODE's.. Of course, you have to modify this for the third equation.

Here are some worked examples including numerical results.

Amzoti
  • 56,629
  • You can also look at the link example and now search out more such examples. – Amzoti Jan 26 '15 at 22:57
  • I'm having difficulty following this, but thanks for taking the time to respond. Should I be trying to split up $$x'_3+t^2x_3+4x_1=0$$into two or more equations? Or am I to use the same technique as in the answer you linked, except with 3 different Runge Kutta equations at the same time as opposed to the 2 in your other example? – user142340 Jan 26 '15 at 23:00
  • You will go from a single third-order equation to a system of three first order systems. You now have to account for solving a system using Runge-Kutta. Clear? When solving a system, you would use something like: https://www.nsc.liu.se/~boein/f77to90/rk.html – Amzoti Jan 26 '15 at 23:03
  • I think I'm starting to get a clearer picture in my head. I see that you've taken the single third-order equation and by substitution given three first order systems. The example in your most recent link; just to be clear, I'll need an extra line in each stage of the RK equations, to account for the extra equation in my system, correct? – user142340 Jan 26 '15 at 23:12
  • Yes, correct, I added a link for some worked numerical examples. They do the conversion as above and then show numerical results. Keep working it until you get the aha moment! – Amzoti Jan 26 '15 at 23:13
  • I'll mark the question as answered, since you've done a pretty thorough job of that, thanks. I might encounter follow-up queries though which I may post as comments. Thanks again. – user142340 Jan 26 '15 at 23:14
  • @user142340: You might like to peruse the C++ code at: http://sherrytowers.com/2014/10/15/a-c-class-for-numerically-solving-odes/ – Amzoti Jan 26 '15 at 23:19