Calculus¶
ChebPy provides differentiation, integration, and cumulative sums with spectral accuracy.
Differentiation¶
import numpy as np
from chebpy import chebfun
f = chebfun(lambda x: np.sin(x), [-np.pi, np.pi])
df = f.diff() # first derivative
d2f = f.diff(2) # second derivative
Differentiation is performed on the Chebyshev coefficients in \(O(n)\) time.
Definite Integration¶
integral = f.sum() # ∫ f(x) dx over the domain
Integration uses Clenshaw–Curtis quadrature and is accurate to machine precision.
Indefinite Integration (Cumulative Sum)¶
F = f.cumsum() # F(x) = ∫_{a}^{x} f(t) dt
The result is a new Chebfun whose degree is one higher than the input.
Example: Verify the Fundamental Theorem¶
f = chebfun(lambda x: np.exp(x), [-1, 1])
F = f.cumsum()
df = F.diff()
# df should agree with f to machine precision
print(np.max(np.abs(f(np.linspace(-1, 1, 100)) - df(np.linspace(-1, 1, 100)))))
References¶
- L. N. Trefethen, Approximation Theory and Approximation Practice, SIAM, 2013 (extended edition 2019), chs. 19–21 (differentiation, integration, quadrature).
- L. N. Trefethen, Is Gauss quadrature better than Clenshaw–Curtis?, SIAM Review, 50 (2008), pp. 67–87.
- T. A. Driscoll, N. Hale, and L. N. Trefethen (eds.), Chebfun Guide, Pafnuty Publications, 2014.