In-Class Assignment 2#
Credit: These exercises follow from work by Mike Zingale’s computational lectures.
We will be picking up from ICA1. These exercises require the solutions from ICA1 and are included here.
from sympy import init_session
init_session(use_latex="mathjax")
%matplotlib inline
IPython console for SymPy 1.13.3 (Python 3.11.8-64-bit) (ground types: python)
These commands were executed:
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()
Documentation can be found at https://docs.sympy.org/1.13.3/
1. stellar model#
rho = symbols('rho', cls=Function)
rhoc = symbols('rho_c')
qc = symbols('q_c')
Pc = symbols('P_c')
G = symbols('G')
Mstar, Rstar = symbols('M_\star R_\star')
r = symbols('r')
xi = symbols('xi')
mu = symbols('mu')
k = symbols('k')
m_u = symbols('m_u')
Imagine a star has a density profile of the form:
where \(\rho_c\) is the central density.
rho = rhoc * (1 - (r/Rstar)**3)
rho
z = (rho/rhoc).subs(r, xi*Rstar)
plot(z, (xi, 0, 1), xlabel=r"$r/R_\star$", ylabel=r"$\rho(r)$")

<sympy.plotting.backends.matplotlibbackend.matplotlib.MatplotlibBackend at 0x104923b10>
Find an expression for the central density in terms of \(R_\star\) and \(M_\star\).
M = integrate(4*pi*r**2*rho, (r, 0, Rstar))
M
rc = solve(Eq(M, Mstar), rhoc)[0]
rc
rho = rho.subs(rhoc, rc)
rho
Use HSE and the fact that the pressure vanishes at the surface to find the pressure as a function of radius. Your answer will be in the form of \(P(r) = P_c \times\) (polynomial in \(r/R_\star\)).
What is \(P_c\) in terms of \(M_\star\) and \(R_\star\)?
Express \(P_c\) numerically with \(M_\star\) and \(R_\star\) in solar units.
M = integrate(4*pi*r**2*rho, (r, 0, r))
M
z = simplify((M/Mstar).subs(r, xi*Rstar))
plot(z, (xi, 0, 1), xlabel=r"$r/R_\star$", ylabel=r"$M(r)$")

<sympy.plotting.backends.matplotlibbackend.matplotlib.MatplotlibBackend at 0x127f32750>
Now we can integrate HSE. We will do this as
We’ll substitute in our expressions for \(M(r)\) and \(\rho(r)\) in the integrand.
rho
However, recall that \(P(R_\star) = 0\), so we can enforce that here to find \(P_c\)
expand(G*M/r**2*rho)
For our general pressure expression. we integrate to some shell \(r\)
P = Pc + integrate(-G*M/r**2*rho, (r, 0, Rstar))
P
Or factoring \(P_c\) out (i.e. \(P/P_c\)), we have
Pc = solve(Eq(P, 0), Pc)[0]
Pc
P = Pc + integrate(-G*M/r**2*rho, (r, 0, r))
P
simplify(P/Pc)
z = simplify((P/Pc).subs(r, xi*Rstar))
plot(z, (xi, 0, 1), xlabel=r"$r/R_\star$", ylabel=r"$P(r)$")

<sympy.plotting.backends.matplotlibbackend.matplotlib.MatplotlibBackend at 0x134998190>
a.#
In this model, what is the central temperature, \(T_\star\)? (Assume an ideal gas). Compare to the result from the constant-density model (we did this in class). Why is the central pressure higher for the linear model whereas the central temperature is lower?
The central temperature, assuming the ideal gas law, is:
let’s start by evaluating the central pressure in the Sun for this model. Use the subs
function to compute \(P_c\) and \(\rho_c\) using the equations we found from ICA1 above.
# compute Pc here
# compute rho_c here
Okay great, but we still need to know the composition before we can compute the temperature.
We’ll look at two choices here:
i. pure H composition has \(\mu = 1/2\)
# compute Tc here for this composition
ii. pure He composition has \(\mu = 4/3\)
# compute Tc here for this composition
The central pressure for the constant-density model (HKT 1.39) was
Here, with the cubic density profile, we find
The pressure is greater in this model because more mass is concentrated toward the center of the star, increasing the force of gravity throughout, making the outer layers weigh more.
The temperature is the almost the same in both models, since both the central pressure and central density increase by the here.
Let’s evaluate \(P_c/\rho_c\) for our model
# Pc/rc
This shows us that the central temperature is:
while for the constant density model, the coefficient was 1/2
b.#
Verify that the virial theorem is satisfied and write down an explicit expression for \(\Omega\) (i.e. what is the `\(\alpha\)’ coefficient)?
We want to demonstrate that (HKT 1.21)
gravitational potential energy#
We start by integrating (HKT 1.6)
To do this, we use our expression for \(M(r)\) and \(\rho(r)\)
# define Omega and integrate it here
# what value of alpha did u find?
internal energy#
We need to compute:
and we can use our expression for \(P(r)\)
# solve the above equation here, does it equal omega?
c.#
Assume that the nuclear energy production rate is given as:
Calculate the luminosity of the star at its surface in terms of \(R_\star\), \(\rho_c\), and \(q_0\).
We just need to do the integral:
(this is the result when we are in thermal equilibrium).
Since \(q(r)\) is 0 beyond \(R_\star/5\), we only need to integrate up to that point.
# define q(r) here
# integrate L using q(r)