บทนำ
ในการคืนค่าเมทริกซ์คู่หูที่ปรับขนาด (scaled companion matrix) ของอาเรย์ 1 มิติ สัมประสิทธิ์พหุนาม Laguerre สามารถใช้ laguerre.lagcompanion() จาก NumPy (หมายเหตุ: ในเอกสารต้นฉบับเขียนว่า lagvander3d แต่จริงๆ แล้วคือ lagcompanion) เมทริกซ์คู่หูปกติของพหุนาม Laguerre เป็นเมทริกซ์สมมาตรแล้วเมื่อ c เป็นพหุนาม Laguerre พื้นฐาน ดังนั้นไม่มีการปรับขนาด
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import laguerre as L
2. สร้างอาเรย์ 1 มิติของสัมประสิทธิ์
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. คืนค่าเมทริกซ์คู่หู
print("\nResult...\n", L.lagcompanion(c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import laguerre as L
# สร้างอาเรย์ 1 มิติของสัมประสิทธิ์
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", L.lagcompanion(c))
ผลลัพธ์ที่คาดหวัง
Our Array... [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result... [[ 1. -0.33333333]
[-1. 4.33333333]]