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

คำนวณรากของอนุกรมเชบิเชฟที่มีรากเชิงซ้อนใน Python

เมธอด chebyshev.chebroots() คำนวณรากของพหุนามเชบิเชฟ คืนค่าอาร์เรย์ของราก หากรากทั้งหมดเป็นจริง ผลลัพธ์จะเป็นจริง มิฉะนั้นจะเป็นเชิงซ้อน

การประมาณรากได้จากค่าเอกค่า (eigenvalues) ของเมทริกซ์คอมแพนियन (companion matrix) รากที่อยู่ไกลจากจุดกำเนิดอาจมีข้อผิดพลาดมาก

ขั้นตอน

from numpy.polynomial import chebyshev as C

j = complex(0, 1)
print("Result (roots)...\n", C.chebroots((-j, j)))
print("\nType...\n", C.chebroots((-j, j)).dtype)
print("\nShape...\n", C.chebroots((-j, j)).shape)

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

from numpy.polynomial import chebyshev as C

j = complex(0, 1)
print("Result (roots)...\n", C.chebroots((-j, j)))
print("\nType...\n", C.chebroots((-j, j)).dtype)
print("\nShape...\n", C.chebroots((-j, j)).shape)

ผลลัพธ์

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