scipy.interpolate.lagrange

来源:互联网 发布:数据库触发器工作原理 编辑:程序博客网 时间:2024/06/05 07:37

拉格朗日插值法是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_likex represents the x-coordinates of a set of datapoints.w : array_likew represents the y-coordinates of a set of datapoints, i.e. f(x).Returns:lagrange : numpy.poly1d instanceThe 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个

1 0
原创粉丝点击