本文简要介绍 python 语言中 scipy.interpolate.lagrange
的用法。
用法:
scipy.interpolate.lagrange(x, w)#
返回一个拉格朗日插值多项式。
给定两个一维数组x和w,通过点返回拉格朗日插值多项式
(x, w)
.警告:此实现在数值上不稳定。即使选择最佳,也不要期望能够使用超过 20 个点。
- x: array_like
x 表示一组数据点的 x 坐标。
- w: array_like
w 表示一组数据点的 y 坐标,即 f(x)。
- lagrange:
numpy.poly1d
实例 拉格朗日插值多项式。
- lagrange:
参数 ::
返回 ::
例子:
将 插值 3 个点。
>>> import numpy as np >>> from scipy.interpolate import lagrange >>> x = np.array([0, 1, 2]) >>> y = x**3 >>> poly = lagrange(x, y)
由于只有 3 个点,因此拉格朗日多项式的次数为 2。明确地,它由下式给出
>>> from numpy.polynomial.polynomial import Polynomial >>> Polynomial(poly.coef[::-1]).coef array([ 0., -2., 3.])
>>> import matplotlib.pyplot as plt >>> x_new = np.arange(0, 2.1, 0.1) >>> plt.scatter(x, y, label='data') >>> plt.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()
相关用法
- Python SciPy interpolate.make_interp_spline用法及代码示例
- Python SciPy interpolate.krogh_interpolate用法及代码示例
- Python SciPy interpolate.InterpolatedUnivariateSpline用法及代码示例
- Python SciPy interpolate.BSpline用法及代码示例
- Python SciPy interpolate.LSQSphereBivariateSpline用法及代码示例
- Python SciPy interpolate.griddata用法及代码示例
- Python SciPy interpolate.splder用法及代码示例
- Python SciPy interpolate.LinearNDInterpolator用法及代码示例
- Python SciPy interpolate.PPoly用法及代码示例
- Python SciPy interpolate.NdBSpline用法及代码示例
- Python SciPy interpolate.pade用法及代码示例
- Python SciPy interpolate.barycentric_interpolate用法及代码示例
- Python SciPy interpolate.RegularGridInterpolator用法及代码示例
- Python SciPy interpolate.NdPPoly用法及代码示例
- Python SciPy interpolate.interp2d用法及代码示例
- Python SciPy interpolate.approximate_taylor_polynomial用法及代码示例
- Python SciPy interpolate.RectSphereBivariateSpline用法及代码示例
- Python SciPy interpolate.sproot用法及代码示例
- Python SciPy interpolate.splantider用法及代码示例
- Python SciPy interpolate.CloughTocher2DInterpolator用法及代码示例
- Python SciPy interpolate.interp1d用法及代码示例
- Python SciPy interpolate.BPoly用法及代码示例
- Python SciPy interpolate.BarycentricInterpolator用法及代码示例
- Python SciPy interpolate.splrep用法及代码示例
- Python SciPy interpolate.make_smoothing_spline用法及代码示例
注:本文由纯净天空筛选整理自scipy.org大神的英文原创作品 scipy.interpolate.lagrange。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。