Computer >> Máy Tính >  >> Lập trình >> Python

Nâng tầm sê-ri Legendre lên thành sức mạnh bằng Python

Để nâng chuỗi Legendre lên thành lũy thừa, hãy sử dụng phương thức polynomial.legendre.legpow () trong PythonNumpy. Phương thức này trả về chuỗi Legendre c được nâng lên thành power pow. Đối số c là một dãy các hệ số được sắp xếp từ thấp đến cao. tức là, [1,2,3] là chuỗi P_0 + 2 * P_1 + 3 * P_2. Quay lại chuỗi Legendre c được nâng lên thành lũy thừa. Đối số c là một chuỗi các hệ số được sắp xếp từ thấp đến cao. tức là [1,2,3] là chuỗi P_0 + 2 * P_1 + 3 * P_2.

Tham số, c là mảng 1-D gồm các hệ số của chuỗi Legendre được sắp xếp từ thấp đến cao. Theparameter, pow là Công suất mà chuỗi sẽ được nâng lên. Tham số, maxpower là công suất tối đa cho phép. Điều này chủ yếu là để hạn chế sự phát triển của chuỗi đến kích thước không thể quản lý được. Defaultis 16

Các bước

Đầu tiên, hãy nhập thư viện được yêu cầu -

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

Tạo mảng 1-D gồm các hệ số chuỗi Laguerre -

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

Hiển thị mảng hệ số -

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

Kiểm tra các thứ nguyên -

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

Lấy Datatype -

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

Lấy hình dạng -

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

Để nâng chuỗi Legendre lên thành lũy thừa, hãy sử dụng phương thức polynomial.legendre.legpow () trong PythonNumpy -

print("\nResult....\n",L.legpow(c, 3))

Ví dụ

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

# Create 1-D arrays of Laguerre series coefficients
c = np.array([1,2,3])

# Display the coefficient array
print("Our coefficient 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 raise a Legendre series to a power, use the polynomial.legendre.legpow() method in Python Numpy
# The method returns the Legendre series c raised to the power pow. The argument c is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series P_0 + 2*P_1 + 3*P_2.
print("\nResult....\n",L.legpow(c, 3))

Đầu ra

Our coefficient Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result....
   [16.74285714 42.17142857 55.14285714 46.4 33.8025974 15.42857143 6.31168831]