jacobian: Compute the Jacobian of a vector-valued function

View source: R/derivatives.R

jacobianR Documentation

Compute the Jacobian of a vector-valued function

Description

Computes the first derivative of f at x using forward-mode AD. Equivalent to D(f, x). For f: R^p -> R^m, returns an m x p matrix. For scalar-valued f, returns a length-p gradient vector.

Usage

jacobian(f, x)

Arguments

f

A function taking a parameter vector and returning a scalar, list of scalars, or a dual_vector.

x

A numeric vector of parameter values (length p).

Value

An m x p numeric matrix for vector-valued f, or a numeric vector of length p for scalar-valued f.

Examples

f <- function(x) {
  a <- x[1]; b <- x[2]
  list(a * b, a^2, sin(b))
}
jacobian(f, c(2, pi/4))

g <- function(x) x[1]^2 + x[2]^2
jacobian(g, c(3, 4))

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