Python의 NumPy 라이브러리에서 제공하는 chebyshev.poly2cheb() 메서드를 사용하면 다항식을 체비쇼프 급수(Chebyshev series)로 손쉽게 변환할 수 있습니다. 이 메서드는 최저 차수부터 최고 차수 순으로 정렬된 다항식 계수 배열을 입력받아, 동일한 함수를 나타내는 체비쇼프 급수의 계수 배열(역시 최저 차수부터 최고 차수 순으로 정렬됨)로 변환해 줍니다.
메서드의 반환값은 등가 체비쇼프 급수의 계수를 담고 있는 1차원 배열이며, 매개변수 c는 변환하려는 다항식의 계수를 포함하는 1차원 배열입니다.
변환 절차
1단계: 필요한 라이브러리 임포트
먼저 NumPy와 다항식 모듈을 임포트합니다.
import numpy as np from numpy import polynomial as P
2단계: numpy.array() 메서드로 배열 생성
c = np.array([1, 2, 3, 4, 5])
3단계: 생성한 배열 출력
print("Our Array...\n",c)4단계: 배열의 차원 확인
print("\nDimensions of our Array...\n",c.ndim)5단계: 데이터 타입 확인
print("\nDatatype of our Array object...\n",c.dtype)6단계: 배열의 형태(shape) 확인
print("\nShape of our Array object...\n",c.shape)7단계: poly2cheb() 메서드로 다항식을 체비쇼프 급수로 변환
print("\nResult (polynomial to chebyshev)...\n",P.chebyshev.poly2cheb(c))전체 예제 코드
import numpy as np
from numpy import polynomial as P
# numpy.array() 메서드로 배열 생성
c = np.array([1, 2, 3, 4, 5])
# 배열 출력
print("Our Array...\n",c)
# 차원 확인
print("\nDimensions of our Array...\n",c.ndim)
# 데이터 타입 확인
print("\nDatatype of our Array object...\n",c.dtype)
# 형태(shape) 확인
print("\nShape of our Array object...\n",c.shape)
# chebyshev.poly2cheb() 메서드로 다항식을 체비쇼프 급수로 변환
print("\nResult (polynomial to chebyshev)...\n",P.chebyshev.poly2cheb(c))실행 결과
Our Array...
[1 2 3 4 5]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(5,)
Result (polynomial to chebyshev)...
[4.375 5. 4. 1. 0.625]실행 결과를 보면 원래 다항식 계수 [1, 2, 3, 4, 5]가 체비쇼프 급수 기준의 계수 [4.375, 5., 4., 1., 0.625]로 성공적으로 변환된 것을 확인할 수 있습니다. 이처럼 poly2cheb() 메서드를 활용하면 다항식과 체비쇼프 급수 간의 변환을 간단하게 처리할 수 있습니다.