A lightweight Python simulation of a model rocket’s vertical (1D) flight from launch to apogee. It uses a tabulated motor thrust curve, accounts for propellant mass loss and quadratic aerodynamic drag, and integrates the equations of motion with a 4th-order Runge-Kutta (RK4) solver.
np.trapezoid, which does not exist in older versions; on NumPy 1.x, replace it with np.trapz)pip install numpy matplotlib
python rocket_sim.py
(Replace rocket_sim.py with whatever you named the file.)
The script prints a summary to the console and writes rocket_flight.png to the working directory.
Burnout time: ...
Max velocity: ...
Apogee height: ...
Time to apogee: ...
Total impulse: ...
Edit the constants near the top of the script.
| Parameter | Default | Units | Description |
|---|---|---|---|
MASS_EMPTY |
0.030 | kg | Rocket structure plus motor casing, no propellant |
MASS_PROPELLANT |
0.015 | kg | Propellant burned during flight |
DRAG_COEFFICIENT |
0.75 | – | Drag coefficient (Cd) |
FRONTAL_AREA |
0.0015 | m² | Cross-sectional area of the rocket |
AIR_DENSITY |
1.225 | kg/m³ | Air density at sea level |
G |
9.81 | m/s² | Gravitational acceleration |
DT |
0.01 | s | Integration time step |
THRUST_CURVE is an array of [time (s), thrust (N)] pairs. Replace it with data for your motor (manufacturer data sheets and the ThrustCurve.org database list these). The first point should be at t = 0 and the last point should have zero thrust, since the last time value is treated as burn time.
State: [height, velocity]
Forces:
F_net = F_thrust(t) - F_drag(v) - m(t) * g
F_drag = 0.5 * rho * v * |v| * Cd * A
a = F_net / m(t)
Mass model: Propellant is assumed to burn in proportion to the impulse delivered so far:
m(t) = m_empty + m_propellant * (1 - cumulative_impulse(t) / total_impulse)
Integration: Each step of size DT uses classic RK4 on d/dt [h, v] = [v, a(t, v)].
Stopping condition: The simulation ends at apogee, defined as the first time after burnout when velocity drops to zero or below. There is also a 60 s safety cutoff.
rocket_flight.png contains four stacked plots sharing a time axis:
A dashed green line marks motor burnout on each plot.
.eng filesThis project is licensed under the MIT License.