This quantity is defined for each mass shell individually. If $\max$ was taken over the whole star, we would be comparing quantities in different regions, which limits the usefulness if the relative difference.
max
vs fmax
¶A = array([1,5,1e10])
B = array([-17,24,16])
max(A) # overall maximum in a single array
10000000000.0
fmax(A,B) # element-wise maximum, result is array of the same shape
array([ 1.00000000e+00, 2.40000000e+01, 1.00000000e+10])
m = mesa.profile('m-17.data')
rhs = - mesa.G * m.mass_grams / (4 * pi * m.radius_cm**4)
dmbar = (0.5 * (m.dm[:-1] + m.dm[1:]))
lhs = (m.pressure[:-1] - m.pressure[1:]) / dmbar
plot(m.mass[1:], abs(lhs - rhs[1:]) / np.fmax(np.abs(lhs),np.abs(rhs[1:])))
xlabel('$M/M_\odot$')
ylabel('$\Delta$')
yscale('log')
Python has lists of arbitrary objects marked by square brackets [...]
. For computations these have to converted to an array (uniform datatype, supports mathematical operations on the whole array).
A = [1, 2, -1e-30] # list
B = array(A)
Indices in Python start at 0.
A = array([1, 2, 7.5, -1e-30])
A[1] # second element only
2.0
A[-1] # last element
-1.0000000000000001e-30
A[1:3] # elements 1 and 2 (last index not included)
array([ 2. , 7.5])
A[2:] # start at third (index 2) element to the end
array([ 7.50000000e+00, -1.00000000e-30])
A.shape # shape of the whole array
(4,)