返回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]]
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP