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('S = {} (error: {})'.format(S, err))
print('Exact S = {}'.format(Sexact))
The output is:
S = 5.330413500268972 (error: 2.422226463731035e-12)
Exact S = 5.330413500268973