All problems
Shell Method
Problem
The volume of the solid formed by rotating y = f(x) about the y-axis is V = 2*pi*integral of x*f(x) dx over [a, b].
Approximate it with n midpoint rectangles: V ≈ 2*pi*dx*sum(x_mid * f(x_mid)) where f(x) = sum(coeffs[i] * x^i) and dx = (b - a) / n. Return 0.0 when n <= 0 and use 3.141592653589793 for pi.
Hint
Cylindrical shells have circumference 2 pi x, height f(x), and thickness dx.
Test cases
case 1
in: [[2],0,3,4]
expected: 56.548667764616276
case 2
in: [[0,1],0,2,4]
expected: 16.493361431346415
case 3
in: [[0],0,3,4]
expected: 0
case 4
in: [[1],1,3,8]
expected: 25.132741228718345
Starter codePython
def shell_method(coeffs, a, b, n):
# Your code here
pass4 test cases · run your code against them in the editor