num_grad: Numerical Gradient

Description Usage Arguments Value Examples

Description

Performs numerical differentiation of a function at a specific point. Uses some numerical tricks to always achieve a reliable, though not necessarily optimal, error.

Usage

1
num_grad(f, x)

Arguments

f

The function for which the gradient is desired.

x

The point at which the gradient should be approximated.

Value

The gradient of the function 'f' at 'x'.

Examples

1
2
3
4
func = function(x) exp(-0.5 * x ^ 2) / sqrt(2 * pi)
grad = function(x) -x * exp(-0.5 * x ^ 2) / sqrt(2 * pi)
num_grad(func, -2)
abs(num_grad(func, -2) - grad(-2))

vsartor/rhmc documentation built on May 10, 2019, 8:27 a.m.