# Solutions for the Lane-Emden with n=0


```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)}$



Reemplazando n=0:


```python
lane_endem_eq_0 = lane_endem_eq.subs(n, 0)
lane_endem_eq_0
```




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




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




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




```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: 1, C2: 0}



$$C1= 1,  C2=0$$


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




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




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




    [-sqrt(6), sqrt(6)]




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


```python
n_xi = np.linspace(0, 10, 101)
n_theta = num_theta_f(n_xi)

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=0$")
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.show()
```


```python

```

5098f6696bc85846e51467c22b23577fa334aa21
ipynb
Jupyter Notebook
01_polytropic_index_0.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
01_polytropic_index_0.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
01_polytropic_index_0.ipynb
RcrdPhysics/Estructura-Estelar
23fe348ab0a49caf7f0c6c25c9bed4b669930d1e
MIT
Qwen/Qwen-72B
1. YES
2. YES