Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

คืนค่า scaled companion matrix ของ Hermite series coefficients 1-D array ใน Python


ภาพรวม

ใช้ numpy.polynomial.hermite.hermcompanion() คืน scaled companion matrix ของ 1-D array ของ Hermite polynomial coefficients basis polynomials ถูก scale ให้ companion matrix เป็น symmetric (เมื่อ c เป็น Hermite basis) ให้ eigenvalue estimates ดีกว่า และ eigenvalues จะเป็น real ถ้าใช้ numpy.linalg.eigvalsh

พารามิเตอร์

  • c: 1-D array ของ Hermite series coefficients เรียงจาก low to high degree

ขั้นตอนการทำงาน

1. นำเข้าไลบรารี

import numpy as np
from numpy.polynomial import hermite as H

2. สร้าง 1D array ของ coefficients

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

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)

4. คำนวณ scaled companion matrix

print("\nResult...\n", H.hermcompanion(c))

ตัวอย่างโค้ดเต็ม

import numpy as np
from numpy.polynomial import hermite as H
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)
print("\nResult...\n", H.hermcompanion(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.58925565]
 [ 0.70710678 -0.33333333]]

หมายเหตุ: Matrix ขนาด (deg, deg) = (2, 2) สำหรับ degree 2 polynomial (3 coefficients)