# NOT RUN {
f <- function(y, X, beta) { y - X %*% beta }
finite_diff(
f, wrt = "beta",
at = list(X = matrix(1:4, 2, 2), y = c(2, 3), beta = c(5, 6))
)
g <- function(X, Y) { X %*% Y }
finite_diff(g, at = list(X = randn(2, 2), Y = randn(2, 2)))
h <- function(x) { exp(-x^2) }
finite_diff(h, at = list(x = 0.01), wrt = "x")
finite_diff(h, at = list(x = 0.01), wrt = "x", method = "central")
# }
Run the code above in your browser using DataLab