relentless.math.Interpolator#

class relentless.math.Interpolator(x, y)#

Interpolating function.

Interpolates through a function \(y(x)\) on the domain \(a \le x \le b\). Outside this domain, y is extrapolated as a constant, i.e., \(y(x < a) = y(a)\) and \(y(x > b) = y(b)\).

Parameters:
  • x (array_like) – 1D array of x coordinates that must be continually increasing.

  • y (array_like) – 1D array of y coordinates.

Raises:

Examples

Interpolating the line \(y=2x\):

f = Interpolator(x=(-1,0,1), y=(-2,0,2))

Evaluating the function:

>>> f(0.5)
1.0
>>> f([-0.5,0.5])
(-1.0, 1.0)

Evaluate the \(n\)th derivative of the function:

>>> f.derivative(x=0.5, n=1)
2.0
>>> f.derivative(x=[-2.5,-0.5,0.5,2.5], n=1)
(0.0, 2.0, 2.0, 0.0)

Extrapolation:

>>> f(100)
2.0

Methods

derivative(x, n)

Evaluate the \(n\)th derivative of the interpolating function.

Attributes

domain

The valid domain for interpolation.

table

The interpolated data.

derivative(x, n)#

Evaluate the \(n\)th derivative of the interpolating function.

Parameters:
  • x (float or array_like) – 1-d array of \(x\) coordinates to evaluate.

  • n (int) – The order of the derivative to take.

Returns:

result – Interpolated derivative values having the same form as x.

Return type:

float or numpy.ndarray

property domain#

The valid domain for interpolation.

Type:

tuple

property table#

The interpolated data.

Type:

numpy.ndarray