# Solving numerically, the position of a rocket from its forces

So how would you solve this equation of the rocket, to find the position of the rocket as it changes with time?

$$T(t) - m(t)g - kv^2 = m(t)a$$

Thrust(changes with time) - weight(changes with time) - drag(changes with velocity) = mass(changes with time) * acceleration

If I knew the thrust function, the change in mass function and the value of $$k$$.

Would you be able to create code to numerically solve this, conceptually?

• Thank you Noah, can you help me with my question though? Jun 25 at 21:16

You also need some initial condition, like the velocity $$v$$ at $$t=0$$, let's call it $$v_0$$, and the position $$x$$ at $$t=0$$, let's call it $$x_0$$.

We know that the acceleration is the change of velocity with time, $$a = \frac{dv}{dt}$$, and the velocity is the change of position with time, $$v = \frac{dx}{dt}$$. I am assuming this problem to be 1-dimensional.

If we want to do this numerically, we cannot take infinitesimally small time steps $$dt$$, so we must choose some (small) finite step size $$\Delta t$$, at which we will want to evaluate the position.

From the equation you gave, we can derive an expression for $$a(t)$$ by simply dividing by $$m(t)$$. Now we can start our numerical calculation. Let's denote the individual timesteps with an index $$k$$, so the times at which we evaluate the variables will be at $$k \cdot \Delta t$$.

At $$t=0$$, we already know acceleration, velocity, and position. They are $$a(0) = \frac{T(0) - m(0)g -kv(0)^2}{m(0)}$$, $$v(0)=v_0$$, and $$x(0) = x_0$$. To get $$x(\Delta t)$$, we use the approximation $$x(\Delta t) \approx x(0) + \Delta t \cdot v(0)$$. The same goes for the velocity, $$v(\Delta t) = v(0) + a(0) \cdot \Delta t$$. Now that we know $$a(\Delta t)$$, $$v(\Delta t)$$, and $$x(\Delta t)$$, we can repeat this whole process to get $$x(2\Delta t) \approx x(\Delta t) + v(\Delta t) \cdot \Delta t$$ and $$v(2\Delta t) \approx v(\Delta t) + a(\Delta t)\cdot \Delta t$$, and so on, for any $$k\Delta t$$.

This is just one possible approximation, but in my opinion the one that's the easiest to understand. Others formulas try to improve numerical accuracy by including more terms or shifting some times slightly, but that's a bit outside the scope of this answer.

• Thankyou this is so helpful! Jun 25 at 23:02
• Is there a name for this method and how accurate would be if Δt = 0.01 s. Also if there is any more accurate methods what would they be? Jun 26 at 9:16
• This is called the (forward) Euler method. How accurate it is for specific values of $\Delta t$ depends entirely on the form $a(t)$ takes. You can find other methods e.g. on Wikipedia, the name for such methods is numerical integration.
– noah
Jun 26 at 9:41

Yes, you will need a discretization of time $$t_1, t_2, ... , t_N$$. Then:

$$T(t_1) - m(t_1) g = m(t_1) \, a(t_1)$$

(I assumed that $$v(t_1) = 0$$) and you solve for $$a$$:

$$a(t_1) = \frac{T(t_1)}{m(t_1)}-g$$

Now you can compute $$v$$ for the next instant:

$$v(t_2) = a(t_1) \, (t_2-t_1)$$

Then you compute the next acceleration $$a(t_2)$$ then $$v(t_2)$$, $$a(t_3)$$ and so on...

• Thankyou this is great! Jun 25 at 23:02
• Is there a name for this method and how accurate would be if Δt = 0.01 s. Also if there is any more accurate methods what would they be? Jun 26 at 9:16
• I guess this is the forward Euler method, as @noah already stated. As for the accuracy of this method, I cannot tell by heart but you can check this en.wikipedia.org/wiki/Euler_method#Global_truncation_error for a starting point. I really can't tell if the value you provided for $\Delta t$ will be good enough. That will not only depend on the truncation error but also on your specific needs.
– Javi
Jun 27 at 1:12
• This answer doesn't make sense. You cannot subtract acceleration from mass. Jun 27 at 2:47
• It was a typo in the latex code. Thanks for pointing out
– Javi
Jun 27 at 4:18