เพื่อประเมินค่า (evaluate) อนุกรมลากูร์ร์ (Laguerre series) ที่จุด x ให้ใช้เมธอด polynomial.laguerre.lagval() ใน NumPy
พารามิเตอร์หลัก:
x: จุดที่ต้องการประเมินค่า หากเป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray มิฉะนั้นจะถือเป็นสเกลาร์c: อาร์เรย์ของ係數เรียงตามลำดับดีกรี โดยc[n]เก็บ係數ของพจน์ดีกรี n หากcเป็นหลายมิติ ดัชนีที่เหลือจะนับหลายพหุนามtensor: หากเป็น True (ค่าเริ่มต้น) รูปร่างของอาร์เรย์係ณจะถูกขยายด้วย 1 ด้านขวาสำหรับแต่ละมิติของxทำให้ทุกคอลัมน์ของ係數ถูกประเมินสำหรับทุกสมาชิกของxหากเป็น Falsexจะถูก broadcast ไปยังคอลัมน์ของc
ขั้นตอน
นำเข้าไลบรารี:
import numpy as np from numpy.polynomial import laguerre as L
สร้างอาร์เรย์係ณหลายมิติ:
c = np.array([[1, 2], [3, 4]])
แสดงอาร์เรย์และตรวจสอบคุณสมบัติ:
print("Our Array...\n", c)
print("\nDimensions of our Array...\n", c.ndim)
print("\nDatatype of our Array object...\n", c.dtype)
print("\nShape of our Array object...\n", c.shape)
ประเมินค่าอนุกรมลากูร์ร์ที่จุด x = [1, 2]:
print("\nResult...\n", L.lagval([1, 2], c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import laguerre as L
c = np.array([[1, 2], [3, 4]])
print("Our Array...\n", c)
print("\nDimensions of our Array...\n", c.ndim)
print("\nDatatype of our Array object...\n", c.dtype)
print("\nShape of our Array object...\n", c.shape)
print("\nResult...\n", L.lagval([1, 2], c))
ผลลัพธ์
Our Array... [[1 2] [3 4]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[ 1. -2.] [ 2. -2.]]