(A kind soul at physics.stackexchange suggested I post here as well, sorry if out of bounds.)
I'm trying to programmatically model a damped harmonic spring for use in mobile UI animations (physics mathematics isn't my background, please pardon any misconceptions).
Having derived the parameters for the general case equation, I can iteratively calculate values until I reach a suitable threshold, though because this is bound to "simple" trigonometric and $e^{x}$ functions on the CPU, the 4000-some-odd steps can cause about 0.25 seconds lag on slow devices while it calculates. I'd like to speed this up using my platform's super-optimized vector and BLAS/LAPACK variants.
The requirement for doing this is precalculating the number of steps necessary to reach my threshold value.
In the underdamped case, where the roots of the characteristic function of the differential equation are non-real, I can use algebraic tricks to get my values:
$$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t) + c_{2}e^{r_{2}}\sin(i_{2}t)$$
(Given $r_{1}$, $i_{1}$, $r_{2}$, and $i_{2}$ are the real and irrational components of my two roots, respectively.)
Knowing that $r_{1} = r_{2}$ and $i_{1} = -i_{2}$, I can simplify to:
$$x(t) = c_{1}e^{r_{1}}\cos(i_{1}t)$$
And get my desired value of $t$ for my threshold $a$:
$$t = \arccos(a / c_{1} / e^{r_{1}}) / i_{1}$$
When the roots are real, the equation looks a lot simpler:
$$x(t) = c_{1}e^{r_{1}} + c_{2}e^{r_{2}}$$
However, I don't have my trig functions floating around to help me solve it (even if I did, the irrational components being 0 would cause problems, of course).
Take the concrete example on pages 3-4 of this document (my bible during this process), since they at least solve cleanly:
$$x(t) = 1.5e^{-t} - 0.5e^{-3t}$$
I know how I would solve for $t$ to get my for when $x(t) = a$ on paper, by setting $x=e^{t}$, solving, and back substituting, but I don't have that luxury here.
I can make a few assumptions: the roots and constants are all real. I'm always going to be looking for the smallest, first, positive value of $t$. Obviously, the iterative solution is the simplest for this case, but in the end that would involve more steps and therefore be slower no matter what my other optimizations would be. How, then, would I go about solving for my threshold value algorithmically in this (supposedly) simplified case?
Addendum
The underdamped solution presents an extra requirement. The motion curve will oscillate back and forth a few times across the endpoint. Therefore, "first and lowest" $t$ requirement is not necessarily true. In my current, iterative code, the threshold value is both checked against the distance from the current $x(t)$ to the endpoint, as well as to the distance from the previous $x(t)$ as well to allow for a number of oscillations. This might make a more efficient solution nearly impossible.
For the general equation $m \ddot{x} + b \dot{x} + k x = 0$ you can find a solution with the following steps
Updated Answer