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

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


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

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

ขั้นตอน

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

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

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

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

ดึง datatype:

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

ดึง shape:

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
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,)