使用Python计算带有给定复根的Legendre级数的根

星星跌入梦境

使用Python计算带有给定复根的Legendre级数的根

要计算Legendre级数的根,请使用Python中的polynomial.legendre.lagroots()方法。该方法返回系列的根数组。如果所有根都是实数,则out也是实数,否则它是复数。参数c是一个1-D系数数组。

步骤

首先,导入所需的库 –

from numpy.polynomial import legendre as L

计算Legendre级数的根 –

j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

获取数据类型 –

print("\nType...\n",L.legroots((-j, j)).dtype)

获取形状 –

print("\nShape...\n",L.legroots((-j, j)).shape)

示例

from numpy.polynomial import legendre as L

# 要计算Legendre级数的根,请使用Python中的polynomial.legendre.lagroots()方法。
# 该方法返回系列的根数组。如果所有根都是实数,则out也是实数,否则它是复数。

# 参数c是一个1-D系数数组。
j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

# 获取数据类型
print("\nType...\n",L.legroots((-j, j)).dtype)

# 获取形状
print("\nShape...\n",L.legroots((-j, j)).shape)

输出

Result...
   [1.+0.j]

Type...
complex128

Shape...
(1,)

版权声明:本页面内容旨在传播知识,为用户自行发布,若有侵权等问题请及时与本网联系,我们将第一时间处理。E-mail:284563525@qq.com

目录[+]

取消
微信二维码
微信二维码
支付宝二维码