DEV Community

I Want To Learn Programming
I Want To Learn Programming

Posted on • Originally published at iwtlp.com

The rocket equation explained by coding it

The Tsiolkovsky rocket equation is the single most important formula in spaceflight, and it explains why getting to orbit is so brutally hard. It is one line, and coding it makes its consequences (including why rockets have stages) impossible to miss.

The equation

The change in velocity a rocket can achieve, its delta-v, is:

import math

def delta_v(exhaust_velocity, mass_initial, mass_final):
    return exhaust_velocity * math.log(mass_initial / mass_final)
Enter fullscreen mode Exit fullscreen mode

In words: delta-v equals the exhaust velocity times the natural log of the mass ratio (the rocket fully fueled, divided by the rocket empty). Two things give you more delta-v: faster exhaust (better engines), or a bigger mass ratio (more fuel relative to structure).

Why the log is the tyranny

That logarithm is the whole story. Because delta-v grows with the log of the mass ratio, getting more delta-v needs exponentially more fuel. Want to double your delta-v? You do not need twice the fuel, you need the mass ratio squared.

ve = 4500   # m/s, a decent chemical engine
# to reach low Earth orbit you need roughly 9,400 m/s of delta-v
# (after losses). Solve for the mass ratio that requires:
required_ratio = math.exp(9400 / ve)   # about 8.1
Enter fullscreen mode Exit fullscreen mode

A mass ratio of 8 means roughly 88% of the rocket at liftoff has to be propellant, leaving only about 12% for the engines, tanks, structure, and payload combined. That is why rockets are giant tanks with a tiny payload on top. This is "the tyranny of the rocket equation."

Why rockets have stages

Staging is the workaround. Once a tank is empty, you are dragging dead weight, which kills your mass ratio. Dropping spent stages lets the remaining rocket have a fresh, favorable mass ratio. The total delta-v is the sum of each stage's:

def staged_delta_v(stages):
    # stages: list of (ve, m_initial, m_final)
    return sum(delta_v(ve, mi, mf) for ve, mi, mf in stages)
Enter fullscreen mode Exit fullscreen mode

Coding it shows why a single-stage rocket to orbit is so hard with chemical fuel, and why nearly every orbital rocket sheds stages on the way up. The equation is not just trivia; it dictates the shape of every rocket ever flown.

Build the rocketry

The aerospace with Python track builds up from physics like this to real rocketry and simulation, all from scratch and graded in your browser. The first project is free.

One line of physics explains the size of every rocket. Code it, and the whole design logic of spaceflight falls out.

Top comments (0)