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