---
title: Energy and momentum lab
heading: Conservation laws as tools for checking simulations, rockets, bounces and crashes
eyebrow: B1 · Lesson 25 · Energy and momentum lab
xp: 50
---

::: hook
Conservation laws do two jobs in engineering. They solve problems directly, as in lessons 15 to 24, and they audit simulations: a simulated pendulum that gains energy, or a crash that creates momentum, has a bug or a bad method. In this lab you'll watch Euler's method pump energy into a pendulum and fix it with a one-line change, fly a rocket against gravity, sum an infinite series of bounces, integrate work from force data, and reconstruct a crash.
:::

::: play
- A gently swinging 1 m pendulum ($\omega^2 = 9.8$ s⁻²) is stepped forward in time by two methods. The curves are each method's energy error, as a fraction of the starting energy, against time.
- Plain Euler updates position and velocity from the old values, and its energy climbs steadily, by a factor $1 + \omega^2h^2$ every step. **Symplectic Euler** uses the new velocity to update the position, and its energy just wobbles, by $\frac{h\omega}{2}$ either way.
- Change the step: explicit Euler's growth shrinks with h but never stops, while the symplectic wobble stays bounded however long it runs.
:::

```sim plot
view: graph
x: t = 0..10 s
y: E = -0.05..1.5
slider: h = 0.001..0.02 step 0.001 = 0.01 s
plot: (1 + 9.8*h^2)^(t/h) - 1 | label: explicit Euler, small-swing growth | samples: 400
plot: -(h*sqrt(9.8)/2)*sin(2*sqrt(9.8)*t) | label: symplectic Euler, bounded wobble | color: ch2 | samples: 800
readout: energy gain after 10 s, explicit = (1 + 9.8*h^2)^(10/h) - 1 | digits: 3
readout: symplectic wobble, percent = h*sqrt(9.8)/2*100 | digits: 3
```

::: predict
## A lively ball dropped from 1 m bounces with coefficient of restitution 0.9. In theory it bounces infinitely many times. How long until it stops?

- [ ] Forever
- [x] About 8.6 s
- [ ] About 0.45 s, the time of the first fall
- [ ] It can't be calculated

::: reveal
About 8.6 s. Each bounce's height is $e^2$ times the last, so each flight time is e times the last, and the times form a geometric series with a finite sum: $\sqrt{2h/g}\,\frac{1 + e}{1 - e} = 0.452 \times 19 = 8.58$ s. Infinitely many bounces fit into a finite time, which is also why a bouncing ball's sound speeds up to a buzz just before it stops. Along the way it travels $h\frac{1 + e^2}{1 - e^2} = 9.53$ m up and down.
:::
:::

::: nameit
## Energy as a test

For a conservative system the total energy must stay constant. Explicit Euler applied to an oscillator multiplies the energy by $1 + \omega^2h^2$ every step, so it always grows. **Symplectic (semi-implicit) Euler** updates the velocity first and then uses the new velocity for the position:

$$v_{n+1} = v_n + h\,a(x_n), \qquad x_{n+1} = x_n + h\,v_{n+1}.$$

It conserves a slightly altered energy exactly, so the true energy only oscillates by a small amount, of order h, forever. Orbit and molecular simulations use methods like this for long runs.

## Rockets against gravity

A rocket climbing vertically gains $\Delta v = v_e\ln\frac{m_0}{m_f} - gt_b$: the **gravity loss** $gt_b$ is why rockets burn hard and fast at launch.

## Bounces

With restitution e, the flight times form a geometric series, totaling $\sqrt{\frac{2h}{g}}\cdot\frac{1 + e}{1 - e}$, and the distance traveled up and down totals $h\frac{1 + e^2}{1 - e^2}$.

## Work from data

When force is measured at points rather than given as a formula, the trapezoid rule $W \approx \sum\frac{F_i + F_{i+1}}{2}\Delta x$ gives the work, accurate to order $\Delta x^2$.
:::

::: example
## A 1000 kg rocket with 600 kg of propellant burns it at 10 kg/s with exhaust speed 2500 m/s, climbing vertically. What speed does it reach at burnout?

::: solution
1. **Burn time.** 600 kg at 10 kg/s lasts 60 s.
2. **Without gravity.**
   $$\begin{aligned} \Delta v &= 2500\ln\frac{1000}{400} \\ &= 2291\ \text{m/s} \end{aligned}$$
3. **Gravity loss.** Gravity takes $9.8 \times 60 = 588$ m/s, leaving
   $$2291 - 588 = 1703\ \text{m/s}$$
4. **A faster burn.** A rocket with the same propellant burned in 30 s would lose only 294 m/s. That's why launchers have thrust-to-weight ratios well above 1: the thrust here, 25 kN against a 9.8 kN weight, is 2.55 times the starting weight.

**Answer:** the rocket reaches 1703 m/s at burnout.
:::
:::

::: example
## Explicit Euler steps a pendulum (g/L = 9.8 s⁻²) with h = 0.01 s. By how much does its small-swing energy grow per second?

::: solution
1. **Growth per step.** Each step multiplies the energy by
   $$\begin{aligned} 1 + \omega^2h^2 &= 1 + 9.8 \times 10^{-4} \\ &= 1.00098 \end{aligned}$$
2. **Growth per second.** Over 100 steps that's
   $$1.00098^{100} = 1.103$$
   10% per second.
3. **Over longer runs.** After 10 s a gentle swing's energy has grown by a factor of 2.66. A pendulum released at 1 rad swings more slowly, so its energy grows a little less, by 2.13 times in 10 s, but after 27 s it has gained enough to go over the top.
4. **Symplectic Euler.** With the same step, its swing energy stays within 1.5% of the starting value for as long as you run it.

**Answer:** the energy grows by a factor of 1.103 each second, about 10%.
:::
:::

::: example
## A 1500 kg car going east at 20 m/s and a 3000 kg truck going north at 10 m/s lock together. What does a reconstruction give?

::: solution
1. **Momentum.** The car brings 30 000 kg·m/s east and the truck 30 000 kg·m/s north:
   $$\vec p = (30\,000,\ 30\,000)\ \text{kg·m/s}$$
2. **Wreck velocity.** Divide by 4500 kg: $(6.67, 6.67)$ m/s, which is 9.43 m/s at 45°.
3. **Energy absorbed.** Kinetic energy before is 450 kJ and after 200 kJ, so 250 kJ was absorbed.
4. **Working backward.** Investigators get the wreck's velocity from the skid direction and length after the crash, and the speeds before it from momentum, which settles who was speeding.

**Answer:** the wreck moves off at 9.43 m/s, 45° north of east, and the crash absorbed 250 kJ.
:::
:::

::: check
kind: python

## Step 1. Write `swing(theta0, h, n, symplectic)` that steps a pendulum with $\ddot\theta = -9.8\sin\theta$ from rest at `theta0` for n steps of size h, using explicit Euler or symplectic Euler, and returns the final energy $\frac12\omega^2 - 9.8\cos\theta$.

```python starter
import math

def swing(theta0, h, n, symplectic):
    return -9.8 * math.cos(theta0)

print(swing(1.0, 0.01, 10000, False), swing(1.0, 0.01, 10000, True))
```

```python solution
import math

def swing(theta0, h, n, symplectic):
    th, w = theta0, 0.0
    for _ in range(n):
        if symplectic:
            w -= h * 9.8 * math.sin(th)
            th += h * w
        else:
            th, w = th + h * w, w - h * 9.8 * math.sin(th)
    return 0.5 * w**2 - 9.8 * math.cos(th)

print(swing(1.0, 0.01, 10000, False), swing(1.0, 0.01, 10000, True))
```

```python tests
import math
E0 = -9.8 * math.cos(1.0)
Ee = swing(1.0, 0.01, 10000, False)
Es = swing(1.0, 0.01, 10000, True)
assert Ee > 9.8, f"Explicit Euler should pump the energy above the top's 9.8 J/kg within 100 s; got {Ee:.3f}."
Eb = 9.8 * (1 - math.cos(1.0))
assert abs((Es + 9.8) - Eb) / Eb < 0.02, f"Symplectic Euler's swing energy should stay within 2% of {Eb:.4f} J/kg; got {Es + 9.8:.4f}."
assert abs(Ee - 43.95) < 0.05, f"Explicit Euler ends near 43.95 J/kg; got {Ee:.3f}."
```

::: right
Right. One reordered line turns an energy pump into a method whose energy wobbles by at most 1.5%, for 10 000 steps or a million.
:::
:::

::: check
kind: python

## Step 2. Write `burnout_speed(m0, mf, ve, mdot, h)` that steps a vertical rocket's speed with Euler's method, $\dot v = \frac{v_e\dot m}{m} - 9.8$, while its mass falls from m0 to mf, and returns the speed at burnout.

```python starter
import math

def burnout_speed(m0, mf, ve, mdot, h):
    return ve * math.log(m0 / mf)

print(burnout_speed(1000, 400, 2500, 10, 0.01))
```

```python solution
import math

def burnout_speed(m0, mf, ve, mdot, h):
    m, v = m0, 0.0
    while m > mf + 1e-9:
        v += h * (ve * mdot / m - 9.8)
        m -= mdot * h
    return v

print(burnout_speed(1000, 400, 2500, 10, 0.01))
```

```python tests
import math
v = burnout_speed(1000, 400, 2500, 10, 0.01)
exact = 2500 * math.log(2.5) - 9.8 * 60
assert abs(v - exact) < 1.0, f"Expect about {exact:.1f} m/s (Tsiolkovsky minus the gravity loss); got {v:.2f}."
v2 = burnout_speed(1000, 400, 2500, 20, 0.005)
assert abs(v2 - (2500 * math.log(2.5) - 9.8 * 30)) < 1.0, f"Burning twice as fast loses only 294 m/s to gravity; got {v2:.2f}."
```

::: right
Right. The simulation lands within 0.2 m/s of $v_e\ln\frac{m_0}{m_f} - gt_b$, and the gap shrinks with the step.
:::
:::

::: check
kind: python

## Step 3. Write `bounce_time(h, e)` that adds up the first fall and the flight times of 200 bounces, each rising to $e^2$ times the previous height, and returns the total.

```python starter
import math

def bounce_time(h, e):
    return math.sqrt(2 * h / 9.8)

print(bounce_time(2, 0.8))
```

```python solution
import math

def bounce_time(h, e):
    total = math.sqrt(2 * h / 9.8)
    for _ in range(200):
        h *= e * e
        total += 2 * math.sqrt(2 * h / 9.8)
    return total

print(bounce_time(2, 0.8))
```

```python tests
import math
for h, e in ((2, 0.8), (1, 0.5), (0.5, 0.9)):
    closed = math.sqrt(2 * h / 9.8) * (1 + e) / (1 - e)
    got = bounce_time(h, e)
    assert abs(got - closed) < 1e-6, f"For h = {h} and e = {e} the series sums to {closed:.6f} s; got {got:.6f}."
```

::: right
Right. 200 terms reach the closed form, $\sqrt{2h/g}\,\frac{1 + e}{1 - e}$, to many digits.
:::
:::

::: check
kind: python

## Step 4. Write `work(x, F)` that integrates force samples `F` at positions `x` (NumPy arrays, not necessarily evenly spaced) by the trapezoid rule.

```python starter
import numpy as np

def work(x, F):
    return float(np.sum(F) * (x[1] - x[0]))

x = np.linspace(0, 2, 21)
print(work(x, 5 * x**2))
```

```python solution
import numpy as np

def work(x, F):
    return float(np.sum((F[1:] + F[:-1]) / 2 * np.diff(x)))

x = np.linspace(0, 2, 21)
print(work(x, 5 * x**2))
```

```python tests
import numpy as np
x = np.linspace(0, 2, 20001)
assert abs(work(x, 5 * x**2) - 40 / 3) < 1e-6, f"∫5x² dx from 0 to 2 is 13.333 J; got {work(x, 5 * x**2)}."
xs = np.array([0.0, 0.1, 0.3, 0.6, 1.0])
Fs = np.array([0.0, 2.0, 4.0, 4.0, 1.0])
assert abs(work(xs, Fs) - 2.9) < 1e-12, f"For the uneven samples the trapezoids sum to 2.9 J; got {work(xs, Fs)}."
x3 = np.linspace(0, 1, 11)
assert abs(work(x3, 3 + 0 * x3) - 3.0) < 1e-12, "A constant 3 N over 1 m does 3 J."
```

::: right
Right. Using each interval's own width handles uneven samples, which is how measured force–distance data usually arrives.
:::
:::

::: check
kind: python

## Step 5. Write `stick(m1, v1, m2, v2)` for two bodies that lock together; v1 and v2 are 2D velocity lists. Return the common velocity (a NumPy array) and the kinetic energy lost.

```python starter
import numpy as np

def stick(m1, v1, m2, v2):
    return np.array(v1, float), 0.0

print(stick(1500, [20, 0], 3000, [0, 10]))
```

```python solution
import numpy as np

def stick(m1, v1, m2, v2):
    v1, v2 = np.asarray(v1, float), np.asarray(v2, float)
    v = (m1 * v1 + m2 * v2) / (m1 + m2)
    lost = 0.5 * m1 * v1 @ v1 + 0.5 * m2 * v2 @ v2 - 0.5 * (m1 + m2) * v @ v
    return v, lost

print(stick(1500, [20, 0], 3000, [0, 10]))
```

```python tests
import numpy as np
v, L = stick(1500, [20, 0], 3000, [0, 10])
assert np.allclose(v, [20 / 3, 20 / 3]), f"The wreck moves at (6.67, 6.67) m/s; got {v}."
assert abs(L - 250000) < 1e-6, f"The crash absorbs 250 kJ; got {L}."
v, L = stick(2, [3, 0], 1, [0, 0])
assert np.allclose(v, [2, 0]) and abs(L - 3) < 1e-12, f"2 kg at 3 m/s sticking to 1 kg: 2 m/s and 3 J lost; got {v} and {L}."
mu = 2 * 5 / 7
v, L = stick(2, [1, 2], 5, [-1, 0])
assert abs(L - 0.5 * mu * 8) < 1e-12, "The loss always equals ½μ|v1 - v2|²."
```

::: right
Right. The loss always equals $\frac12\mu|\mathbf v_1 - \mathbf v_2|^2$, the internal energy of lesson 24.
:::
:::

::: check
kind: parts
given: m0 = 500 | 2000; f = 0.5 | 0.7; ve = 2500 | 3000; tb = 60 | 120

## A rocket of {m0} kg, of which a fraction {f} is propellant, burns for {tb} s with exhaust speed {ve} m/s, climbing vertically.

::: part
answer: ve*ln(1/(1 - f))
unit: m/s
tolerance: 0.5%

### What Δv would it gain without gravity?

::: misses
- [ve*f] The rocket equation is logarithmic.
- [any] $v_e\ln\frac{m_0}{m_f}$ with $m_f = (1 - f)m_0$.
:::
:::

::: part
answer: ve*ln(1/(1 - f)) - 9.8*tb
unit: m/s
tolerance: 0.5%

### What speed does it actually reach at burnout?

::: misses
- [any] Subtract the gravity loss $gt_b$.
:::
:::
:::

::: check
given: h = 1 | 2 | 5; e = 0.5 | 0.7 | 0.9
answer: h*(1 + e^2)/(1 - e^2)
unit: m
tolerance: 0.5%

## A ball dropped from {h} m bounces with restitution {e}. What total distance does it travel, up and down, before it stops?

::: right
Right. $h + 2h\frac{e^2}{1 - e^2} = h\frac{1 + e^2}{1 - e^2}$.
:::

::: misses
- [h/(1 - e^2)] Count each bounce twice: up and down.
- [any] Heights form a geometric series with ratio $e^2$.
:::
:::

::: check
given: w = 2 | 3.13 | 6; h = 0.01 | 0.02
answer: ((1 + w^2*h^2)^(1/h) - 1)*100
unit: %
tolerance: 0.5%

## Explicit Euler steps an oscillator of angular frequency {w} rad/s with step {h} s. By what percentage does its energy grow in one second?

::: right
Right. $(1 + \omega^2h^2)^{1/h}$: the growth is never zero, only small.
:::

::: misses
- [w^2*h^2*100] That's one step; compound it over $1/h$ steps.
- [any] Each step multiplies the energy by $1 + \omega^2h^2$.
:::
:::

::: explain
## Why is checking energy conservation a good way to test a simulation of a frictionless system?

::: model
In a frictionless system the total energy can't change, and that's true no matter how complicated the motion is. Computing the energy at each step costs almost nothing, and any drift shows that something is wrong: a bug in the forces, a step that's too large, or a method like explicit Euler that adds energy every step. A trajectory can look plausible for a long time while drifting, but the energy reveals it at once. Momentum plays the same role for isolated systems of interacting bodies. Conservation doesn't prove a simulation right, since some errors conserve energy, but violating it proves one wrong.
:::
:::

::: practice

::: check
given: h = 0.5 | 3; e = 0.6 | 0.85
answer: sqrt(2*h/9.8)*(1 + e)/(1 - e)
unit: s
tolerance: 0.5%

## Total bouncing time from {h} m with e = {e}?

::: misses
- [any] $\sqrt{2h/g}\,\frac{1 + e}{1 - e}$.
:::
:::

::: check
given: m1 = 800 | 1200; v1 = 15 | 25; m2 = 1500 | 2500; v2 = 8 | 12
answer: 0.5*m1*m2/(m1 + m2)*(v1^2 + v2^2)/1000
unit: kJ
tolerance: 0.5%

## Energy absorbed when {m1} kg at {v1} m/s east hits {m2} kg at {v2} m/s north and they stick?

::: misses
- [any] $\frac12\mu|\mathbf v_1 - \mathbf v_2|^2$.
:::
:::
:::
