Universitas : UIN Maulana Malik Ibrahim Malang
Prodi : Teknik Informatika
Fakultas : Sains dan Teknologi
Dosen : Prof. Dr. SUHARTONO, M.Kom
Numerical differentiation is a technique to approximate derivatives of functions when an analytical expression for the derivative is not available.
# Function for which we want to find the derivative
f <- function(x) x^2 + 2*x + 1
# Finite difference method for numerical differentiation
finite_difference <- function(f, x, h = 1e-6) {
(f(x + h) - f(x)) / h
}
# Point at which to find the derivative
x_value <- 2
# Compute the numerical derivative
numerical_derivative <- finite_difference(f, x_value)
numerical_derivative
## [1] 6.000001
central_difference <- function(f, x, h = 1e-6) {
(f(x + h) - f(x - h)) / (2 * h)
}
# Compute the numerical derivative using central difference
numerical_derivative_central <- central_difference(f, x_value)
numerical_derivative_central
## [1] 6