I understand that for one dimension of space a Rung Kutta 4 Formula for approximating the equations of motion given some force that depends only on the location of an object is
k1xn=vn
k2xn=vn+h*k1vn/2
k3xn=vn+h*k2vn/2
k4xn=vn+h*k3vn
xn+1=xn+h/6(k1xn+2*k2xn+2*k3xn+k4xn)
k1vn=f(xn)=acceleration
k2vn=f(xn+h*k1xn/2)
k3vn=f(xn+h*k2xn/2)
k4vn=f(xn+h*k3xn)
vn+1=vn+h/6(k1vn+2*k2vn+2*k3vn+k4vn)
h=Deltat
I tried using the above formula with the initial values being x=1, and v=0, the acceleration being given by the equation F=x, and h=0.3.
and found that the Rung Kutta 4 approximation is close to the analytical solution of x=cos(t) even after nearly 3000 time steps despite having such a large time step.
For comparison when I used the same initial conditions, same equation for acceleration, and same time step law, using a method where I approximate the differential equation using polynomials of the same degree as the order of differential equation, which I will just call the polynomial method in this thread, using the formulas
xn+1=1/2anh^2+vnh+xn
vn+1=anh+vn
The amplitude is already several times greater than that of cosine after only a few cycles.
I also tried using both the Rung Kutta 4 method and the polynomial method mentioned above to approximate the case where the initial position is 1, initial velocity is 0, and with a=sin(x).
For a time step of 0.006 I found that both formulas give nearly the same result even after nearly 3000 time stems.
Rung Kutta 4 in more than 1 dimension of space

 Posts: 75
 Joined: Thu May 15, 2014 5:45 pm
Rung Kutta 4 in more than 1 dimension of space
Gravitons would be my favorite particle as their existence could prove extra dimensions.

 Posts: 75
 Joined: Thu May 15, 2014 5:45 pm
Re: Rung Kutta 4 in more than 1 dimension of space
I tried changing the time step to 0.3
and found that with the polynomial method the x value doesn't even complete 1 cycle before rushing towards negative infinity
However for the Rung Kutta 4 method the amplitude is nearly the same as it was at the beginning implying that the Rung Kutta method I chose is more accurate than the polynomial method.
I know that for the polynomial method I mentioned the way to extend the method to two spatial dimensions is to use the formula
F=r/r*f(r)
So I though I could just change the formulas in the Rung Kutta 4 method to
k1rn=vn
k2rn=vn+h*k1vn/2
k3rn=vn+h*k2vn/2
k4rn=vn+h*k3vn
rn+1=rn+h/6(k1rn+2*k2rn+2*k3rn+k4rn)
k1vn=rn/rn*f(rn)
k2vn=rn+h*k1vn/2/rn+h*k1vn/2*f(rn+h*k1vn/2)
k3vn=rn+h*k2vn/2/rn+h*k2vn/2*f(rn+h*k2vn/2)
k4vn=rn+h*k3vn/rn+h*k3vn*f(rn+h*k3vn)
vn+1=vn+h/6(k1vn+2*k2vn+2*k3vn+k4vn)
I tried this approach on the inverse square law
And found that the method I chose gave a worse answer than the polynomial method I mentioned making me think I chose the wrong way to generalize the Rung Kutta 4 method as it should be more accurate than the polynomial method I mentioned.
What is the correct way to generalize the Rung Kutta 4 method to more than 1 dimension of space?
and found that with the polynomial method the x value doesn't even complete 1 cycle before rushing towards negative infinity
However for the Rung Kutta 4 method the amplitude is nearly the same as it was at the beginning implying that the Rung Kutta method I chose is more accurate than the polynomial method.
I know that for the polynomial method I mentioned the way to extend the method to two spatial dimensions is to use the formula
F=r/r*f(r)
So I though I could just change the formulas in the Rung Kutta 4 method to
k1rn=vn
k2rn=vn+h*k1vn/2
k3rn=vn+h*k2vn/2
k4rn=vn+h*k3vn
rn+1=rn+h/6(k1rn+2*k2rn+2*k3rn+k4rn)
k1vn=rn/rn*f(rn)
k2vn=rn+h*k1vn/2/rn+h*k1vn/2*f(rn+h*k1vn/2)
k3vn=rn+h*k2vn/2/rn+h*k2vn/2*f(rn+h*k2vn/2)
k4vn=rn+h*k3vn/rn+h*k3vn*f(rn+h*k3vn)
vn+1=vn+h/6(k1vn+2*k2vn+2*k3vn+k4vn)
I tried this approach on the inverse square law
And found that the method I chose gave a worse answer than the polynomial method I mentioned making me think I chose the wrong way to generalize the Rung Kutta 4 method as it should be more accurate than the polynomial method I mentioned.
What is the correct way to generalize the Rung Kutta 4 method to more than 1 dimension of space?
Gravitons would be my favorite particle as their existence could prove extra dimensions.

 Posts: 75
 Joined: Thu May 15, 2014 5:45 pm
Re: Rung Kutta 4 in more than 1 dimension of space
Nevermind, it seems I had the correct formula and the inaccuracies must have been from careless mistakes.
Gravitons would be my favorite particle as their existence could prove extra dimensions.
 testtubegames
 Site Admin
 Posts: 1081
 Joined: Mon Nov 19, 2012 7:54 pm
Re: Rung Kutta 4 in more than 1 dimension of space
That's super cool, I've been wondering about the difference between RK4 and the Euler method in GSim. I know they are off, just as you show in your first post, and the Euler method (can) diverge much more quickly. But on the other hand, I've been wondering about the best way to maybe do a sidebyside comparison. (Even with change the timestep, for that matter).
Your graphs do a nice job showing off that difference
Your graphs do a nice job showing off that difference