numpy.polynomial.legendre.legfromroots#

polynomial.legendre.legfromroots(roots)[源代码]#

生成具有给定根的勒让德级数.

该函数返回多项式的系数

\[p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),\]

在勒让德形式中,其中 \(r_n\) 是在 roots 中指定的根.如果一个零点的重数为 n,那么它必须在 roots 中出现 n 次.例如,如果 2 是一个重数为三的根,3 是一个重数为二的根,那么 roots 看起来像 [2, 2, 2, 3, 3].根可以以任何顺序出现.

如果返回的系数是 c,那么

\[p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x)\]

对于勒让德形式的单项多项式,最后一项的系数通常不是1.

参数:
rootsarray_like

包含根的序列.

返回:
outndarray

系数的一维数组. 如果所有根都是实数,则 out 是一个实数数组,如果某些根是复数,则 out 是复数,即使结果中的所有系数都是实数(见下面的示例).

示例

>>> import numpy.polynomial.legendre as L
>>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis
array([ 0. , -0.4,  0. ,  0.4])
>>> j = complex(0,1)
>>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis
array([ 1.33333333+0.j,  0.00000000+0.j,  0.66666667+0.j]) # may vary