在 Python 中返回一维多项式系数数组的伴随矩阵
要返回一维多项式系数数组的伴随矩阵,请在 Python NumPy 中使用 `polynomial.polycompanion()` 方法。由于通过缩放基数无法使幂级数的伴随矩阵对称,因此此函数与正交多项式的函数不同。该方法返回维度为 (deg, deg) 的伴随矩阵。参数 c 是一个从低到高次排列的一维多项式系数数组。
步骤
首先,导入所需的库:
import numpy as np from numpy.polynomial.polynomial import polycompanion
创建一个一维系数数组:
c = np.array([1, 2, 3])
显示数组:
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)
要返回一维多项式系数数组的伴随矩阵,请使用 `polynomial.polycompanion()` 方法:
print("\nResult...\n",polycompanion(c))
示例
import numpy as np from numpy.polynomial.polynomial import polycompanion # Create a 1D array of coefficients c = np.array([1, 2, 3]) # 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 companion matrix of a 1-D array of polynomial coefficients, return the polynomial.polycompanion() method in Python Numpy print("\nResult...\n",polycompanion(c))
输出
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [[ 0. -0.33333333] [ 1. -0.66666667]]
广告