To calculate the first location, first_order does a diff diff, duplicates the first and last locations with an hstack, and then takes the mean of [:-1] and [1:] indexings of this array.
That gives the first location of the result $= \frac{\frac{x_1 - x_0}{dt} + \frac{x_1 - x_0}{dt}}{2} = \frac{x_1 - x_0}{dt}$.
But then the not-endpoints are doing second-order center-differencing, because
$$\frac{\frac{x_n - x_{n-1}}{dt} + \frac{x_{n+1} - x_n}{dt}}{2} = \frac{x_{n+1} - x_{n-1}}{2dt}$$.
This is the same as what second_order is doing for its central points. So first_order isn't truly first order, except at the endpoints.
To calculate the first location,
first_orderdoes a diffdiff, duplicates the first and last locations with anhstack, and then takes the mean of[:-1]and[1:]indexings of this array.That gives the first location of the result$= \frac{\frac{x_1 - x_0}{dt} + \frac{x_1 - x_0}{dt}}{2} = \frac{x_1 - x_0}{dt}$ .
But then the not-endpoints are doing second-order center-differencing, because
This is the same as what
second_orderis doing for its central points. Sofirst_orderisn't truly first order, except at the endpoints.