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

Chuyển đổi đa thức thành chuỗi Laguerre bằng Python

Để chuyển đổi một đa thức thành một chuỗi Laguerre, hãy sử dụng phương thức laguerre.poly2lag () trong Python Numpy. mức độ cao nhất thấp nhất.

Phương thức trả về mảng 1-D chứa các hệ số của chuỗi Laguerre tương đương. Theparameter pol, là mảng 1-D chứa các hệ số đa thức

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ột mảng bằng phương thức numpy.array () -

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

Hiển thị mảng -

print("Our 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)

Để chuyển đổi một đa thức thành một chuỗi Laguerre, hãy sử dụng phương thức laguerre.poly2lag () trong Python Numpy -

print("\nResult (polynomial to laguerre)...\n",L.poly2lag(c))

Ví dụ

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

# Create an array using the numpy.array() method
c = np.array([1, 2, 3, 4, 5])

# 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 convert a polynomial to a Laguerre series, use the laguerre.poly2lag() method in Python Numpy
print("\nResult (polynomial to laguerre)...\n",L.poly2lag(c))

Đầu ra

Our Array...
   [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result (polynomial to laguerre)...
   [ 153. -566. 798. -504. 120.]