cmlabs.interpolate.interpolate
- cmlabs.interpolate.interpolate(xvals, x, yvals=None, coef=None, method='auto')[source]
Interpolate the value of a function at a given point.
- Parameters:
xvals (array_like, 1-D) – The sorted x-coordinates of the data points.
x (float) – The x-coordinate at which to evaluate the polynomial.
yvals (array_like, 1-D, optional) – The y-coordinates of the data points, i.e., f(\(x\)). Only used if coef is not provided.
coef (array_like, 1-D or 2-D, optional) – The coefficients of the polynomial.
method (str, optional, default: 'auto') –
The interpolation method to use. Can be one of:
’auto’
’lagrange’
’newton’
’newtonfd’
’newtonbd’
’gaussfd’
’gaussbd’
’stirling’
’bessel’
- Returns:
res – The value of the polynomial at \(x\).
- Return type:
float
See also
divided_differences,finite_differences,lagrange,newton,newtonfd,newtonbd,gaussfd,gaussbd,stirling,besselNotes
The output is the value of the polynomial at \(x\) using the specified method or the most efficient method if method is ‘auto’.
Examples
>>> import numpy as np >>> from cmlabs.interpolate import interpolate >>> xvals = np.array([0, 1, 2, 3]) >>> yvals = np.array([1, 3, 2, 5]) >>> x = np.float32(1.15) >>> interpolate(xvals, x, yvals=yvals) >>> 2.8701875