Deprecated since version 1.18.0:
- Parameters:
- x : array_like
x represents the x-coordinates of a set of datapoints.
- w : array_like
w represents the y-coordinates of a set of datapoints, i.e., f(x).
- Returns:
- lagrange :
numpy.poly1d instance The Lagrange interpolating polynomial.
Notes
The name of this function refers to the fact that the returned object represents
a Lagrange polynomial, the unique polynomial of lowest degree that interpolates
a given set of data [1]. It computes the polynomial using Newton’s divided
differences formula [2]; that is, it works with Newton basis polynomials rather
than Lagrange basis polynomials. For numerical calculations, the barycentric form
of Lagrange interpolation (scipy.interpolate.BarycentricInterpolator) is
typically more appropriate.
Array API Standard Support
lagrange is not in-scope for support of Python Array API Standard compatible
backends other than NumPy.
References
Examples
.
plot
(
x_new
,
Polynomial
(
poly
.
coef
[::
-
1
])(
x_new
),
label
=
'Polynomial'
)
plt
.
plot
(
x_new
,
3
*
x_new
**
2
-
2
*
x_new
+
0
*
x_new
,
label
=
r
"$3 x^2 - 2 x$"
,
linestyle
=
'-.'
)
plt
.
legend
()
plt
.
show
()