Arithmetic¶
Chebfun objects support natural arithmetic operations, producing new Chebfun objects as results.
Basic Operations¶
import numpy as np
from chebpy import chebfun
f = chebfun(lambda x: np.sin(x), [-np.pi, np.pi])
g = chebfun(lambda x: np.cos(x), [-np.pi, np.pi])
h = f + g # addition
h = f - g # subtraction
h = f * g # multiplication
h = f / g # division (where g != 0)
h = f ** 2 # power
h = -f # negation
Scalar Operations¶
h = f + 1 # add a constant
h = 2 * f # scalar multiplication
h = f / 3 # scalar division
NumPy Universal Functions¶
Many NumPy ufuncs work with Chebfun objects:
h = np.sin(f)
h = np.exp(f)
h = np.abs(f)
Norms and Comparisons¶
print(f.norm()) # L2 norm
print(np.max(f)) # maximum value
print(np.min(f)) # minimum value
References¶
- Z. Battles and L. N. Trefethen, An extension of MATLAB to continuous functions and operators, SIAM J. Sci. Comput., 25 (2004), pp. 1743–1770.
- T. A. Driscoll, N. Hale, and L. N. Trefethen (eds.), Chebfun Guide, Pafnuty Publications, 2014.