Ordinate 2D Marketplace Community Open the studio

Marketplace › From Ordinate 2D

The rocket equation

Script by Ordinate 2D ✓ · Dynamics

A rocket that burns fuel gets lighter: Δv = v_e ln(m₀/m) − gt, mass and thrust set from the script.

Use in Ordinate 2DOpens in the Script tab: it runs when you press Run. Free, no account needed.
"""The rocket equation: a rocket that burns fuel gets lighter, so it speeds up faster and faster.

A 2 kg rocket carries 1 kg of fuel and throws it out at v_e = 60 m/s (thrust = v_e·ṁ = 24 N, ṁ = 0.4 kg/s). Each step the script sets the rocket's
mass and thrust. The speed follows Δv = v_e ln(m₀/m) − g t, written next to the measurement; the table has both.

Runs in the studio (Script tab → Run) and locally:  python3 rocket_equation.py
"""
import math
import studio as s

M0, FUEL, VE, MDOT, G = 2.0, 1.0, 60.0, 0.4, 9.81

s.clear()
s.gravity = (0, -G)
s.ground(0, width=10)
rocket = s.box(0, 0.45, 0.3, 0.9, mass=M0, name="Rocket", color="#e5484d", friction=0.5)


@s.on_step
def burn(t, dt):
    burned = min(FUEL, MDOT * t)
    rocket.mass = M0 - burned
    rocket.force = (0, VE * MDOT if burned < FUEL else 0.0)
    if round(t / dt) % 12 == 0:                       # 20 rows a second
        m = M0 - burned
        s.record(t=t, mass=m, v=rocket.vy, v_theory=VE * math.log(M0 / m) - G * t, height=rocket.y)


@s.on_end
def report():
    t_burn = FUEL / MDOT
    print(f"burnout at {t_burn:.1f} s; the equation gives v = {VE * math.log(M0 / (M0 - FUEL)) - G * t_burn:.2f} m/s then (the table has the measured speed)")


s.run(6)

table forces from a script changing mass