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

อินทิเกรตอนุกรมเลจันเดอร์และตั้งค่าค่าคงที่การอินทิเกรชันใน Python


บทนำ

การอินทิเกรตอนุกรมเลจันเดอร์ใช้เมธอด polynomial.legendre.legint() พารามิเตอร์ k ตั้งค่าค่าคงที่การอินทิเกรชัน (Integration Constant) ค่าของอินทิเกรลแรกที่ lbnd คือค่าแรกในลิสต์ k

พารามิเตอร์

  • c: อาร์เรย์สัมประสิทธิ์อนุกรมเลจันเดอร์
  • m: ออเดอร์การอินทิเกรชัน (Default: 1)
  • k: ค่าคงที่การอินทิเกรชัน (Default: ทั้งหมดเป็นศูนย์) m=1 ให้สเกลาร์เดียวได้
  • lbnd: ขอบเขตล่าง (Default: 0)
  • scl: สเกลาร์ (Default: 1)
  • axis: แกนอินทิเกรชัน (Default: 0)

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

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

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

2. สร้างอาร์เรย์สัมประสิทธิ์

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

3. แสดงอาร์เรย์

print("Our Array...\n", c)

4. ตรวจสอบมิติ

print("\nDimensions of our Array...\n", c.ndim)

5. ตรวจสอบชนิดข้อมูล

print("\nDatatype of our Array object...\n", c.dtype)

6. ตรวจสอบรูปร่าง

print("\nShape of our Array object...\n", c.shape)

7. อินทิเกรตพร้อม k=3

print("\nResult...\n", L.legint(c, k=3))

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

import numpy as np
from numpy.polynomial import legendre 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)
print("\nResult...\n", L.legint(c, k=3))

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

Our Array...   [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result...   [3.33333333 0.4 0.66666667 0.6 ]