返回Python中一维勒让德多项式系数的缩放伴随矩阵


要返回一维勒让德多项式系数的缩放伴随矩阵,请在Python NumPy中使用legendre.legcompanion()方法。当c是拉盖尔多项式基时,勒让德多项式的普通伴随矩阵已经是对称的,因此不应用缩放。

返回维度为(deg, deg)的缩放伴随矩阵。参数c是一个从低到高阶排序的一维勒让德级数系数数组。

步骤

首先,导入所需的库:

import numpy as np
from numpy.polynomial import legendre as L

创建一个一维系数数组:

c = np.array([1, 2, 3, 4, 5])

显示数组:

print("Our Array...\n",c)

检查维度:

print("\nDimensions of our Array...\n",c.ndim)

获取数据类型:

print("\nDatatype of our Array object...\n",c.dtype)

获取形状:

print("\nShape of our Array object...\n",c.shape)

要返回一维勒让德多项式系数的缩放伴随矩阵,请在Python NumPy中使用legendre.legcompanion()方法。当c是拉盖尔多项式基时,勒让德多项式的普通伴随矩阵已经是对称的,因此不应用缩放:

print("\nResult...\n",L.legcompanion(c))

示例

import numpy as np
from numpy.polynomial import legendre as L

# Create a 1D array of coefficients
c = np.array([1, 2, 3, 4, 5])

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To return the scaled companion matrix of a 1-D array of Legendre polynomial coefficients, use the legendre.legcompanion() method in Python Numpy
print("\nResult...\n",L.legcompanion(c))

输出

Our Array...
   [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(5,)

Result...
   [[ 0.           0.57735027     0.           -0.30237158]
   [ 0.57735027    0.             0.51639778   -0.34914862]
   [ 0.            0.51639778     0.            0.10141851]
   [ 0.            0.             0.50709255   -0.45714286]]

更新于:2022年3月10日

116 次浏览

启动您的职业生涯

通过完成课程获得认证

开始学习
广告