# Numerical integration of the dataset of a function

The energy equation for a spherically symmetric system is given by $$\mathscr{E}=\frac{v^2(r)}{2}+\frac{c_s^2(r)}{\gamma-1}+\phi(r)$$ where $$\mathscr{E}$$ is the total energy, $$v$$ is the velocity of fluid, $$c_s$$ is the speed of sound and $$\phi$$ is the potential energy. The radial force is obtained as the derivative of the potential energy, i.e., $$f(r)=-\phi'(r)$$, where the prime means derivative wrt $$r$$.

One can obtain the derivative of the equation as follows: $$\mathscr{E}'=vv'+\frac{2c_sc_s'}{\gamma-1}+\phi'$$

I am working in hydrodynamics of the system where I have an expression for $$f(r)$$ which is too complicated to integrate as the integral involves complex roots (the expression for $$f(r)$$ is the integrand in this answer). Using other constraints of the problem, the first two terms of the second equation can be expressed in terms of $$\phi'$$. This means that the second equation can be written as a function of $$\phi'$$(or equivalently $$f(r)$$). Now we can easily plot the equation $$\mathscr{E}'=\mathscr{E}'(f(r))=\mathscr{E}'(r)$$ The second equality is evident as $$f(r)$$ is a function of only $$r$$.

MY QUESTION:

Since $$\mathscr{E}'(r)$$ is a function of $$r$$, we can plot this function and obtain the dataset for a whole range of $$r$$. So is it possible to numerically integrate $$\mathscr{E}'(r)$$ using the dataset?

I am not sure whether such a numerical integration of a dataset is possible.

• As a point to clarify, the energy is the integral over the expression you have in the first formula. The first formula is really just an energy density. That also explains the funny second formula you have which does not seem to originate from the first by differentiation. – Wolfgang Bangerth Nov 25 '19 at 15:22
• @WolfgangBangerth Here $\mathscr{E}$ is actually the specific energy of a fluid element in the Bondi flow model of spherical accretion in astrophysics. Then one can perform sonic point analysis at a critical point to express both $v$ and $c_s$ in terms of $\phi'$. The similar calculations for a Newtonian model is done in page-10 of the following link: books.google.co.in/… – Richard Nov 26 '19 at 5:38
• No, it's still only an energy density :-) – Wolfgang Bangerth Nov 26 '19 at 16:20

In essence, you are asking whether you have values for a function $$h'(r)$$ at points $$r_i$$, you can obtain an approximation of $$h(r)$$. The answer is of course yes: If you connect the points $$(r_i,h'(r_i))$$ by a piecewise linear curve, then you can integrate that to obtain a piecewise quadratic approximation of $$h(r)$$.
You can be more accurate if you connect the points $$(r_i,h'(r_i))$$ through, for example, a spline curve.