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

คำนวณรากของชุด Hermite_e ที่มีรากซ้อนใน Python


เพื่อคำนวณรากของชุด Hermite_e ให้ใช้เมธอด hermite_e.hermeroots() ใน Python Numpy เมธอดคืนค่าอาร์เรย์ของรากของชุด หากรากทั้งหมดเป็นจริง out ก็จะเป็นจริง มิฉะนั้นจะเป็น complex

พารามิเตอร์ c คืออาร์เรย์ 1-D ของ係 การประมาณรากได้จาก eigenvalues ของ companion matrix รากที่ไกลจากจุดกำเนิดของ complex plane อาจมี error ใหญ่เพราะ numerical instability รากที่มี multiplicity มากกว่า 1 ก็จะแสดง error ใหญ่เช่นกัน รากที่แยกจากกันใกล้จุดกำเนิดสามารถปรับปรุงได้ด้วย Newton's method

ขั้นตอน

ก่อนอื่น import ไลบรารีที่จำเป็น:

from numpy.polynomial import hermite_e as H

คำนวณรากของชุด Hermite_e:

j = complex(0,1)
print("Result...\n", H.hermeroots((-j, j)))

ดึง datatype:

print("\nType...\n", H.hermeroots((-j, j)).dtype)

ดึง shape:

print("\nShape...\n", H.hermeroots((-j, j)).shape)

ตัวอย่าง

from numpy.polynomial import hermite_e as H

# To compute the roots of a Hermite_e series
j = complex(0,1)
print("Result...\n", H.hermeroots((-j, j)))

# Get the datatype
print("\nType...\n", H.hermeroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n", H.hermeroots((-j, j)).shape)

ผลลัพธ์

Result...   [1.+0.j]
Type... complex128
Shape... (1,)