체비쇼프 급수의 거듭제곱 계산
파이썬 NumPy에서 체비쇼프(Chebyshev) 급수를 거듭제곱하려면 numpy.polynomial.chebyshev 모듈의 chebpow() 메서드를 사용하면 됩니다. 이 메서드는 체비쇼프 급수 c를 pow 거듭제곱한 결과를 다시 체비쇼프 급수 형태로 반환합니다.
인자 c는 낮은 차수부터 높은 차수 순으로 정렬된 계수의 시퀀스입니다. 예를 들어 [1, 2, 3]은 T0 + 2·T1 + 3·T2에 해당하는 급수를 의미합니다.
주요 매개변수
- c : 체비쇼프 급수의 계수를 담은 1차원 배열로, 낮은 차수에서 높은 차수 순으로 정렬됩니다.
- pow : 급수를 거듭제곱할 지수 값입니다.
- maxpower : 허용되는 최대 지수입니다. 급수가 감당하기 어려운 크기로 커지는 것을 방지하기 위한 제한값이며, 기본값은 16입니다. 이 값을 초과하면 ValueError가 발생합니다.
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np from numpy.polynomial import chebyshev as C
체비쇼프 급수의 계수를 담은 1차원 배열을 생성합니다.
c = np.array([1,2,3])
생성한 계수 배열을 출력해 확인합니다.
print("Our coefficient 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)
이제 chebpow() 메서드를 사용해 체비쇼프 급수를 3제곱합니다.
print("\nResult...\n",C.chebpow(c,3))
전체 예제 코드
import numpy as np
from numpy.polynomial import chebyshev as C
# 체비쇼프 급수 계수로 구성된 1차원 배열 생성
c = np.array([1,2,3])
# 계수 배열 출력
print("Our coefficient Array...\n",c)
# 차원 확인
print("\nDimensions of our Array...\n",c.ndim)
# 데이터 타입 확인
print("\nDatatype of our Array object...\n",c.dtype)
# 형태 확인
print("\nShape of our Array object...\n",c.shape)
# chebpow() 메서드로 체비쇼프 급수를 3제곱
print("\nResult...\n",C.chebpow(c,3))
실행 결과
Our coefficient Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [29.5 57. 53.25 33.5 22.5 13.5 6.75]
실행 결과를 보면 차수가 2인 원래 급수를 3제곱했기 때문에 결과 급수의 차수는 6이 되고, 그에 따라 계수의 개수도 3개에서 7개로 늘어난 것을 확인할 수 있습니다. 참고로 지정한 지수가 maxpower(기본값 16)를 초과하면 에러가 발생하므로, 큰 지수를 다룰 때는 이 점에 유의해야 합니다.