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

Python에서 주어진 복잡한 근을 가진 Legendre 시리즈 생성

<시간/>

르장드르 시리즈를 생성하려면 Python에서 polynomial.legendre.legfromroots() 메서드를 사용합니다. 이 메서드는 계수의 1차원 배열을 반환합니다. 모든 근이 실수이면 out은 실수 배열이고, 일부 근이 복소수이면 결과의 모든 계수가 실수인 경우에도 out은 복소수입니다. 매개변수 루트는 루트를 포함하는 시퀀스입니다.

단계

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

from numpy.polynomial import legendre as L

Python에서 polynomial.legendre.legfromroots() 메서드를 사용하여 르장드르 시리즈 생성 -

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

데이터 유형 가져오기 -

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

모양 가져오기 -

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

예시

from numpy.polynomial import legendre as L

# To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python
j = complex(0,1)
print("Result...\n",L.legfromroots((-j, j)))

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

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

출력

Result...
   [1.33333333+0.j 0. +0.j 0.66666667+0.j]

Type...
complex128

Shape...
(3,)