문제 4 · 실습 — 미분 수치검증
해석적 도함수
python
import numpy as np
def f(x):
return x**np.sin(x)
def fprime(x): # 해석적 도함수
return x**np.sin(x) * (np.cos(x)*np.log(x) + np.sin(x)/x)
x, h = 1.7, 1e-6
numeric = (f(x + h) - f(x - h)) / (2*h)
print(f"해석적 f'({x}) = {fprime(x):.8f}")
print(f"수치적 f'({x}) = {numeric:.8f}")