scipy.interpolate.

BarycentricInterpolator#

class scipy.interpolate.BarycentricInterpolator(xi, yi=None, axis=0, *, wi=None, rng=None)[source]#

Barycentric (Lagrange with improved stability) interpolator (C∞ smooth).

Constructs a polynomial that passes through a given set of points. Allows evaluation of the polynomial and all its derivatives, efficient changing of the y-values to be interpolated, and updating by adding more x- and y-values. For numerical stability, a barycentric representation is used rather than computing the coefficients of the polynomial directly.

Parameters:
xiarray_like, shape (npoints, )

1-D array of x-coordinates of the points the polynomial should pass through

yiarray_like, shape (…, npoints, …), optional

N-D array of y-coordinates of the points the polynomial should pass through. If None, the y values will be supplied later via the set_y method. The length of yi along the interpolation axis must be equal to the length of xi. Use the axis parameter to select correct axis.

axisint, optional

Axis in the yi array corresponding to the x-coordinate values. Defaults to axis=0.

wiarray_like, optional

The barycentric weights for the chosen interpolation points xi. If absent or None, the weights will be computed from xi (default). This allows for the reuse of the weights wi if several interpolants are being calculated using the same nodes xi, without re-computation. This also allows for computing the weights explicitly for some choices of xi (see notes).

rng{None, int, numpy.random.Generator}, optional

If rng is passed by keyword, types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate a Generator. If rng is already a Generator instance, then the provided instance is used. Specify rng for repeatable interpolation.

If this argument random_state is passed by keyword, legacy behavior for the argument random_state applies:

  • If random_state is None (or numpy.random), the numpy.random.RandomState singleton is used.

  • If random_state is an int, a new RandomState instance is used, seeded with random_state.

  • If random_state is already a Generator or RandomState instance then that instance is used.

Changed in version 1.15.0: As part of the SPEC-007 transition from use of numpy.random.RandomState to numpy.random.Generator this keyword was changed from random_state to rng. For an interim period, both keywords will continue to work (only specify one of them). After the interim period using the random_state keyword will emit warnings. The behavior of the random_state and rng keywords is outlined above.

Attributes:
dtype

Methods

__call__(x)

Evaluate the interpolating polynomial at the points x

add_xi(xi[, yi])

Add more x values to the set to be interpolated

derivative(x[, der])

Evaluate a single derivative of the polynomial at the point x.

derivatives(x[, der])

Evaluate several derivatives of the polynomial at the point x

set_yi(yi[, axis])

Update the y values to be interpolated

Notes

This method is a variant of Lagrange polynomial interpolation [1] based on [2]. Instead of using Lagrange’s or Newton’s formula, the polynomial is represented by the barycentric formula

\[p(x) = \frac{\sum_{i=1}^m\ w_i y_i / (x - x_i)}{\sum_{i=1}^m w_i / (x - x_i)},\]

where \(w_i\) are the barycentric weights computed with the general formula

\[w_i = \left( \prod_{k \neq i} x_i - x_k \right)^{-1}.\]

This is the same barycentric form used by