返回一维Legendre多项式系数的缩放伴随矩阵

返回一维Legendre多项式系数的缩放伴随矩阵

要返回一维Legendre多项式系数的缩放伴随矩阵,请在Python的Numpy中使用legendre.legcompanion()方法。当c是Laguerre多项式的基础时,Legendre多项式的通常伴随矩阵已经是对称的,因此不需要进行缩放。

返回维度为(deg, deg)的缩放伴随矩阵。参数c是按低到高度排序的一维Legendre级数系数数组。

步骤

首先,导入所需的库−

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() 方法,可以将1-D数组的Legendre多项式系数返回为缩放的伴随矩阵。当c是基础的Laguerre多项式时,Legendre多项式的通常伴随矩阵已经是对称的,因此不需要进行缩放。

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]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程