ในการสร้างชุด Laguerre ด้วยรูทที่กำหนด ให้ใช้เมธอด laguerre.lagfromroots() ใน PythonNumpy วิธีนี้เป็นอาร์เรย์ 1-D ของสัมประสิทธิ์ ถ้ารากทั้งหมดเป็นของจริง ผลลัพธ์ก็คืออาร์เรย์จริง ถ้ารากบางส่วนนั้นซับซ้อน ค่าที่ออกมาจะเป็นจำนวนเชิงซ้อนแม้ว่าสัมประสิทธิ์ทั้งหมดในผลลัพธ์จะเป็นจำนวนจริงก็ตาม รากของพารามิเตอร์คือลำดับที่มีราก
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
from numpy.polynomial import laguerre as L
ในการสร้างชุด Laguerre ด้วยรากที่กำหนด ใช้วิธี laguerre.lagfromroots() -
j = complex(0,1)
print("Result...\n",L.lagfromroots((-j, j))) รับประเภทข้อมูล -
print("\nType...\n",L.lagfromroots((-j, j)).dtype) รับรูปร่าง -
print("\nShape...\n",L.lagfromroots((-j, j)).shape) ตัวอย่าง
from numpy.polynomial import laguerre as L
# To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy.
# The method is a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.
# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",L.lagfromroots((-j, j)))
# Get the datatype
print("\nType...\n",L.lagfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",L.lagfromroots((-j, j)).shape) ผลลัพธ์
Result... [ 3.+0.j -4.+0.j 2.-0.j] Type... complex128 Shape... (3,)