scipy.interpolate.lagrange

403 阅读1分钟
拉格朗日插值法是scipy库中常用的插值方法。

官网定义如下:

scipy.interpolate.lagrange(x, w)[source]
Return a Lagrange interpolating polynomial.

Given two 1-D arrays x and w, returns the Lagrange interpolating polynomial through the points (x, w).

Warning: This implementation is numerically unstable. Do not expect to be able to use more than about 20 points even if they are chosen optimally.

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.

其参数为两个一维数组,分别代表坐标的x值和y值,输出是多项式。可以直接用了计算插值。

例如:

x=[100,200,300,400]\

y=[10,20,30,40]\

f=lagrange(x,y)\

求在500处的插值f(500)得到49.999999999999837,符号我们的数据

Warning: This implementation is numerically unstable. Do not expect to be able to use more than about 20 points even if they are chosen optimally.

这方法不是很稳定,所有输入的数据点最好不要超过20个