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

สร้างความแตกต่างให้กับซีรีย์ Legendre ใน Python


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

พารามิเตอร์ตัวที่ 2 m คือจำนวนอนุพันธ์ที่นำมาต้องไม่เป็นค่าลบ (ค่าเริ่มต้น:1). พารามิเตอร์ตัวที่ 3 scl คือสเกลาร์ ดิฟเฟอเรนติเอชันแต่ละตัวคูณด้วย scl ผลลัพธ์ที่ได้คือการคูณด้วย scl**m ใช้สำหรับการเปลี่ยนแปลงเชิงเส้นของตัวแปร (ค่าเริ่มต้น:1). พารามิเตอร์ที่ 4 แกนคือ anAxis ที่นำอนุพันธ์มา (ค่าเริ่มต้น:0).

ขั้นตอน

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

import numpy as np
from numpy.polynomial import legendre 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)

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

print("\nResult...\n",L.legder(c))

ตัวอย่าง

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

# Create an array of coefficients
c = np.array([1,2,3,4])

# 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 differentiate a Legendre series, use the polynomial.laguerre.legder() method in Python
print("\nResult...\n",L.legder(c))

ผลลัพธ์

Our Array...
   [1 2 3 4]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [ 6. 9. 20.]