Integral Calculus!
Solving a difficult Calculus problem by hand and by Python!
1/25/20242 min read
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=812,h=344,fit=crop/A3QryQyvZ8IBwgrZ/volume_solid-A85r6BlvGoipW06q.png)
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=328,h=320,fit=crop/A3QryQyvZ8IBwgrZ/volume_solid-A85r6BlvGoipW06q.png)
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
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=852,h=320,fit=crop/A3QryQyvZ8IBwgrZ/disk_method-AE0vq6EjjpSPga4k.png)
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=328,h=320,fit=crop/A3QryQyvZ8IBwgrZ/disk_method-AE0vq6EjjpSPga4k.png)
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](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=249,h=81,fit=crop/A3QryQyvZ8IBwgrZ/volume_cylinder-Yg251ry7pGTgB8eW.png)
![The volume formula for a cylinder](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=328,h=320,fit=crop/A3QryQyvZ8IBwgrZ/volume_cylinder-Yg251ry7pGTgB8eW.png)
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=819,h=509,fit=crop/A3QryQyvZ8IBwgrZ/integral_code-dOqNXK15kaU0LLD4.png)
![](https://assets.zyrosite.com/cdn-cgi/image/format=auto,w=328,h=320,fit=crop/A3QryQyvZ8IBwgrZ/integral_code-dOqNXK15kaU0LLD4.png)