Integral Calculus!

Solving a difficult Calculus problem by hand and by Python!

1/25/20242 min read

A student posted this question to "askmath" on Reddit. It's a Calculus question on finding the volume of a solid formed by rotating a curve around the x-axis. Like the 2-dimensional areas under curves, the solution involves integrals, the inverse operation of derivatives. Also like the 2-dimensional questions, the "Volume of a Solid of Revolution" problems are always introduced using the idea of adding up a number of simpler shapes. These problems are always accompanied by a diagram of a stack of cylinders

This method is introduced but quickly replaced by taking integrals algebraically, which works fine if the student understands integrals and the integrals involved aren't crazy hard. Many integrals require special methods of substitution to solve, and many have no derivative!

But there's a way that gets a very accurate solution no matter the difficulty of the algebraic solution. Finding the volume of a disk is easy. The volume is

We know the radius (that's the value of the function at any x-coordinate) and the height of each cylinder is simply the range of the x-values divided by the number of cylinders you want to use. The more cylinders you use, the more accurate your calculation will be to the actual volume. But doing this by hand, you couldn't realistically calculate the volume of more than 10 or 20 cylinders in a half hour, and that approximation still wouldn't be that accurate.

Using a computer would help! With the help of a loop, you could calculate the volume of millions of cylinders in a second or two. The code turned out to be only a dozen or so lines.

The solution for 100,000 cylinders took only a tenth of a second, and calculating 1 million took only a half a second to run.

The real power of this method is how, even if a function can't be integrated by the usual algebraic methods, it's still no problem for this program. In fact, that would be a good way to introduce other methods such as Taylor Series, which are used for precisely this purpose. I recommend Python!

Here's a video of my solutions to this problem:

The volume formula for a cylinder
The volume formula for a cylinder