<jupyter_start><jupyter_text>Lagrange's work on Kepler equation suggests that an equation of the form \begin{equation}y=x+\alpha \phi(y)\end{equation}Its solution is approximated by the series expansion:\begin{equation}y=x+\sum_{n=1}^{\infty} \frac{\alpha^{n}}{n !} \frac{d^{n-1}}{d x^{n-1}} \phi(x)^{n}\end{equation}<jupyter_code>import numpy as np  # calculations
import pathlib  # needed to create folder
import matplotlib.pyplot as plt  # needed for graphs
import sympy as sp
from sympy.abc import E, e, n, M, o<jupyter_output><empty_output><jupyter_text>Kepler's equation is \begin{equation}E=M+e \sin E\end{equation}Its solution is approximated by the series expansion:\begin{equation}y=M+\sum_{n=1}^{\infty} \frac{e^{n}}{n !} \frac{d^{n-1}}{d E^{n-1}} \sin(M)^{n}\end{equation}We plan to evaluate the series expression E(M) up to order n=3 and n=10 for eccentrities e=0.3 and e=0.9. We're using python's package Sympy to do our symbolic interpretation.From sympy.abc we're importing these symbols. Their usage is:E = Eccentric anomaly of Kepler's EquationM = Mean Anomaly of Kepler's Equatione = Eccentricityn = index of summationo = upper bound of summationSome starting setup<jupyter_code>dpisiz=100
def savim(dir,name):
    path = pathlib.Path(f"./{dir}")
    path.mkdir(exist_ok=True,parents=True)
    plt.savefig(f'./{dir}/{name}.png',dpi=dpisiz)
fract = e ** n / sp.factorial(n)
func = (sp.sin(M)) ** n
dif_func = (sp.Derivative(func, (M, n - 1)))
sumo = sp.Sum(fract * dif_func, (n, 1, o))
sum3 = (sumo.subs(o, 3)).doit() #The form asked for n=3. Could add .simplify() as well
sum10 = (sumo.subs(o, 10)).doit() #The form asked for n=3. Could add .simplify() as well
E3 = sum3 + M
E10 = sum10 + M
En3_e3 = sp.trigsimp(E3.subs(e, 0.3))
En10_e3 = sp.trigsimp(E10.subs(e, 0.3))
En3_e9 = sp.trigsimp(E3.subs(e, 0.9))
En10_e9 = sp.trigsimp(E10.subs(e, 0.9))<jupyter_output><empty_output><jupyter_text>Use sp.lambdify to create our lambda functions and plot our graphs.Could have used sp.plot but I prefer having more options with matplotlib.<jupyter_code>numberoftries = 10000
xx = np.linspace(0, 2 * np.pi, 10000)
En3_e3f = sp.lambdify(M, En3_e3)(xx)
En10_e3f = sp.lambdify(M, En10_e3)(xx)
En3_e9f = sp.lambdify(M, En3_e9)(xx)
En10_e9f = sp.lambdify(M, En10_e9)(xx)

fig = plt.figure()
ax = plt.axes()


data = np.genfromtxt(fname="data.csv", delimiter=',') #Importing data from task 1
ax.set_ylabel('E')
ax.set_xlabel('M')
ax.plot(data[:, 0], data[:, 2], label='E for e=0.3', color='tab:pink')
ax.plot(xx, En3_e3f, label='E for n=3, e=0.3', linestyle='dashed', color='tab:red')
ax.plot(xx, En10_e3f, label='E for n=10, e=0.3', linestyle='dotted', color='tab:blue')
ax.legend()
savim('pr1_task2','e_03')
fig1 = plt.figure()
ax1 = plt.axes()
ax1.plot(data[:, 0], data[:, 5], label='E for e=0.9', color='black' )
ax1.plot(xx, En3_e9f, label='E for n=3, e=0.9', color='tan')
ax1.plot(xx, En10_e9f, label='E for n=10, e=0.9', color='fuchsia')
ax1.legend()
ax1.set_ylabel('E')
ax1.set_xlabel('M')
savim('pr1_task2','e_09')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17866492146596857, 'fraction_numerical': 0.044829842931937175, 'mean_word_length': 5.546038543897216, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '642395', 'license': 'MIT', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1265, 'n_words': 303, 'path': 'Project 1/Project1_Task2.ipynb', 'repo_name': 'od1sm/CoPh', 'size': '3056'}