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

รวมซีรี่ส์ Legendre บนแกน 1 ใน Python


ในการรวมซีรี่ส์ Legendre ให้ใช้เมธอด polynomial.legendre.legint() ใน Python วิธีการส่งคืนสัมประสิทธิ์ซีรีส์ Legendre c รวม m ครั้งจาก lbnd ตามแนวแกน ในการวนซ้ำแต่ละครั้ง อนุกรมผลลัพธ์จะถูกคูณด้วย scl และค่าคงที่การรวม k ถูกเพิ่มเข้าไป ตัวคูณมาตราส่วนใช้สำหรับการเปลี่ยนแปลงเชิงเส้นของตัวแปร

พารามิเตอร์ที่ 1 c คืออาร์เรย์ของสัมประสิทธิ์อนุกรมตำนาน ถ้า c เป็นพหุมิติ ดิฟเฟอเรนซ์แกนจะสัมพันธ์กับตัวแปรต่างๆ โดยมีระดับในแต่ละแกนที่กำหนดโดยดัชนีที่สอดคล้องกัน พารามิเตอร์ตัวที่ 2 m คือลำดับการรวม ต้องเป็นค่าบวก (ค่าเริ่มต้น:1). พารามิเตอร์ที่ 3 kis ค่าคงที่การรวม ค่าของอินทิกรัลแรกที่ lbnd คือค่าแรกในรายการ ค่าของอินทิกรัลที่สองที่ lbnd คือค่าที่สอง ฯลฯ หาก k ==[] (ค่าเริ่มต้น) ค่าคงที่ทั้งหมดจะถูกตั้งค่าเป็นศูนย์ ถ้า m ==1 สามารถระบุสเกลาร์เดี่ยวแทนรายการได้

พารามิเตอร์ตัวที่ 4 lbnd คือขอบเขตล่างของอินทิกรัล (ค่าเริ่มต้น:0) พารามิเตอร์ที่ 5 scl คือ ascalar หลังจากการผสานรวมแต่ละครั้ง ผลลัพธ์จะถูกคูณด้วย scl ก่อนที่ค่าคงที่การรวมจะถูกเพิ่ม (ค่าเริ่มต้น:1). พารามิเตอร์ที่ 6 แกนคือแกนที่ใช้อินทิกรัล (ค่าเริ่มต้น:0).

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

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

สร้างอาร์เรย์หลายมิติของสัมประสิทธิ์ -

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

แสดงอาร์เรย์ -

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)

ในการรวมซีรี่ส์ Legendre ให้ใช้เมธอด polynomial.legendre.legint() ใน Python -

print("\nResult...\n",L.legint(c, axis = 1))

ตัวอย่าง

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

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To integrate a Legendre series, use the polynomial.legendre.legint() method in Python
print("\nResult...\n",L.legint(c, axis = 1))

ผลลัพธ์

Our Array...
   [[0 1]
   [2 3]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
   [[0.16666667 0. 0.33333333]
   [0.5 2. 1. ]]