Computes the matrix of second partial derivatives of f at x
using forward-mode AD. Equivalent to D(f, x, order = 2).
hessian(f, x)A p x p numeric matrix (the Hessian).
f <- function(x) -(x[1] - 3)^2 - (x[2] - 5)^2
hessian(f, c(1, 2)) # diag(c(-2, -2))
#> [,1] [,2]
#> [1,] -2 0
#> [2,] 0 -2