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

Tính toán gốc của chuỗi Legendre với các gốc phức cho trước bằng Python

Để tính toán gốc của chuỗi Legendre, hãy sử dụng phương thức polynomial.legendre.lagaries () trongPython. Phương thức này trả về một mảng gốc của chuỗi. Nếu tất cả các gốc là thật, thì bên ngoài cũng là thật, nếu không thì phức tạp. Tham số c là mảng hệ số 1-D.

Các bước

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

from numpy.polynomial import legendre as L

Tính toán gốc rễ của chuỗi Legendre -

j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

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

print("\nType...\n",L.legroots((-j, j)).dtype)

Lấy hình dạng -

print("\nShape...\n",L.legroots((-j, j)).shape)

Ví dụ

from numpy.polynomial import legendre as L

# To compute the roots of a Legendre series, use the polynomial.legendre.lagroots() method in Python
# The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex.

# The parameter c is a 1-D array of coefficients.
j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

# Get the datatype
print("\nType...\n",L.legroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",L.legroots((-j, j)).shape)

Đầu ra

Result...
   [1.+0.j]

Type...
complex128

Shape...
(1,)