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,
yis 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:
ValueError – If
xis a scalar.ValueError – If
xis not 1-dimensional.ValueError – If
yis not the same shape asx.ValueError – If
xis not strictly increasing.
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
The valid domain for interpolation.
The interpolated data.
- derivative(x, n)#
Evaluate the \(n\)th derivative of the interpolating function.
- Parameters:
- Returns:
result – Interpolated derivative values having the same form as
x.- Return type:
- property table#
The interpolated data.
- Type: