5.1.3.4. numdifftools.extrapolation.Richardson¶
-
class
Richardson
(step_ratio=2.0, step=1, order=1, num_terms=2)[source]¶ Extrapolates as sequence with Richardsons method
Notes
Suppose you have series expansion that goes like this
L = f(h) + a0 * h^p_0 + a1 * h^p_1+ a2 * h^p_2 + …
where p_i = order + step * i and f(h) -> L as h -> 0, but f(0) != L.
If we evaluate the right hand side for different stepsizes h we can fit a polynomial to that sequence of approximations. This is exactly what this class does.
Examples
>>> import numpy as np >>> import numdifftools as nd >>> n = 3 >>> Ei = np.zeros((n,1)) >>> h = np.zeros((n,1)) >>> linfun = lambda i : np.linspace(0, np.pi/2., 2**(i+5)+1) >>> for k in np.arange(n): ... x = linfun(k) ... h[k] = x[1] ... Ei[k] = np.trapz(np.sin(x),x) >>> En, err, step = nd.Richardson(step=1, order=1)(Ei, h) >>> truErr = np.abs(En-1.) >>> np.all(truErr < err) True >>> np.all(np.abs(Ei-1)<1e-3) True >>> np.allclose(En, 1) True
-
__init__
(step_ratio=2.0, step=1, order=1, num_terms=2)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([step_ratio, step, order, num_terms])Initialize self. extrapolate
(sequence, steps)rule
([sequence_length])-