HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /A Kepler's equation solver
Space Science and AstronomyHardHigh School (11–12)Celestial Mechanics and Spaceflight

A Kepler's equation solver

You will write a solver for Kepler's equation and use it to find where a planet is at a given time.

The idea. M=E−esin⁡EM = E - e\sin EM=E−esinE, with angles in radians. Newton's method repeats E→E−(E−esin⁡E−M)/(1−ecos⁡E)E \to E - (E - e\sin E - M)/(1 - e\cos E)E→E−(E−esinE−M)/(1−ecosE). Then r=a(1−ecos⁡E)r = a(1 - e\cos E)r=a(1−ecosE). For the true anomaly, first work out

y=1+e sin⁡(E/2)\displaystyle y = \sqrt{1 + e}\,\sin(E/2)y=1+e​sin(E/2)
x=1−e cos⁡(E/2)\displaystyle x = \sqrt{1 - e}\,\cos(E/2)x=1−e​cos(E/2)

and then θ=2 atan2(y,x)\theta = 2\,\text{atan2}(y, x)θ=2atan2(y,x).

Your tasks.

  1. In solve_kepler, return EEE from MMM and eee. Start from E=ME = ME=M and take 303030 Newton steps.
  2. In distance, return rrr from aaa, eee and EEE.
  3. In true_anomaly, return θ\thetaθ in radians from eee and EEE.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, find where a comet with e=0.8e = 0.8e=0.8 is one tenth of a period after perihelion. Is it ahead of an even motion?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← Orbits from their two endsWhat kind of orbit is it? →
More onCelestial Mechanics and Spaceflight

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. Finding L1 by bisectionAdvanced
  2. A Hohmann transfer plannerHard
  3. An orbit step by stepAdvanced
  4. What kind of orbit is it?Hard
  5. Orbits from their two endsHard
All labs on this topic →