Derivation of pressure gradient stellar equation [duplicate]

I am trying to understand how to derive the following formula:

$$\frac{dP(r)}{dr}=-\frac{GM(r_<)\rho(r)}{r^2}$$

The notes are as follow:

Consider a star with COM and a shell:

$$P_1 - P_2 = -{\large\frac{dP}{dr}}\,dr$$

$${\large\frac{dP}{dr}} + g\rho = 0$$ ( My main issue with the derivation is unsure where this comes from.)

Then if we take $$g = {\large\frac{Gm}{r^2}}$$ and substitute into the above equation, we get the expected result.

If anyone could explain this derivation to me or an alternative one, it would be much appreciated.

marked as duplicate by Rob Jeffries astrophysics StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Oct 16 '18 at 6:30

If we suppose hydrostatic equilibrium, then \begin{align} \sum \vec{F}_i=0 \end{align}The forces acting come from: $$1$$) Pressure difference $$2$$) Gravity. I'll suppose all forces are radial and then just equal them. Let's calculate the forces. First \begin{align}[P(r)-P(r+dr)]\,dA=dP\,dA \end{align} Then we need force due to the mass enclosed by $$dA\,dr$$: \begin{align} F_g= dm\, g &= \rho\,g\,dV &\\ &= \rho g\,dA dr\\&=\rho \frac{GM_r}{r^2} \,dAdr \end{align}

As those forces must be equal:

\begin{align} \require{cancel}-\rho G \frac{M_r}{r^2} \cancel{dA}\,dr &=dP\,\cancel{dA}\\ -\rho G \frac{M_r}{r^2} &=\frac{dP}{dr}\end{align} The minus sign come from a simple reasoning they point in opposite direction. $$M_r$$ is the mass enclosed by a surface of radius $$r

It comes from:

$$F = ma = mg$$

as a function of radius:

$$F(r) = m(r)g(r)$$

Where the force to support the mass at $$r$$ is the pressure gradient:

$$F(r) = \frac{dP}{dr}$$

and is equal to the weight (mass times gravity)

$$w= g\rho(r)$$

with the gravity from Gauss's law (the enclosed mass for spherical symmetry):

$$g = -G\frac{M(