%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import special
def vol_sphere(n):
"Return the volume of the unit ball in n dimensions"
return np.pi**(n/2)/ special.gamma(n/2+1)
def vol_cube(n):
"Return the volume of the cube surrounding the unit ball in n dimensions"
return 2**n
n = np.arange(1, 10)
sph = vol_sphere(n)
cub = vol_cube(n)
plt.scatter(n, sph, label="Sphere")
plt.scatter(n, cub, label="Cube")
plt.legend();