R/derivatives.R

Defines functions numGrad numHessian

Documented in numGrad numHessian

#' Create function calculating the numerical gradient
#'
#' @param func Function to get gradient of.
#' @param ... Arguments passed to numDeriv::grad().
#'
#' @return A gradient function
#' @export
#'
#' @examples
#' numGrad(sin)
numGrad <- function(func, ...) {
  function(x) {numDeriv::grad(func=func, x=x, ...)}
}

#' Create function calculating the numerical hessian
#'
#' @param func Function to get hessian of
#' @param ... Arguments passed to numDeriv::hessian().
#'
#' @return A hessian function
#' @export
#'
#' @examples
#' numHessian(sin)
numHessian <- function(func, ...) {
  function(x) {numDeriv::hessian(func=func, x=x, ...)}
}

Try the TestFunctions package in your browser

Any scripts or data that you put into this service are public.

TestFunctions documentation built on May 2, 2019, 2:42 a.m.