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

การสร้างอนุกรม Laguerre จากรากที่กำหนดใน Python


บทนำ

ในการสร้างอนุกรม Laguerre จากรากที่กำหนด สามารถใช้เมธอด laguerre.lagfromroots() จาก NumPy คล้ายกับตัวอย่างก่อนหน้า แต่ใช้รากเป็นจำนวนจริง

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

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

from numpy.polynomial import laguerre as L

2. สร้างอนุกรมจากรากจริง

print("Result...\n", L.lagfromroots((-1, 0, 1)))

3. ตรวจสอบชนิดข้อมูล

print("\nType...\n", L.lagfromroots((-1, 0, 1)).dtype)

4. ตรวจสอบรูปร่าง

print("\nShape...\n", L.lagfromroots((-1, 0, 1)).shape)

ตัวอย่างโค้ดสมบูรณ์

from numpy.polynomial import laguerre as L

# สร้างอนุกรมจากรากจริง
print("Result...\n", L.lagfromroots((-1, 0, 1)))

# ตรวจสอบชนิดข้อมูล
print("\nType...\n", L.lagfromroots((-1, 0, 1)).dtype)

# ตรวจสอบรูปร่าง
print("\nShape...\n", L.lagfromroots((-1, 0, 1)).shape)

ผลลัพธ์ที่คาดหวัง

Result...   [ 5. -17. 18. -6.]
Type... float64
Shape... (4,)