Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nl.grad

Numerical Gradients and Jacobians


Description

Provides numerical gradients and jacobians.

Usage

nl.grad(x0, fn, heps = .Machine$double.eps^(1/3), ...)

Arguments

x0

point as a vector where the gradient is to be calculated.

fn

scalar function of one or several variables.

heps

step size to be used.

...

additional arguments passed to the function.

Details

Both functions apply the “central difference formula” with step size as recommended in the literature.

Value

grad returns the gradient as a vector; jacobian returns the Jacobian as a matrix of usual dimensions.

Author(s)

Hans W. Borchers

Examples

fn1 <- function(x) sum(x^2)
  nl.grad(seq(0, 1, by = 0.2), fn1)
  ## [1] 0.0  0.4  0.8  1.2  1.6  2.0
  nl.grad(rep(1, 5), fn1)
  ## [1] 2  2  2  2  2

  fn2 <- function(x) c(sin(x), cos(x))
  x <- (0:1)*2*pi
  nl.jacobian(x, fn2)
  ##      [,1] [,2]
  ## [1,]    1    0
  ## [2,]    0    1
  ## [3,]    0    0
  ## [4,]    0    0

nloptr

R Interface to NLopt

v1.2.2.2
LGPL-3
Authors
Jelmer Ypma [aut, cre], Steven G. Johnson [aut] (author of the NLopt C library), Hans W. Borchers [ctb], Dirk Eddelbuettel [ctb], Brian Ripley [ctb] (build process on multiple OS), Kurt Hornik [ctb] (build process on multiple OS), Julien Chiquet [ctb], Avraham Adler [ctb] (removal deprecated calls from tests, <https://orcid.org/0000-0002-3039-0703>)
Initial release
2020-07-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.