# Solutions for the Lane-Emden with n=1


```python
from distutils.spawn import find_executable

import matplotlib.pyplot as plt
import numpy as np

import seaborn

rem = 12

seaborn.set(context='notebook', style='darkgrid')

plt.ioff()

plt.rc('lines', linewidth=1)
plt.rc('font', family='serif')
plt.rc('font', size=rem)
plt.rc('axes', titlepad=1.500*rem)
plt.rc('axes', titlesize=1.728*rem)
plt.rc('axes', labelsize=1.200*rem)
plt.rc('legend', fontsize=1.000*rem)
plt.rc('xtick', labelsize=0.833*rem)
plt.rc('ytick', labelsize=0.833*rem)

if find_executable('latex'):
    plt.rc('text', usetex=True)

material_palette = {
    -1: "#212121",
    0: "#F44336",
    1: "#E91E63",
    2: "#9C27B0",
    3: "#673AB7",
    4: "#3F51B5",
    5: "#2196F3",
    6: "#03A9F4",
    7: "#00BCD4",
    8: "#009688",
    9: "#4CAF50",
    10: "#8BC34A",
    11: "#CDDC39",
    12: "#FFEB3B",
    13: "#FFC107",
    14: "#FF9800",
    15: "#FF5722",
}
```


```python
%matplotlib inline
```


```python
from sympy import (
    Eq as Equation,
    Derivative,
    Function,
    Symbol,
    lambdify,
    simplify,
    symbols,
    dsolve,
    solve,
)
```


```python
n = Symbol("n")
xi = Symbol("xi")
theta = Function("theta")
```


```python
lhs = simplify((1 / xi ** 2) * Derivative((xi ** 2) * Derivative(theta(xi), xi), xi).doit())
lhs
```




$\displaystyle \frac{d^{2}}{d \xi^{2}} \theta{\left(\xi \right)} + \frac{2 \frac{d}{d \xi} \theta{\left(\xi \right)}}{\xi}$




```python
rhs = -theta(xi) ** n
rhs
```




$\displaystyle - \theta^{n}{\left(\xi \right)}$




```python
lane_endem_eq = Equation(lhs, rhs)
lane_endem_eq
```




$\displaystyle \frac{d^{2}}{d \xi^{2}} \theta{\left(\xi \right)} + \frac{2 \frac{d}{d \xi} \theta{\left(\xi \right)}}{\xi} = - \theta^{n}{\left(\xi \right)}$



Reemplazamos n=1:


```python
lane_endem_eq_1 = lane_endem_eq.subs(n, 1)
lane_endem_eq_1
```




$\displaystyle \frac{d^{2}}{d \xi^{2}} \theta{\left(\xi \right)} + \frac{2 \frac{d}{d \xi} \theta{\left(\xi \right)}}{\xi} = - \theta{\left(\xi \right)}$




```python
solution = dsolve(lane_endem_eq_1, theta(xi))
solution
```




$\displaystyle \theta{\left(\xi \right)} = \frac{C_{1} J_{\frac{1}{2}}\left(\xi\right) + C_{2} Y_{\frac{1}{2}}\left(\xi\right)}{\sqrt{\xi}}$




```python
constants = solve(
    [
        simplify(xi * solution.rhs).subs(xi, 0),
        Derivative(simplify(xi * solution.rhs), xi).doit().subs(xi, 0) - 1,
    ],
    symbols('C1 C2'),
)
constants
```




    {C1: sqrt(2)*sqrt(pi)/2, C2: 0}



$$ C1=\frac{\sqrt{2 \pi}}{2}, C2=0$$


```python
solution = solution.subs(constants)
solution
```




$\displaystyle \theta{\left(\xi \right)} = \frac{\sqrt{2} \sqrt{\pi} J_{\frac{1}{2}}\left(\xi\right)}{2 \sqrt{\xi}}$




```python
solution = solution.simplify()
solution
```




$\displaystyle \theta{\left(\xi \right)} = \frac{\sin{\left(\xi \right)}}{\xi}$




```python
theta_zeros = solve(solution.rhs, xi)
theta_zeros
```




    [pi]




```python
num_theta_f = lambdify(xi, solution.rhs, "numpy")
```


```python
n_xi = np.linspace(0, 10, 101)
n_theta = np.ones(n_xi.shape)
n_theta[1:] = num_theta_f(n_xi[1:])

fig = plt.figure(figsize=(11.25, 4.5), frameon=False)
axs = fig.add_subplot(1, 1, 1)

axs.plot(
    n_xi, 
    n_theta, 
    color=material_palette[1],
    label=r"$\theta_0(\xi)$"
)
axs.legend()
axs.set_title(r"Solution for Lane-Endem equation for $n=1$")
axs.set_xlim([0, 10])
axs.set_xlabel(r"$\xi$")
axs.set_ylim([-2, 2])
axs.set_ylabel(r"$\theta_0(\xi)$")
plt.tight_layout()

plt.savefig('LE_n1')
plt.show()
```


```python
from IPython.display import Image
Image(filename='LE_n1.png')
```

# GRACIAS

ae2e51ee6a0abd61a929994d8e4fe8120aacaba6
ipynb
Jupyter Notebook
02_polytropic_index_1.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
02_polytropic_index_1.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
02_polytropic_index_1.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
Qwen/Qwen-72B
1. YES
2. YES