Divide and Conquer
수치미분 numerical differentiation 본문
728x90
- 수치 미분(numerical differentiation)을 수행하는 경우
- 주어진 함수가 매우 복잡하여 미분을 얻기가 어려운 경우
- 데이터에 대한 미분을 구해야 하는 경우
1차 미분 공식 |
2차 미분 공식 | ||
전방 차분 공식 | 후방 차분 공식 | 중앙 차분 공식 | |
![]() |
![]() |
전방테일러급수 - 후방테일러급수 |
전방테일러급수 + 후방테일러급수 |
![]() |
![]() |
![]() |
![]() |
def f(x):
return x**3 - 2.0*x**2 + 3*x - 1.0
# 1차 미분
def fordiff(f, x, h):
diff = (f(x+h) - f(x)) /h
return diff
def backdiff(f, x, h):
diff = (f(x) - f(x-h)) / h
return diff
def centdiff(f, x, h):
diff = (f(x+h) - f(x-h)) / (2.0*h)
return diff
# 2차 미분
def ddiff(f, x, h):
diff = (f(x+h) - 2.0*f(x) + f(x-h)) / h**2
return diff
h = 0.25 # 차분의 간격
x = 0.5
fdiff = fordiff(f, x, h)
bdiff = backdiff(f, x, h)
cdiff = centdiff(f, x, h)
diff = ddiff(f, x, h)
print(f'Forward difference = \t{fdiff:8.4f}')
print(f'Backward difference = \t{bdiff:8.4f}')
print(f'Central difference = \t{cdiff:8.4f}')
print(f'dfdx2 = {diff:8.4f}')
반응형
'성장캐 > 수치해석' 카테고리의 다른 글
반복법(Jacobi 방법, Gauss-Seidel 방법) (0) | 2022.06.21 |
---|---|
LU 분해 LU decomposition (0) | 2022.06.21 |
Gauss 소거법 Gauss Elimination (0) | 2022.04.25 |
선형 연립방정식의 해법 (0) | 2022.04.25 |
할선법 Secant Method (0) | 2022.04.25 |
Comments