Suppose I have the current position, velocity and acceleration of a particle. As I see it, the best estimate of its velocity and position at a time $\Delta t$ from now should be $$\vec{v}(t+\Delta t) = \vec{v}(t) + \vec{a}\Delta t$$ $$\vec{s}(t+\Delta t) = \vec{s}(t) + \vec{v}(t)\Delta t + \frac{1}{2} \vec{a} \Delta t^2$$ However, by doing some simulations, I've noticed that an extremely more accurate method would be to consider $$\vec{v}(t+\Delta t) = \vec{v}(t) + \vec{a}\Delta t$$ $$\vec{s}(t+\Delta t) = \vec{s}(t) + \vec{v}(t)\Delta t + \vec{a} \Delta t^2$$ Which is almost the same, except by the missing $1/2$ factor. The position equation is also equivalent to $$\vec{s}(t+\Delta t) = \vec{s}(t) + \vec{v}(t+\Delta t)\Delta t$$ To show how better it is, here is the absolute deviation to the analytical solution with both methods for a simple harmonic oscillator
So the error or deviation of the second method stays almost the same while the first one increases much faster, more specifically it seems the error of the first method increases quadratically and the second linearly. I've also got this result by simulating a gyroscope and a wave propagating through a string.
What explains this counterintuitive result?
Edit
To add more details to the question, here is the implementation for the oscillator example:
- The position and velocity are initially equal to 2 constants
x0andv0defined in the code - The acceleration is given by $-\omega^2x$, according to the harmonic oscillator differential equation, where $x$ is the current position and $\omega$ a constant that is related to the mass and elastic constant.
- Each iteration of method 1 is given by
dv = acc(x)*dt
x += dt*(v + 1/2*dv)
v += dv
- Each iteration of method 2 is given by
v += acc(x)*dt
x += v*dt
