- Scipy.interpolation provides interp1d class which is a useful method to create a function based on fixed data points. We will create two such functions that use different techniques of interpolation. The difference will be clear to you when you see the plotted graph of both of these functions.
- We compare our results to scipy.interpolate.interp1d, the primary method used for 1-dimensional interpolation in scipy. The API for scipy.interpolate.interp1d is identical to interpval, but takes an additional argument to specify what degree interpolant to estimate. We now verify that both functions return the same set of results.
This example demonstrates some of the different interpolation methods available in scipy.interpolation.interp1d.
Inverse Quadratic Interpolation¶
Inverse quadratic interpolation is a type of polynomial interpolation.Polynomial interpolation simply means we find the polynomial of leastdegree that fits a set of points. In quadratic interpolation, we usethree points, and find the quadratic polynomial that passes throughthose three points.
So that’s the idea behind quadratic interpolation. Use a quadraticapproximation, find the zero of interest, use that as a new point forthe next quadratic approximation.
Inverse quadratic interpolation means we do quadratic interpolation onthe inverse function. So, if we are looking for a root of (f),we approximate (f^{-1}(x)) using quadratic interpolation. Notethat the secant method can be viewed as a linear interpolation on theinverse of (f). We can write:
![Interpolate Interpolate](/uploads/1/3/7/5/137564690/129832751.png)
Interpolate.interp1d
[f^{-1}(y) = frac{(y-f(x_n))(y-f(x_{n-1}))}{(f(x_{n-2})-f(x_{n-1}))(f(x_{n-2})-f(x_{n}))}x_{n-2} + frac{(y-f(x_n))(y-f(x_{n-2}))}{(f(x_{n-1})-f(x_{n-2}))(f(x_{n-1})-f(x_{n}))}x_{n-1} + frac{(y-f(x_{n-2}))(y-f(x_{n-1}))}{(f(x_{n})-f(x_{n-2}))(f(x_{n})-f(x_{n-1}))}x_{n-1}]
We use the above formula to find the next guess (x_{n+1}) for azero of (f) (so (y=0)):
[x_{n+1} = frac{f(x_n)f(x_{n-1})}{(f(x_{n-2})-f(x_{n-1}))(f(x_{n-2})-f(x_{n}))}x_{n-2} + frac{f(x_n)f(x_{n-2})}{(f(x_{n-1})-f(x_{n-2}))(f(x_{n-1})-f(x_{n}))}x_{n-1} + frac{f(x_{n-2})f(x_{n-1})}{(f(x_{n})-f(x_{n-2}))(f(x_{n})-f(x_{n-1}))}x_{n}]
We aren’t so much interested in deriving this as we are understandingthe procedure:
Convergence rate is approximately (1.8). The advantage of theinverse method is that we will always have a real root (the parabolawill always cross the x-axis). A serious disadvantage is that theinitial points must be very close to the root or the method may notconverge.
That is why it is usually used in conjunction with other methods.
Interpolate a 1-D function.
x and y are arrays of values used to approximate some function f:y=f(x). This class returns a function whose call method usesinterpolation to find the value of new points.
Parameters: | x : (N,) array_like y : (...,N,...) array_like
kind : str or int, optional
axis : int, optional
copy : bool, optional
bounds_error : bool, optional
fill_value : float, optional
assume_sorted : bool, optional
|
---|
See also
Python Linear Interpolation
- UnivariateSpline
- A more recent wrapper of the FITPACK routines.
splrep, splev, interp2d
Examples
Methods
Interp1d
__call__(x) | Evaluate the interpolant |