Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ประเมินค่าอนุกรมลากูร์ร์ที่รายการจุด x ใน Python

เมธอด polynomial.laguerre.lagval() ใน NumPy ใช้สำหรับประเมินค่าอนุกรมลากูร์ร์ที่จุด x โดย x สามารถเป็นลิสต์ได้ หาก x เป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray อัตโนมัติ

พารามิเตอร์:

  • x: จุดประเมินค่า (ลิสต์ ทูเพิล หรือสเกลาร์)
  • c: อาร์เรย์係ณเรียงตามดีกรี
  • tensor: ควบคุมการ broadcast (ค่าเริ่มต้น True)

ขั้นตอน

นำเข้าไลบรารี:

import numpy as np
from numpy.polynomial import laguerre as L

สร้างอาร์เรย์係ณ 1 มิติ:

c = np.array([1, 2, 3])

แสดงข้อมูลอาร์เรย์:

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 เป็นลิสต์ และประเมินค่า:

x = [5, 10, 15]
print("\nResult...\n", L.lagval(x, c))

ตัวอย่างโค้ดสมบูรณ์

import numpy as np
from numpy.polynomial import laguerre as L

c = np.array([1, 2, 3])
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 = [5, 10, 15]
print("\nResult...\n", L.lagval(x, c))

ผลลัพธ์

Our Array...   [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result...   [ 3.5 76. 223.5]