Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 주어진 복소수 근을 사용하여 르장드르 급수의 근을 계산합니다.

<시간/>

Legendre 계열의 근을 계산하려면 Python에서 polynomial.legendre.lagroots() 메서드를 사용합니다. 이 메서드는 계열의 루트 배열을 반환합니다. 모든 근이 실수이면 out도 실수이고, 그렇지 않으면 복소수입니다. 매개변수 c는 계수의 1차원 배열입니다.

단계

먼저 필요한 라이브러리를 가져옵니다 -

from numpy.polynomial import legendre as L

르장드르 급수의 근을 계산 -

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

데이터 유형 가져오기 -

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

모양 가져오기 -

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

예시

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)

출력

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

Type...
complex128

Shape...
(1,)