ในการสร้างซีรีส์ Legendre ให้ใช้เมธอด polynomial.legendre.legfromroots() ใน Python วิธีการส่งคืนอาร์เรย์ 1-D ของสัมประสิทธิ์ ถ้ารากทั้งหมดเป็นของจริง ผลลัพธ์ก็คืออาร์เรย์จริง ถ้ารากบางส่วนนั้นซับซ้อน ค่าที่ออกมาจะซับซ้อนแม้ว่าสัมประสิทธิ์ทั้งหมดในผลลัพธ์จะเป็นจำนวนจริงก็ตาม รากของพารามิเตอร์คือลำดับที่มีราก
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np from numpy.polynomial import legendre as L
ในการสร้างซีรีย์ Legendre ให้ใช้เมธอด polynomial.legendre.legfromroots() ใน Python -
print("Result...\n",L.legfromroots((-1,0,1))) รับประเภทข้อมูล -
print("\nType...\n",L.legfromroots((-1,0,1)).dtype) รับรูปร่าง -
print("\nShape...\n",L.legfromroots((-1,0,1)).shape)
ตัวอย่าง
import numpy as np
from numpy.polynomial import legendre as L
# To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python
print("Result...\n",L.legfromroots((-1,0,1)))
# Get the datatype
print("\nType...\n",L.legfromroots((-1,0,1)).dtype)
# Get the shape
print("\nShape...\n",L.legfromroots((-1,0,1)).shape) ผลลัพธ์
Result... [ 0. -0.4 0. 0.4] Type... float64 Shape... (4,)