B1 · Lesson 54 · Project
Fly a satellite in Python and check Kepler's laws
Kepler found his three laws of planetary motion by poring over decades of observations; Newton showed they follow from one inverse-square force. In this project you'll get there a third way: write a simulator that steps a satellite forward under gravity alone, and then measure what it does. You'll check that it conserves energy and angular momentum, measure its period from the simulated path, and compare with the formula that mission planners use to put satellites where they belong.
- A satellite starts 7000 km from Earth's center (about 630 km up) moving sideways at . The curve is its orbit, with Earth drawn to scale.
- At about 7.55 km/s the orbit is a circle. Faster, it stretches into an ellipse with Earth at one focus; the far point climbs quickly.
- Near 10.7 km/s the ellipse opens into an escape path. The readouts give the orbit's size and period.
Predict
A satellite at 7000 km from Earth's center moves at 8.0 km/s, a little faster than circular speed. Compared with the circular orbit's 97 minutes, its period is:
Longer, about 118 minutes. The extra speed lifts the far side of the orbit to about 9000 km from Earth's center, so the semi-major axis grows from 7000 km to 7990 km, and by Kepler's third law the period grows as . Moving faster at the start makes the trip longer, because the orbit gets bigger.
Name it
Kepler's laws, from Newton
- Orbits are ellipses with the planet's center at one focus (or, above escape speed, open curves).
- The line from the planet to the satellite sweeps equal areas in equal times: the satellite's angular momentum is conserved, because gravity pulls along and exerts no torque.
- : , where , the semi-major axis, is half the longest diameter of the ellipse.
Energy and the vis-viva equation
The orbit's total energy per unit mass depends only on its size:
So a launch speed at radius fixes , and with it the period. Launched sideways at the closest point (perigee), the farthest point (apogee) is at . For Earth, km³/s².
The simulation
The state is position and velocity ; the acceleration is . RK4 (lesson 52) with a 10 s step over a 100-minute orbit holds the energy constant to about one part in . Conserved quantities are the best test of an orbit code: any bug or too-large step shows up as energy drifting.
Worked example
A satellite at 7000 km from Earth's center moves sideways at 8.0 km/s. Find the semi-major axis, the apogee altitude and the period.
Show the solution
- Semi-major axis, from vis-viva. so km.
- Apogee. The apogee radius is which is 2610 km above the surface.
- Period. which is 118.5 min.
- Check with the simulation. A simulation with 10 s steps measures 7108.07 s, matching to 0.01 s.
Answer km, the apogee is 2610 km up, and the period is 7108 s (118.5 min).
Worked example
What speed puts a satellite at 7000 km into a circular orbit, and what speed lets it escape?
Show the solution
- Circular speed. with a period of 5829 s (97.1 min).
- Escape speed.
- In between. Between them the orbits are ellipses, growing without limit as the speed nears escape.
Answer 7.55 km/s gives a circular orbit, and 10.67 km/s lets the satellite escape.
Check
Step 1. Write gravity(r) returning the acceleration for a position r (a NumPy array, in km), with GM = 398600.4 km³/s².
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write orbit(r0, v0, dt, n) that steps n times with RK4 and returns two (n + 1) × 2 arrays, the positions and velocities, starting with the initial state. gravity is included.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write period(rs, dt) that finds the times when the orbit crosses the positive axis going upward ( changes from negative to non-negative while ), interpolating within the step, and returns the time between the first two crossings. orbit is included.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. A satellite at 7000 km from Earth's center moves sideways at 8.5 km/s. Using the vis-viva equation, how high above the surface (radius 6371 km) is its apogee?
Write units the way you normally would: 1.5 km and 1500 m are the same answer.
Explain why
Why is energy conservation a good test of an orbit simulation?
Gravity is a conservative force, so the true orbit keeps its total energy exactly constant. A numerical method only approximates each step, and its errors usually show up as a slow drift in energy: the orbit spirals in or out. Watching the energy is cheap, needs no exact solution to compare against, and catches most bugs and steps that are too large. A drift of one part in over an orbit means the method is tracking the physics closely; a drift of a percent means the results can't be trusted.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.