ในการคำนวณรากของพหุนาม ให้ใช้วิธีการ chebyshev.chebroots() ใน Python Numpy วิธีการคืนค่าอาร์เรย์ของรากของชุดข้อมูล ถ้ารากทั้งหมดเป็นของจริง ผลลัพธ์ก็คือของจริง มิฉะนั้น มันก็จะซับซ้อน พารามิเตอร์ c คืออาร์เรย์ 1-D ของสัมประสิทธิ์
ค่าประมาณของรูทได้มาจากค่าลักษณะเฉพาะของเมทริกซ์ที่แสดงร่วม รูทที่อยู่ไกลจากทฤษฎีของระนาบเชิงซ้อนอาจมีข้อผิดพลาดอย่างมากเนื่องจากความไม่แน่นอนของตัวเลขของอนุกรมสำหรับค่าดังกล่าว รากที่มีหลายหลากมากกว่า 1 จะแสดงข้อผิดพลาดที่มากขึ้นเช่นกัน เนื่องจากค่าของอนุกรมใกล้จุดดังกล่าวค่อนข้างไม่ไวต่อข้อผิดพลาดในราก รากที่แยกออกมาใกล้จุดกำเนิดสามารถปรับปรุงได้ด้วยการทำซ้ำสองสามครั้งในวิธีของนิวตัน
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
from numpy.polynomial import chebyshev as C
ในการคำนวณรากของพหุนาม ใช้วิธี chebyshev.chebroots() ใน Python Numpy -
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
# To compute the roots of a polynomials, use the chebyshev.chebroots() 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 (roots)...\n",C.chebroots((-j, j)))
# Get the datatype
print("\nType...\n",C.chebroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",C.chebroots((-j, j)).shape) ผลลัพธ์
Result (roots)... [1.+0.j] Type... complex128 Shape... (1,)