hessian: Compute the Hessian of a scalar-valued function

View source: R/derivatives.R

hessianR Documentation

Compute the Hessian of a scalar-valued function

Description

Computes the matrix of second partial derivatives of f at x using forward-mode AD. Equivalent to D(f, x, order = 2).

Usage

hessian(f, x)

Arguments

f

A function taking a parameter vector and returning a scalar.

x

A numeric vector of parameter values.

Value

A p x p numeric matrix (the Hessian).

Examples

f <- function(x) -(x[1] - 3)^2 - (x[2] - 5)^2
hessian(f, c(1, 2))

nabla documentation built on Feb. 11, 2026, 1:06 a.m.