polynomial interpolate
Wiki Polynomial interpolation\
solve this system of linear equations:
p(x)=anxn+an−1xn−1+⋯+a2x2+a1x+a0
We have to solve this system for
ak
to construct the interpolant
p(x)
. The matrix on the left is commonly referred to as a Vandermonde matrix.
Lagrange polynomial
example
x | f(x) |
---|---|
1 | 1 |
2 | 8 |
3 | 27 |
∴L(1.5)=3
code
from scipy.interpolate import lagrange
L = lagrange([1,2,3],[1,8,27])
print(L)
#poly1d([ 6., -11., 6.])
L(1.5)
#3.0
#check
import numpy as np
vandermonate = np.vander([1,2,3])
A = L.coeffs
y = np.dot(vandermonate,A)
print(y)
Vandermonde:
deal with null numbers using interpolate
filled = df.interpolate(method='spline', order=4)
#view
df.plot()
filled.plot()
method: {‘linear’, ‘time’, ‘index’, ‘values’, ‘nearest’, ‘zero’,‘slinear’, ‘quadratic’, ‘cubic’, ‘barycentric’, ‘krogh’, ‘polynomial’, ‘spline’ ‘piecewise_polynomial’, ‘pchip’}
see: scipy