The area of the surface of revolution about the $x$-axis between $a$ and $b$ of the function $y = f(x)$ is given by the integral
$$
S = 2\pi\int_a^b y\;\mathrm{d}s, \quad \mathrm{where}\;\mathrm{d}s = \sqrt{1 + \left(\frac{\mathrm{d}y}{\mathrm{d}x}\right)^2}\mathrm{d}x.
$$
Use this equation to write a function to determine the surface area of revolution of a function $y=f(x)$ about the $x$-axis, given Python function objects which return $y$ and $\mathrm{d}y/\mathrm{d}x$, and test it for the paraboloid obtained by rotation of the function $f(x) = \sqrt{x}$ about the $x$-axis between $a=0$ and $b=1$. Compare with the exact result, $\pi(5^{3/2}-1)/6$.
Solution P8.2.1
The general formula for the surface area is given
$$
S = 2\pi\int_0^1 y\;\mathrm{d}s, \quad \mathrm{where}\;\mathrm{d}s = \sqrt{1 + \left(\frac{\mathrm{d}y}{\mathrm{d}x}\right)^2}\mathrm{d}x.
$$
For the function $y(x) = \sqrt{x}$,
$$
\frac{\mathrm{d}y}{\mathrm{d}x} = \frac{1}{2\sqrt{x}}
$$
In the code below we define a generalized function for obtaining the surface of revolution (about the $x$-axis), given a function, its derivative and limits $a$ and $b$.
import numpy as np
from scipy.integrate import quad
def surface_of_revolution(f, dfdx, a, b):
# The integrand, y.sqrt(1 + (dy/dx)^2):
g = lambda x: f(x) * np.sqrt(1 + dfdx(x) ** 2)
I, err = quad(g, a, b)
return 2 * np.pi * I, 2 * np.pi * err
# Numerical answer: lambda functions for y = f(x) and dydx = f'(x)
y = lambda x: np.sqrt(x)
dydx = lambda x: 1 / 2 / np.sqrt(x)
S, err = surface_of_revolution(y, dydx, 0, 1)
# Exact answer:
Sexact = np.pi / 6 * (5**1.5 - 1)
print(f"S = {S} (error: {err})")
print(f"Exact S = {Sexact}")
The output is:
S = 5.330413500268972 (error: 2.422226463731035e-12)
Exact S = 5.330413500268973