weejee said:
x_n+1 = x_n + v_n*dt
v_n+1 = v_n + a(x_n+1)*dt
That is not the quite the standard Euler method. Using your notation, the basic Euler method for updating the position and velocity is
x_n+1 = x_n + v_n*dt
v_n+1 = v_n + a(x_n)*dt
One way of looking at the basic Euler method is by looking at the position+velocity state as a 6-vector:
\mathbf u_n = \bmatrix<br />
x_{n,1} \\ x_{n,2} \\ x_{n,3} \\<br />
v_{n,1} \\ v_{n,2} \\ v_{n,3} \endbmatrix
Euler's method for a scalar function
u is simply u_{n+1} = u_n + f(u_n)\Delta t[/math] where [math]f(u_n)[/math] is the derivative function: [math]du/dt = f(u).
Now extend this to multiple dimensions: \mathbf u_{n+1} = \mathbf u_n + \mathbf f(\mathbf u_n)\Delta t. Finally, the derivative function in this case is
\mathbf f(\mathbf u_n) = \bmatrix<br />
v_{n,1} \\ v_{n,2} \\ v_{n,3} \\<br />
a_1(x_n) \\ a_2(x_n) \\ a_3(x_n) \endbmatrixOne problem with the basic Euler method is that it fails to conserve energy in a problem where energy should be conserved. There is a simple technique that does conserve energy. Once again using your notation,
v_n+1 = v_n + a(x_n)*dt
x_n+1 = x_n + v_n+1*dt
This is called the symplectic Euler technique (it has a lot of other names as well). Basic Euler updates position using the previous velocity and updates velocity using the acceleration based on the previous position. Symplectic Euler updates velocity using the acceleration based on the previous position and updates position using the updated velocity.
Your technique updated position using the previous velocity and updated velocity using the acceleration based on the updated position. Switching from basic Euler to symplectic Euler results in a drastic improvement. Switching from basic Euler to what you did makes the basic Euler technique look good. (Quite an accomplishment!)How about RK4? It, like the basic Euler technique, does not conserve energy in a conservative problem.