Skip to content

Instantly share code, notes, and snippets.

@randombenj
Last active August 29, 2015 13:58
Show Gist options
  • Save randombenj/10412297 to your computer and use it in GitHub Desktop.
Save randombenj/10412297 to your computer and use it in GitHub Desktop.
The rocket impulse problem: the rocket changes its mass to accelerate
# G acceleration of earth (m/s^2)
G_EARTH = 9.81
# How many times the iteration is repeated (s)
DELAY = 0.001
# Start mass of Rocket (kg)
START_MASS = 775000
# End mass of the Rocket (all fuel burnt) (kg)
END_MASS = 265143
# Velocity of the gas (relative to the rocket) (m/s)
V_REL = 3248
# Mass loss per second (burned fuel per second) (kg)
FUEL_LOSS = 3922
# Delta mass loss in flight (kg)
delta_mass = 0
# Velocity while flying (m/s)
velocity = 0
# Mass loss per delay time (iteration time) (kg)
fuel_loss_delay = FUEL_LOSS * DELAY
def get_endvelocity(delta_mass, velocity):
"""
Calculates the endvelocity of the rocket in a given timespan
:param delta_mass: the mass lost since start (burned gas)
:param velocity: the beginn veloity
"""
mass_beginn = START_MASS - delta_mass
g_force = mass_beginn * G_EARTH
endvelocity = \
(g_force * DELAY - fuel_loss_delay * V_REL + \
(fuel_loss_delay - mass_beginn) * velocity) \
/ (fuel_loss_delay - mass_beginn)
return endvelocity
# calculating the time iterative
while START_MASS - delta_mass > END_MASS:
print velocity
velocity = get_endvelocity(delta_mass, velocity)
delta_mass += fuel_loss_delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment