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

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


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

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

ขั้นตอน

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

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

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

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

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

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

รับรูปร่าง -

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

ตัวอย่าง

from numpy.polynomial import hermite_e as H

# To compute the roots of a Hermite_e 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.
print("Result...\n",H.hermeroots((-1, 0, 1)))

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

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

ผลลัพธ์

Result...
   [-1.41421356 1.41421356]

Type...
float64

Shape...
(2,)