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

Python에서 다항식 미분

<시간/>

다항식을 구별하려면 Python Numpy에서 polynomial.polyder() 메서드를 사용합니다. 축을 따라 m번 미분된 다항식 계수 c를 반환합니다. 각 반복에서 결과에 scl이 곱해집니다(스케일링 계수는 변수의 선형 변경에 사용하기 위한 것입니다). 인수 c는 각 축을 따라 낮은 차수에서 높은 차수의 계수 배열입니다. 예를 들어 [1,2,3]은 다항식 1 + 2*x +3*x**2를 나타내는 반면 [[1,2],[1 ,2]]는 axis=0이 x이고 axis=1이 y인 경우 1 + 1*x + 2*y + 2*x*y를 나타냅니다.

이 메서드는 도함수의 다항식 계수를 반환합니다. 첫 번째 매개변수인 c는 다항식 계수의 배열입니다. c가 다차원인 경우 다른 축은 해당 인덱스에 의해 주어진 각 축의 정도를 가진 다른 변수에 해당합니다. 두 번째 매개변수인 m은 취한 도함수의 수이며 음수가 아니어야 합니다. (기본값:1)

세 번째 매개변수는 scl입니다. 각 미분에 scl을 곱합니다. 최종 결과는 곱하기 byscl**m입니다. 이것은 변수의 선형 변화에 사용하기 위한 것입니다. (기본값:1). 네 번째 매개변수는 축입니다. 도함수를 취하는 축입니다. (기본값:0). 결과는 (d/dx)(c) =2 + 6x + 12x**2

입니다.

단계

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

import numpy as np
from numpy.polynomial import polynomial as P

다항식 계수 배열 생성, 즉 1 + 2x + 3x**2 + 4x**3 −

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

계수 배열 표시 -

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)

다항식을 구별하려면 Python Numpy에서 polynomial.polyder() 메서드를 사용하십시오 -

print("\nResult...\n",P.polyder(c))

import numpy as np
from numpy.polynomial import polynomial as P

# Create an array of polynomial coefficients i.e.
# 1 + 2x + 3x**2 + 4x**3
c = np.array([1,2,3,4])

# Display the coefficient array
print("Our coefficient Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To differentiate a polynomial, use the polynomial.polyder() method in Python Numpy.
# Return the polynomial coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl (the scaling factor is for use in a linear change of variable). The argument c is an array of coefficients from low to high degree along each axis, e.g., [1,2,3] represents the polynomial 1 + 2*x + 3*x**2 while [[1,2],[1,2]] represents 1 + 1*x + 2*y + 2*x*y if axis=0 is x and axis=1 is y.

print("\nResult...\n",P.polyder(c))

출력

Our coefficient Array...
   [1 2 3 4]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [ 2. 6. 12.]