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

การประเมินค่าอนุกรม Laguerre ที่จุด x และขยายรูปร่างสัมประสิทธิ์ตามมิติของ x ใน Python


บทนำ

ในการประเมินค่าอนุกรม Laguerre ที่จุด x โดยขยายรูปร่างของอาเรย์สัมประสิทธิ์สำหรับแต่ละมิติของ x สามารถใช้เมธอด polynomial.laguerre.lagval() พร้อมตั้งค่า tensor=True (ค่าเริ่มต้น) การตั้งค่านี้จะทำให้ทุกคอลัมน์ของสัมประสิทธิ์ใน c ถูกประเมินค่าสำหรับทุกสมาชิกของ x

ขั้นตอนการทำงาน

1. นำเข้าไลบรารี

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

2. สร้างอาเรย์สัมประสิทธิ์แบบหลายมิติ

c = np.arange(8).reshape(2, 4)

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)

4. ประเมินค่าด้วย tensor=True

print("\nResult...\n", L.lagval([1, 2], c, tensor=True))

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

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

# สร้างอาเรย์สัมประสิทธิ์แบบหลายมิติ
c = np.arange(8).reshape(2, 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)

# ประเมินค่าด้วย tensor=True
print("\nResult...\n", L.lagval([1, 2], c, tensor=True))

ผลลัพธ์ที่คาดหวัง

Our Array...   [[0 1 2 3]
                 [4 5 6 7]]
Dimensions of our Array... 2
Datatype of our Array object... int64
Shape of our Array object... (2, 4)
Result...   [[ 0. -4.]
             [ 1. -4.]
             [ 2. -4.]
             [ 3. -4.]]