Skip to content

Instantly share code, notes, and snippets.

@j-faria
Last active February 27, 2019 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-faria/795967193c7dfaefb03e9d77febec35c to your computer and use it in GitHub Desktop.
Save j-faria/795967193c7dfaefb03e9d77febec35c to your computer and use it in GitHub Desktop.
How to solve Kepler's equation with sympy
from sympy import symbols, sin, nsolve
E = symbols('E')
def eccentric_anomaly(M, ecc, prec=15):
return nsolve(E - e*sin(E) - M, M, prec=prec)
import mpmath as mp
M = 2 * mp.pi * mp.rand()
M # mpf('1.6579367008579697')
e = 0.2
eccentric_anomaly(M, e) # 1.85018172211042
eccentric_anomaly(M, e, prec=30) # 1.85018172211042010599543511036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment