Q8.2.1Numerical integration of a simple function
Use scipy.integrate.quad to evaluate the following integral:
\[\int_0^6 \left\lfloor x \right\rfloor - 2\left\lfloor\frac{x}{2}\right\rfloor\;\mathrm{d}x.\]
Show solution
By numerical integration, the result is seen to be 3:
In [x]: from scipy.integrate import quad
In [x]: import numpy as np
In [x]: func = lambda x: np.floor(x) - 2 * np.floor(x / 2)
In [x]: quad(func, 0, 6)
Out[x]: (2.999964948683555, 0.0009520766614606472)