I am trying to find out the magnitude of the acceleration of my object based on non-uniformly sampled 3D position data. I'm using the standard approximation of the 2nd order derivative on a non-uniform grid (see e.g. here, page 121):$$ f'' \approx 2 \cdot\frac{h^+ f_0 - (h^- + h^+) f_1 + h^- f_2}{h^+ h^- (h^+ + h^-)}$$where $h^-$ is the first sample interval, $h^+$ is the second sample interval, and $f_n$ are the sampled points.I'm trying to implement it in the following way:class ComputeAcceleration{    Vector3D prevPosition;    Vector3D prevPrevPosition;    float prevTimeStep;    float acceleration;    // This function gets called every time step with the time step    // since the last data input as argument.    void Update(const float timeStep)    {        float doubleTimeStep = prevTimeStep + timeStep;        Vector3D currentPosition = getCurrentPosition();        Vector3D accelerationVector = prevTimeStep * currentPosition -                                       doubleTimeStep * prevPosition +                                       timeStep * prevPrevPosition;              accelerationVector  *= 2 / (doubleTimeStep * prevTimeStep * timeStep);        acceleration = sqrt(accelerationVector.X * accelerationVector.X +                            accelerationVector.Y * accelerationVector.Y+                            accelerationVector.Z * accelerationVector.Z);        prevPrevPosition = prevPosition;        prevPosition = currentPosition;    }}I can't find the error in this, but when I plot this in real-time, I get a curve that doesn't resemble acceleration at all, but rather speed, in some jerky way. I plotted it against the speed (which I know to be correct), and it looks roughly like this:Am I doing something fundamentally wrong here?
Why does my Finite Difference approximation not work?
finite difference;computational physics