Using Riemann sums to approximate the second antiderivative I’m currently working on a coding project where I’m given the the net force acting on an object at any time $t$ (meaning I essentially have its acceleration). I know the object’s current position and I want to move it accordingly as a result of that force very gradually. I have a variable, say $x$ (position), and a function $a(t)$ (acceleration). Now, to calculate its position at $t+h$ (for a very small $h$, and then repeat this process), would I essentially add $ah^2$ to $x$ to get the new $x$? The second antiderivative of acceleration with respect to time is $0.5t^2$, so I’m a bit confused. And I tried to find online double Riemann Sums, yet the online double Riemann Sums are for two independent indices of integration $x, y$ whereas I have $t, t$. Could you please clarify the correct value to add?
 A: Well, what you would want to do ideally is create a new variable $v(t)=v(0)+\int^t_0 a(t')\,dt'$, and approximate $v(t)$ using Riemann sums. We know that $x(t)=\int^t_0 v(t')\,dt'$, so we can then use Riemann summation of $v$ to estimate $x$. That being said, if you don't know $v(0)$ then there is no way to calculate the position.
We can do this explicitly with variables. Suppose we know the values of $x, v, a$ at $t=0$. We also know $a(n\Delta t)$, where $n\in\mathbb{N}$. Then, using trapezoidal rule, we can estimate $v(t)$:
\begin{align*}
v(n\Delta t)&\approx v(0)+\frac{a(0)+a(\Delta t)}{2}\Delta t+\frac{a(\Delta t)+a(2\Delta t)}{2}\Delta t+\cdots+\frac{a((n-1)\Delta t)+a(n\Delta t)}{2}\Delta t\\
&=v(0)+\Delta t\left[\frac{a(0)}{2}+a(\Delta t)+a(2\Delta t)+\cdots+a((n-1)\Delta t)+\frac{a(n\Delta t)}{2}\right]\\
&=v(0)+\Delta t\left[\frac{a(0)+a(n\Delta t)}{2}+\sum^{n-1}_{i=1}a(i\Delta t)\right]
\end{align*}
Similarly, we can approximate $x(n\Delta t)$:
\begin{align*}
x(n\Delta t)&\approx x(0)+\frac{v(0)+v(\Delta t)}{2}\Delta t+\frac{v(\Delta t)+v(2\Delta t)}{2}\Delta t+\cdots+\frac{v((n-1)\Delta t)+v(n\Delta t)}{2}\Delta t\\
&=x(0)+\Delta t\left[\frac{v(0)}{2}+v(\Delta t)+v(2\Delta t)+\cdots+v((n-1)\Delta t)+\frac{v(n\Delta t)}{2}\right]\\
&=x(0)+\Delta t\left[n\Delta t+\frac{v(1)}{2}+v(\Delta t)+v(2\Delta t)+\cdots+v((n-1)\Delta t)+\frac{v(n\Delta t)}{2}\right]\\
&=x(0)+n\Delta tv(0)+\Delta t^2\left[\frac{(2n-1)a(0)}{4}+(n-1)a(\Delta t)+(n-2)a(2\Delta t)+\cdots+a((n-1)\Delta t)+\frac{a(n)}{4}\right]\\
&=x(0)+n\Delta tv(0)+\Delta t^2\left[\frac{(2n-1)a(0)+a(n)}{4}+\sum^{n-1}_{i=1}(n-i)a(i\Delta t)\right]\\
\end{align*}
If you wanted to use Midpoint rule/Simpson's rule/Euler-Maclaurin formula the expression for the estimate of $x$ would be different.
