Rung Kutta 4 in more than 1 dimension of space
Posted: Sat Jun 05, 2021 1:44 am
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.
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.