I'm working on a piece of code that is supposed to visualize a particle bouncing up and down from the ground (somehow magically we can give it velocity upwards when it is on the ground). I figured that I'd try to remember my high school physics and find the formula myself.
So, I have a particle on the ground ($distance = 0$) at $t_0 = 0$. It's given an initial velocity $v_0$. The task is to calculate the distance from the ground at $t = t_1$
Force due to gravity is $F_g = a*m = {-GMm}/{d^2}$, giving that $a = M/d^2$ (I drop $G$ since it has no use in my application).
Then, onto integrating. Integral of acceleration is velocity, and integral of velocity is distance. Bingo!
Given that $t_0 = 0$ $$ v = v_0 - \int_{t_0}^{t_1} \frac{M}{d^2}dt = v_0 - \frac{Mt_1}{d^2}\\ d = \int_{t_0}^{t_1}vdt = v_0t_1 - \frac{Mt_1^2}{2d^2} $$
Manipulating this a bit, I get $2d^3 - 2d^2*v_0t_1 + Mt_1^2 = 0$
Ok, time to test this. Let's see what I get if I set the initial velocity to $10$, $t_1$ to $1$, and $M$ to $100$.
$$ 2d^3 - 2d^2*(10)(1) + (100)(1)^2 = 0 $$
Running this through R
z <- c(100, 0, -20, 2)
polyroot(z)
# returns
# [1] 2.599243+0i -2.038016+0i 9.438772-0i
There are 3 roots! What?
Where did I go wrong?