# Mathematics used for SpaceX first stage re-entry burn guidance?

I thought it would be fun to make a basic simulation of a first-stage fly-back of SpaceX's Falcon 9, but was wondering what mathematics is used to perform something like this. Looking at this page: http://en.wikipedia.org/wiki/Trajectory_of_a_projectile, there is a nice equation for calculating the distance a projectile will cover, but this is based on a flat earth, constant gravitational acceleration and an absence of drag. Furthermore, using this formula would also imply an instantaneous delta-v change for it to be accurate (unless we re-calculate $d$ every second or so during engine burn in order to get a more accurate result), which is also rather unrealistic considering the time scales involved.

So my question is this: If we consider the Falcon 9 first-stage to be a point mass so that we don't need to worry about 6 DOF attitude dynamics, and also only look at 2 dimensions instead of having to worry about a 3D spherical Earth, what equations would be used in order to accurately calculate the required burn time needed to get the Falcon 9 first-stage to within a few kilometres of its intended surface target when taking atmospheric drag and a circular Earth into consideration. Any links to informative websites covering something like this, or academic papers would be greatly appreciated. Thanks!

You really want to break down your exploration into a number of projects. I'm going to assume you have some mathematical and physics background. Otherwise, getting those is task #0.

First, you want to build a Runge Kutta integrator that will numerically integrate a system of differential equations from an initial condition state vector forward to an arbitrary moment in time.

Second, you want to derive the equations of motion for your vehicle. I would start with simply dropping an uncontrolled mass with some initial velocity.

Third, implement your control system of choice into the system of equations.

Finally, employ optimal control theory to minimize a cost function of choice (minimize propellent required perhaps?).

No, these are not necessarily simple things to do. But important things rarely are.

• Hi Erik, luckily I've managed to create the gravitational model already which will accurately calculate the first-stage's motion under the influence of variable gravitational acceleration. I didn't make an RK solver myself, but instead used Mathematica's NDSolve function and applied it to a system of ODEs describing gravitation. I'm a bit confused by the third point, could you possibly explain a little further (unfortunately I never took a course in Control Theory whilst at university)? – InquisitiveInquirer Jan 28 '15 at 6:26
• A simple control system would simply increase the thrust/weight ratio as your altitude decreased. If you have it approach 1.0 when your altitude is 0 you will actually land safely -- assuming you do not run our of propellant. So you would add another equation to your system of ODEs that represents this control strategy and solve. – Erik Jan 28 '15 at 6:33
• I shouldn't say safely actually. You might hit hard... ;) – Erik Jan 28 '15 at 6:35
• The F9 case doesn't quite work that way because it can't throttle down to a 1.0 TWR. – Russell Borogove Aug 8 '15 at 0:41
• One must walk before one can run... – Erik Aug 8 '15 at 0:44

Chapter 3 of Hicks' text Introduction to Astrodynamic Reentry provides an overview of the derivation of the reentry equations of motion. The text can be found at this link, and also provides an introduction into reentry control methods such as aerobraking. The translational reentry equations are highly-coupled, non-linear ordinary differential equations that require numerical routines (e.g., RK integrators) for solutions, unless some very simplifying assumptions are made (e.g., planar entry, constant bank angles, etc.). This reference at FAA.gov also provides a reentry discussion using a kinetic / potential energy tradeoff formulation, which could also be a good way to start thinking about your project.

• The book you've linked is quite fascinating. Is it available as free online resource/ for redistribution? – AtmosphericPrisonEscape Apr 6 '17 at 1:27

There's a fair amount written on the guidance system for the Apollo lunar landers; the same principles apply for any powered landing, although you have to add atmospheric drag into your model for Earth landings.

The equations shown under "Powered Descent Guidance Theory" on this page are the key to getting position and velocity deltas to zero at the same time (which is what you need for a precise soft landing).

Robert Braeunig's notes on his LM simulation are also potentially useful.

• Really beautiful links! That funky "triangular window" finally explained! I'm gonna read both of these through a few times today. Nice! – uhoh Aug 10 '16 at 1:41
• Digital Apollo is a really good read if you want to know more about the LM systems and operation. – Russell Borogove Aug 10 '16 at 2:00

You're not facing a mathematical problem, really, this is physics. Mathematics is just one of the tools needed. You also need drag models (aerodynamics)

And realistically this is solved by numerical methods. You calculate the time series x[t], y[t], vx[t], vy[t], Fx[t], Fy[t], m[t] for every time step dt. This replaces the calculation of the related differential equations and integrals.

I would do it as a numerical simulation and would plan on having a time step of a millisecond or less. Any modern processor should be able to do all the equations for each step in a few milliseconds at worst, so it should be able to run in real time (or my guess, much faster).

First you need to do the thrust and drag to get the forces, then use the mass at that time step to get the acceleration, use that to update the velocity vector and then use that to update the position vector.

My guess is that spherical earth washes out since you are outside of it and you can treat it as a point mass at the center.

So to get the thrust, you need to figure the baseline engine thrust and then what percentage of it you are running at in each time step. The atmospheric drag will be in the opposite direction of the velocity vector and will be basically some drag constant times projected area times the velocity relative to the air squared. (Yup, drag is a V squared phenominon) The gravity drag will be a constant. From that and the mass at the timeslice, you should be able to get the acceleration.

Start at takeoff with the location vector and velocity vector being zero and then do each time step and check that the results look plausible.