Motion of a body given acceleration as a function of velocity I'm having trouble figuring this out. I'm trying to determine the final time and final velocity for the motion of a vehicle over a given distance along a straight line.
$t$ is time
$v$ is velocity
$a$ is acceleration
$r$ is displacement
$m$ and $c$ are constant
Known:
$t_0$, $v_0$, $r_0$, $\Delta r$
Acceleration of the vehicle is described by:
$a=\frac{f(v)-c}{m}$
I want to derive expressions for:
$\Delta t$, and $v$
$f(v)$ is a function which returns the force which the engine can apply at a given velocity. This is essentially a lookup against a table of values from the vehicle manufacturer. I can perform an accumulation over this if required.
I'm currently estimating a result to this problem by iteratively calculating using small intervals of time.
Any help would be greatly appreciated.
 A: Since $a = \dot{v}$, your equation of motion is the ODE
$$m\dot{v} = f(v) - c$$
This is an autonomous first-order ODE; separating the variables gives
$$m\int_{v(0)}^{v(t)} \frac{1}{f(w)-c}dw = t,$$
and if you had a formula for $f$ you could try to perform the integration on the LHS to get $mg(v) = t$, and then solve for $v$.
Since you only have numerical data, though, your best bet is numerical quadrature (which it sounds like you're already doing). For instance, pick a time step $h$ a good bit smaller than your estimated $\Delta t$, and iterate
\begin{align*}
r_{i+1} &= r_i + h v_i\\
v_{i+1} &= v_i + h \frac{f(v_i) -c}{m}\\
t_{i+1} &= t_i + h
\end{align*}
until $r_i-r_0 > \Delta r$.
A: You are trying to calculate $\frac 1m \int f(v)-c \; dt$ and unless you have a nice formula for $f(v)$ you will be doing it numerically, which basically amounts to what you are doing-add up accelerations times small timesteps.  If $f(v)$ is reasonably smooth, you can reduce the calculation time and make it more robust by using an adaptive integration routine.  Any numerical analysis text will have a discussion.  I like Numerical Recipes, which is free online and has routines in C.
A: I think you can get much farther with explicit methods than the other answers suggest.
First, given $a$ as a function of $v$, we can find $t$ as a function of $v$ by integration:
$$\begin{gather}
\frac{\mathrm dv}{\mathrm dt}=a=\frac{f(v)-c}m.\\
\frac m{f(v)-c}\,\mathrm dv=\mathrm dt.\\
\int_{v_0}^{v_1}\frac{m\,\mathrm dv}{f(v)-c}=\int_{t_0}^{t_1}\mathrm dt=t_1-t_0.
\end{gather}$$
Since $f(v)-c$ is piecewise linear, $\int_{v_0}^{v_1}m\,\mathrm dv/(f(v)-c)$ is piecewise logarithmic and you can compute it explicitly. This gives us $t$ as an increasing function of $v$, which I'll call $\tau$:
$$t_1=\tau(v_1):=t_0+\int_{v_0}^{v_1}\frac{m\,\mathrm dv}{f(v)-c}.$$
Now we get $r$ by integrating again:
$$\begin{gather}
\tau(v)=t.\\
\frac{\mathrm dr}{\mathrm dt}=v=\tau^{-1}(t).\\
r_1-r_0=\int_{t_0}^{t_1}\tau^{-1}(t)\,\mathrm dt.
\end{gather}$$
It appears we have to integrate $\tau^{-1}$, which seems complicated. But not too complicated: let $t_0=\tau(v_0)$ and $t_1=\tau(v_1)$, and then we have
$$\int_{t_0}^{t_1}\tau^{-1}(t)\,\mathrm dt=(t_1v_1-t_0v_0)-\int_{v_0}^{v_1}\tau(v)\,\mathrm dv,$$
and integrating the piecewise logarithmic $\tau$ can also be done explicitly. So now we have $r$ as another explicitly known, increasing function of $v$. Your problem amounts to finding the $v$ for the given $r$, which you will have to do via a numerical procedure, but something really simple like bisection search should work just fine.
A: As user7530 says, you could integrate numerically by using a first order  Euler method to integrate numerically
\begin{align*} r_{i+1} &= r_i + h v_i\\ v_{i+1} &= v_i + h a_{i+1} \\
a_{i+1} &  = \frac{f(v_i) -c}{m}\\ t_{i+1} &= t_i + h \end{align*}
until $r_i-r_0 > \Delta r$.
But you could use different methods to integrate numerically.  One way to test whether it's worth using a more complicated method would be to replace your looked up acceleration function with something that has a nice formmula for f(v), and then compare the numerical result with the exact result.
