A simulation advances a model through small time steps rather than trying to solve a complex system with one equation. For a rocket, each step changes the propellant remaining in its tank and recalculates how the rocket moves. section 8.7 section 8.8
Listing 8.16 Updating the propellant mass after Δt time has elapsed
function update!(r::StagedRocket, t::Number, Δt::Number)
mflow = mass_flow(thrust(r), Isp(r.engine))
consume!(r.tank, mflow * Δt)
end
# Payload has no tanks with propellant to consume
update!(r::Payload, t::Number, Δt::Number) = nothing
The rocket’s update! method computes propellant use from thrust and specific impulse, then consumes the amount used during Δt. A payload needs no such update because it has no propellant tank. section 8.7
Listing 8.19 Simulating a rocket launch and determining the maximum altitude of the rocket
function launch!(rocket::Rocket, Δt::Real)
g = 9.80665 # acceleration caused by gravity
v = 0.0 # velocity
h = 0.0 # altitude (height)
for t in 0:Δt:1000 #1
m = mass(rocket) #2
F = thrust(rocket) - m*g
remaining = update!(rocket, t, Δt)
# Any propellant and thrust left?
if remaining == 0 || F <= 0
return (t, h) #3
end
h += v*Δt #4
a = F/m
v += a*Δt
end
end
The launch loop calculates mass and net force, updates propellant, and advances altitude and velocity using Δt. It returns the elapsed time and altitude when propellant is exhausted or thrust cannot overcome gravity. section 8.8
Try a launch
With a 300-unit payload, a small tank, and a Rutherford engine, launch!(rocket, 0.5) returns approximately (45.0, 31117.8): 45 seconds and 31 kilometers of altitude. The tank is empty afterward. Try changing the payload or tank size; a larger tank need not produce a higher result, because its mass also increases gravity’s pull. section 8.8
The model has boundaries: it omits air resistance and cannot simulate stage transitions, even though rockets with multiple stages can be constructed. Its result therefore describes this simplified launch, not a full real-world flight. section 8.7 section 8.8





