本文簡要介紹 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。