Skip to content
DeepForgeby svx
All problems
MediumCalculusca-040

Volume of Revolution Disk Method

Problem

Approximate the volume of the solid formed by rotating y = f(x) about the x-axis over [a, b] with n disks, where f(x) = sum(coeffs[i] * x^i).

Use midpoint sampling: V = pi * dx * sum(f(midpoint)^2) with dx = (b - a) / n. Return 0.0 when n <= 0. Use 3.141592653589793 for pi.

Hint

Each disk has radius f(midpoint) and thickness dx, so its volume is pi * r^2 * dx.

Test cases

case 1
in: [[2],0,3,6]
expected: 37.69911184307752
case 2
in: [[0,1],0,2,4]
expected: 8.246680715673207
case 3
in: [[0,0,1],0,1,2]
expected: 0.5031456984264903
case 4
in: [[0],0,5,5]
expected: 0
Starter codePython
def volume_disk(coeffs, a, b, n):
    # Your code here
    pass

4 test cases · run your code against them in the editor