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