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

หารอนุกรม Hermite_e ด้วยอีกอนุกรมหนึ่งใน Python


บทนำ

การหารอนุกรม Hermite_e ด้วยอีกอนุกรมหนึ่ง ใช้เมธอด polynomial.hermite.hermediv() ใน NumPy เมธอดนี้คืนค่าอาร์เรย์ของสัมประสิทธิ์อนุกรม Hermite_e ที่แสดงผลลัพธ์ของการหาร (Quotient) และเศษ (Remainder)

รายละเอียด

คืนค่า Quotient-with-Remainder ของอนุกรม Hermite_e สองตัว c1 / c2 อาร์กิวเมนต์คือลำดับของสัมประสิทธิ์จากออเดอร์ต่ำสุดไปสูงสุด เช่น [1,2,3] แทนอนุกรม P₀ + 2·P₁ + 3·P₂ พารามิเตอร์ c1 และ c2 เป็นอาร์เรย์ 1-D ของสัมประสิทธิ์อนุกรม Hermite_e เรียงจากต่ำไปสูง

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

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

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

2. สร้างอาร์เรย์ 1-D ของสัมประสิทธิ์

c1 = np.array([53., 30., 52., 7., 6.])
c2 = np.array([1, 2, 3])

3. แสดงอาร์เรย์สัมประสิทธิ์

print("Array1...\n", c1)
print("\nArray2...\n", c2)

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

print("\nArray1 datatype...\n", c1.dtype)
print("\nArray2 datatype...\n", c2.dtype)

5. ตรวจสอบมิติ

print("\nDimensions of Array1...\n", c1.ndim)
print("\nDimensions of Array2...\n", c2.ndim)

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

print("\nShape of Array1...\n", c1.shape)
print("\nShape of Array2...\n", c2.shape)

7. ทำการหารอนุกรม

print("\nResult (division)....\n", H.hermediv(c1, c2))

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

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

# สร้างอาร์เรย์ 1-D ของสัมประสิทธิ์
c1 = np.array([53., 30., 52., 7., 6.])
c2 = np.array([1, 2, 3])

# แสดงอาร์เรย์
print("Array1...\n", c1)
print("\nArray2...\n", c2)

# ตรวจสอบชนิดข้อมูล
print("\nArray1 datatype...\n", c1.dtype)
print("\nArray2 datatype...\n", c2.dtype)

# ตรวจสอบมิติ
print("\nDimensions of Array1...\n", c1.ndim)
print("\nDimensions of Array2...\n", c2.ndim)

# ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", c1.shape)
print("\nShape of Array2...\n", c2.shape)

# หารอนุกรม Hermite_e
print("\nResult (division)....\n", H.hermediv(c1, c2))

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

Array1...   [53. 30. 52. 7. 6.]
Array2...   [1 2 3]
Array1 datatype... float64
Array2 datatype... int64
Dimensions of Array1... 1
Dimensions of Array2... 1
Shape of Array1... (5,)
Shape of Array2... (3,)
Result (division).... (array([8., 1., 2.]), array([31., -1.]))