I’ll create an astronomy example problem involving Kepler’s Third Law of planetary motion and solve it using $Python$.
We’ll calculate and visualize orbital periods of planets based on their distances from the Sun.
1 | import numpy as np |
Let me explain the astronomical problem and solution:
Problem:
According to Kepler’s Third Law of planetary motion, the square of a planet’s orbital period ($T$) is proportional to the cube of its semi-major axis ($a$).
We can write this as: $T² = k * a³$, where $k$ is a constant. When using $AU$ (Astronomical Units) for distance and Earth years for time, $k = 1$.
The code does the following:
- Defines a function to calculate orbital periods using Kepler’s Third Law
- Creates a dataset of real planets and their distances from the Sun in $AU$
- Calculates their orbital periods
- Creates two visualizations:
- A standard plot showing the relationship between distance and orbital period
- A log-log plot that demonstrates the power law relationship
- Prints a table of results
The visualizations show:
- Left plot:
The direct relationship between distance and orbital period, showing the curved nature of the relationship - Right plot:
The log-log plot, which shows a straight line with a slope of $3/2$, confirming Kepler’s Third Law

Calculated Orbital Periods:
Calculated Orbital Periods:
Planet Distance (AU) Period (Years)
Mercury 0.387 0.24
Venus 0.723 0.61
Earth 1.000 1.00
Mars 1.524 1.88
Jupiter 5.203 11.87
Saturn 9.537 29.45
Uranus 19.191 84.07
Neptune 30.069 164.88
From the results, you can see how the orbital period increases with distance. For example:
- Mercury ($0.387 AU$) takes about $0.24$ Earth years to orbit the Sun
- Mars ($1.524 AU$) takes about $1.88$ Earth years
- Neptune ($30.069 AU$) takes about $164.8$ Earth years
This demonstrates how outer planets take much longer to complete their orbits, following the mathematical relationship $T = √(a³)$.








