Computer >> 컴퓨터 >  >> 프로그래밍 >> Python

Python에서 독립 변수로 라게르(Laguerre) 급수 곱하기

Python에서 라게르(Laguerre) 급수에 독립 변수를 곱하려면 numpy.polynomial.laguerre.lagmulx() 메서드를 사용합니다. 이 메서드는 라게르 급수 c에 독립 변수 x를 곱한 새로운 급수를 반환합니다. 매개변수 c는 낮은 차수부터 높은 차수 순으로 정렬된 라게르 급수 계수를 담은 1차원 배열이며, x를 곱하면 다항식의 차수가 하나 증가하므로 결과 배열의 계수 개수는 원래보다 하나 더 많아집니다.

구현 단계

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

import numpy as np
from numpy.polynomial import laguerre as L

라게르 급수 계수로 사용할 배열을 생성합니다.

c = np.array([1, 2, 3])

생성한 배열을 출력합니다.

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)

lagmulx() 메서드를 사용하여 라게르 급수에 독립 변수 x를 곱합니다.

print("\nResult....\n",L.lagmulx(c))

전체 예제

import numpy as np
from numpy.polynomial import laguerre as L

# 배열 생성
c = np.array([1, 2, 3])

# 배열 출력
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)

# lagmulx() 메서드로 라게르 급수에 독립 변수 x를 곱함
print("\nResult....\n",L.lagmulx(c))

실행 결과

Our Array...
    [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result....
    [-1. -1. 11. -9.]

실행 결과를 보면 입력 계수 [1, 2, 3]에 독립 변수 x를 곱한 값이 라게르 기저에서 [-1., -1., 11., -9.]로 표현됩니다. 곱셈으로 인해 다항식의 차수가 하나 증가했기 때문에 계수 개수도 3개에서 4개로 늘어난 것을 확인할 수 있습니다.