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

หาค่าอนุพันธ์ของอนุกรมเฮอร์ไมท์_e ตั้งค่าอนุพันธ์และคูณด้วยสเกลาร์ใน Python

บทนำ

เพื่อหาค่าอนุพันธ์ (differentiate) ของอนุกรมเฮอร์ไมท์_e (Hermite_e series) เราสามารถใช้เมธอด hermite_e.hermeder() ใน Python เมธอดนี้รับพารามิเตอร์หลักๆ ดังนี้:

  • c: อาร์เรย์ของสัมประสิทธิ์อนุกรมเฮอร์ไมท์_e หาก c เป็นมัลติมิติ แกนต่างๆ จะสอดคล้องกับตัวแปรต่างๆ โดยดีกรีในแต่ละแกนกำหนดโดยดัชนีที่สอดคล้องกัน
  • m: จำนวนอนุพันธ์ที่ต้องการ (number of derivatives taken) ต้องเป็นค่าบวกหรือศูนย์ (ค่าเริ่มต้น: 1)
  • scl: สเกลาร์ แต่ละครั้งของการหาอนุพันธ์จะคูณด้วย scl ผลลัพธ์สุดท้ายคือการคูณด้วย scl**m ใช้สำหรับการเปลี่ยนแปลงตัวแปรแบบเชิงเส้น (ค่าเริ่มต้น: 1)
  • axis: แกนที่นำไปหาอนุพันธ์ (ค่าเริ่มต้น: 0)

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

1. นำเข้าไลบรารีที่จำเป็น

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

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

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

3. แสดงอาร์เรย์

print("Our Array...\n", c)

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

print("\nDimensions of our Array...\n", c.ndim)

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

print("\nDatatype of our Array object...\n", c.dtype)

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

print("\nShape of our Array object...\n", c.shape)

7. หาค่าอนุพันธ์ของอนุกรมเฮอร์ไมท์_e (อนุพันธ์อันดับ 2 คูณด้วย -1)

print("\nResult...\n", H.hermeder(c, 2, scl=-1))

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

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

# สร้างอาร์เรย์สัมประสิทธิ์
c = np.array([1, 2, 3, 4])

# แสดงอาร์เรย์
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)

# หาค่าอนุพันธ์ของอนุกรมเฮอร์ไมท์_e (อนุพันธ์อันดับ 2 คูณด้วย -1)
print("\nResult...\n", H.hermeder(c, 2, scl=-1))

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

Our Array...
 [1 2 3 4]
Dimensions of our Array...
 1
Datatype of our Array object...
 int64
Shape of our Array object...
 (4,)

Result...
 [ 6. 24.]