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

Python에서 주어진 복소수 근을 사용하여 체비쇼프 급수의 근을 계산합니다.

<시간/>

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

근 추정치는 컴패니언 행렬의 고유값으로 얻어지며, 복소 평면의 원점에서 멀리 떨어진 근은 해당 값에 대한 계열의 수치적 불안정성으로 인해 큰 오차를 가질 수 있습니다. 다중도가 1보다 큰 근은 이러한 점 근처의 계열 값이 근의 오류에 상대적으로 둔감하기 때문에 더 큰 오류도 표시합니다. 원점 근처의 고립된 뿌리는 Newton의 방법을 몇 번 반복하여 개선할 수 있습니다.

단계

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

from numpy.polynomial import chebyshev as C

다항식의 근을 계산하려면 Python Numpy에서 chebyshev.chebroots() 메서드를 사용하십시오 -

j = complex(0,1)
print("Result (roots)...\n",C.chebroots((-j, j)))

데이터 유형 가져오기 -

print("\nType...\n",C.chebroots((-j, j)).dtype)

모양 가져오기 -

print("\nShape...\n",C.chebroots((-j, j)).shape)

예시

from numpy.polynomial import chebyshev as C

# To compute the roots of a polynomials, use the chebyshev.chebroots() method in Python Numpy.
# 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 (roots)...\n",C.chebroots((-j, j)))

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

# Get the shape
print("\nShape...\n",C.chebroots((-j, j)).shape)

출력

Result (roots)...
   [1.+0.j]

Type...
complex128

Shape...
(1,)