[Math] 3-Dimensional Runge Kutta Method

numerical methodsrunge-kutta-methods

I have a second order non-linear differential equation in 3 dimensions which can't be solved analytically and have been looking at different numerical methods for solving it. I am particularly interested in RK4, but I don't know how it generalizes to 3 dimensions after checking Google for quite some time. The problem looks as such:

$$
x'' = f(x, x', y', z') \\
y'' = g(y, x', y', z') \\
z'' = h(z, x', y', z') \\
x(0) = x_0, y(0)=y_0,z(0) = z_0 \\
x'(0) = x'_0, y'(0)=y'_0, z'(0)=z'_0
$$

From here, I've gotten it down to a system of first order differential equations and I get:

$$
u' = f(x,u,v,w) \\
v' = g(y,u,v,w) \\
w' = h(z,u,v,w) \\
x' = u \\
y' = v \\
z' = w
$$

My problem now is how Runge-Kutta works in 3 dimensions. The calculation for $K_1$ seems easy enough, but for the other ones I'm stuck. For example, $K_2 = \Delta x f(x_n + \frac{\Delta x}{2},y_n+\frac{K_1}{2}) $ but I don't know what to put for the other parameters.

Best Answer

Write your equation as a first order one by defining new variables for the first derivatives. Your points are now six position vectors, the first three being $x,y,z$ and the last three being $x',y',z'$. Your equation becomes $$\begin {pmatrix} x\\y\\z\\x'\\y'\\z' \end {pmatrix}'=\begin {pmatrix} x'\\y'\\z'\\f\\g\\h \end {pmatrix}$$ This is a first order equation, which is what RK4 is written for. It operates on vectors instead of a single variable, but that doesn't change anything.

Added: If your derivatives are all with respect to time, you just make all the $K$ equations a vector, so $K_1=hf(y_n)$ becomes the vector $K_1=h(u',v',w',u,v,w)^T$ and $K_2=hf(y_n+\frac 12K_1)$ becomes the same but you half step all the variables on the right, so the arguments of your functions become $x_n+\frac h2x'_n$ and so on.