-
Notifications
You must be signed in to change notification settings - Fork 0
/
NR.py
34 lines (25 loc) · 850 Bytes
/
NR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
###################################################################################
## IMPORTS
import numpy as np
import sympy
###################################################################################
## NEWTON_RAPHSON METHOD FOR KEPLER'S EQ
"""
Newton-Raphson method for numerically
solving the Kepler equation
"""
def new_rap(n, M, e):
E = sympy.symbols('E')
f = E-e*sympy.sin(E)-M
# derivative, analytically done
fprim = 1-e*sympy.cos(E)
# good first-value is M
# due to Taylor-expansion of sine
En = M
for _ in range(n):
En = En - np.float(f.evalf(subs= {E:En})) / np.float(fprim.evalf(subs= {E:En}))
return En
###################################################################################
## RUN CODE
if __name__ == "__main__":
i = new_rap(2, 3, 2)