# A Friendly Tutorial on Leibniz’s Rule with a Physical Application to a Liquid-Filled Spherical Tank

Those of you that haven’t taken calculus, feel free to sit this one out.

Several times in my engineering education, I have been confronted with a problem where I must differentiate an integral with a time-varying limit of integration. This is a different problem altogether from when the upper limit of integration is simply $x$, in which case we can use the Fundamental Theorem of Calculus to differentiate the integral.

The purpose of this blog post is to give the reader a concrete example of where the application of Leibniz’s Rule is useful and labor-saving.

Here is a problem that was given to some undergraduate students in the control theory course I was a teaching assistant for. Consider the problem diagram below. We have a spherical tank that is being filled with a liquid at the top. The fluid level is rising due the accumulation of the mass in the tank.

The exact problem was a little lengthier, but a key part solving the problem was writing the differential equation for the mass balance. From this mass balance, we can find our true objective, which is a differential equation for the fluid level in the tank. The mass balance equation is written as:

$\frac{dM_{total}}{dt} = \dot m_{in} -\dot m_{out}$

The spherical tank is being filled with a liquid. Since it is only being filled, and no fluid is leaving the tank, we have $\dot m_{out} = 0$. The mass flowrate into the control volume is simply the fluid density times the volumetric flowrate, or mathematically, $\dot m_{in} = \rho \dot q$.

The total fluid mass in the spherical tank, $M_{total}$, can be found by integrating over the volume of the liquid in the vessel.

$\frac{d}{dt}\int\rho dV=\rho \dot q$

Let’s focus now on the integral term that is being differentiated. As you might remember from calculus II or III, you can take a volume integral by adding up infinitesimal slices. We can calculate the volume of the fluid in the spherical container by integrating from the base of the sphere up to the fluid level, $h(t)$, where the height is an unknown function of time.

The volume of the liquid is the integral of the cross-sectional area of the fluid surface times an infinitesimal height, $dh$.

$\int\rho dV = \int_{0}^{h(t)}Adh$

Using our skills in analytic geometry, we can figure out what the cross-sectional area term is. The fluid surface in the sphere is always a circle, of radius $a$ as shown in the figure. Using the Pythagorean Theorem and a little algebra, we compute the cross-sectional area term as:

$A = \pi a^2$

$\pi a^2 =\pi (2Rh - h^2)$

(Verify this for yourself mentally. What happens  to $A$ at the midpoint, where $h = R$? What happens to $A$ at when the sphere is completely full, at $h = 2R$?)

Substituting the cross-sectional area term into our previous integral now yields the differential equation:

$\frac{d}{dt}\int_{0}^{h(t)}\rho\pi (2Rh - h^2)dh = \rho \dot q$

This integral isn’t anything particularly terrifying. We could just compute the integral directly using the power rule, substitute in the limits of integration, and then differentiate it. But Mr. von Leibniz did some moderately heavy lifting for us, and computed a useful formula (page 393) we can use for differentiating integrals with time-varying limits of integration:

$\frac{d}{dt}\int_{a(t)}^{b(t)}f(x)dx = f(b(t))\frac{db}{dt} - f(a(t))\frac{da}{dt}$

Applying the formula to our integral is a snap. Since the lower limit of integration is zero, the subtrahend on the right hand side is zero, since both $\rho\pi (2Rh - h^2)$ evaluated at $h = 0$ is zero, and $\frac{d}{dt}(0) = 0$. The minuend of the right hand side is simply:

$f(h(t))\frac{dh}{dt} = \rho\pi (2Rh - h^2)\frac{dh}{dt}$

Which means the differential equation transforms into:

$\rho\pi (2Rh - h^2)\frac{dh}{dt} = \rho \dot q$

or, when cast in standard form:

$\frac{dh}{dt} = \frac{\dot q}{\pi (2Rh - h^2)}$

Which yields a differential equation for the fluid level, $h$, in the spherical tank, as desired.