반응형

 

미분하는 함수 라이브러리를 사용하기 위해서는 sympy 가 필요하다.

cmd로 다운로드 한다.

pip install sympy

sympy 설치 완료

코드

import math
from sympy import symbols, Limit    # pip install sympy

x, a, h = symbols('x, a, h')

fx = 3 * (x**2) - 4 * x + 1     # 함수 f(x) 정의
fxa = fx.subs({x: a})           # f(x)에 x = a 대입
fxh = fx.subs({x: a + h})       # f(x)에 x = a + h 대입

result = Limit( (fxh - fxa)/h, h, 0 ).doit()     # 극한값(미분계수) 계산

print(fx)
print(fxa)
print(fxh)

print("미분 Result:", result)

 

미분이 잘 되었는가 결과 확인을 위해 미분을 자동으로 해주는 사이트를 이용했다.

www.derivative-calculator.net/

 

Derivative Calculator • With Steps!

Above, enter the function to derive. Differentiation variable and more can be changed in "Options". Click "Go!" to start the derivative calculation. The result will be shown further below. How the Derivative Calculator Works For those with a technical back

www.derivative-calculator.net

아래 함수를 미분하면, 아래와 같은 결과가 나온다.

 

 

(결과) 잘 미분 되었다.

 

반응형

+ Recent posts