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

คำนวณรากของชุด Hermite ด้วยรากที่ซับซ้อนใน Python


ในการคำนวณรากของอนุกรม Hermite ให้ใช้เมธอด hermite.hermroots() ใน Python Numpy วิธีการคืนค่าอาร์เรย์ของรูทของซีรีส์ ถ้ารากทั้งหมดเป็นของจริง ผลลัพธ์ก็คือของจริง มิฉะนั้น มันก็จะซับซ้อน พารามิเตอร์ c คืออาร์เรย์ 1 มิติของสัมประสิทธิ์

ค่าประมาณของรูทได้มาจากค่าลักษณะเฉพาะของเมทริกซ์ที่แสดงร่วม รูทที่อยู่ไกลจากทฤษฎีของระนาบเชิงซ้อนอาจมีข้อผิดพลาดอย่างมากเนื่องจากความไม่แน่นอนของตัวเลขของอนุกรมสำหรับค่าดังกล่าว รากที่มีหลายหลากมากกว่า 1 จะแสดงข้อผิดพลาดที่มากขึ้นเช่นกัน เนื่องจากค่าของอนุกรมใกล้จุดดังกล่าวค่อนข้างไม่ไวต่อข้อผิดพลาดในราก รากที่แยกออกมาใกล้จุดกำเนิดสามารถปรับปรุงได้ด้วยการทำซ้ำสองสามครั้งในวิธีของนิวตัน

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

from numpy.polynomial import hermite as H

ในการคำนวณรากของอนุกรม Hermite ให้ใช้เมธอด hermite.hermroots() ใน Python Numpy -

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

รับประเภทข้อมูล -

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

รับรูปร่าง -

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

ตัวอย่าง

from numpy.polynomial import hermite as H

# To compute the roots of a Hermite series., use the hermite.hermroots() method in Python Numpy.
# The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex..

# The parameter, c is a 1-D array of coefficients.
j = complex(0,1)
print("Result...\n",H.hermroots((-j, j)))

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

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

ผลลัพธ์

Result...
   [0.5+0.j]

Type...
complex128

Shape...
(1,)