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

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


บทนำ

ในการสร้างอนุกรม Hermite จากรากที่กำหนด สามารถใช้เมธอด hermite.hermfromroots() จาก NumPy เมธอดนี้คืนค่าอาเรย์ 1 มิติของสัมประสิทธิ์ หากรากทั้งหมดเป็นจริง ผลลัพธ์จะเป็นจริง หากมีรากเชิงซ้อน ผลลัพธ์จะเป็นเชิงซ้อน แม้สัมประสิทธิ์จะเป็นจริงทั้งหมด พารามิเตอร์ roots คือลำดับของราก

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

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

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

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

print("Result...\n", H.hermfromroots((-1, 0, 1)))

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

print("\nType...\n", H.hermfromroots((-1, 0, 1)).dtype)

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

print("\nShape...\n", H.hermfromroots((-1, 0, 1)).shape)

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

from numpy.polynomial import hermite as H

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

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

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

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

Result...   [0. 0.25 0. 0.125]
Type... float64
Shape... (4,)