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

Tạo chuỗi Laguerre với nguồn gốc đã cho bằng Python

Để tạo chuỗi Laguerre với các gốc đã cho, hãy sử dụng phương thức laguerre.lagfromosystem () trong PythonNumpy. Phương thức trả về mảng hệ số 1-D. Nếu tất cả các gốc là thực thì out là một mảng thực, nếu một số gốc là phức, thì out là phức ngay cả khi tất cả các hệ số trong kết quả là thực. Các gốc tham số là dãy chứa các gốc.

Các bước

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

from numpy.polynomial import laguerre as L

Để tạo chuỗi Laguerre với các gốc đã cho, hãy sử dụng phương thức laguerre.lagfromosystem () trong Python Numpy -

print("Result...\n",L.lagfromroots((-1,0,1)))

Nhận loại dữ liệu -

print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

Lấy hình dạng -

print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

Ví dụ

from numpy.polynomial import laguerre as L

# To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy.
# The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
print("Result...\n",L.lagfromroots((-1,0,1)))

# Get the datatype
print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

# Get the shape
print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

Đầu ra

Result...
   [ 5. -17. 18. -6.]

Type...
float64

Shape...
(4,)