Learn R Programming

cta (version 1.3.0)

num.deriv.fct: Numerical Derivatives Based on Central Difference Formula

Description

Computes the numerical derivative of the transpose of the vector-valued function \(f\) evaluated at the point \(m\), based on the central difference formula.

If \(f\) is a mapping from \(R^p\) to \(R^q\), then the result is a \(p\)-by-\(q\) matrix. i.e. The result is an approximation to \(\partial f'(m)/\partial m\).

Usage

num.deriv.fct(f.fct, m)

Arguments

f.fct

An R function object that defines a vector-valued function \(f\).

m

A vector, indicating the point \(m\) at which the numerical derivative is to be computed.

Value

num.deriv.fct returns a matrix, which is the numerical derivative of the transpose of the function \(f\) evaluated at \(m\).

Examples

Run this code
# NOT RUN {
# Let x = (x[1], x[2], x[3])', and
# f(x) = (x[1]^3 - 2 * x[2] + 1, sin(x[1] * x[3]), log(x[2] + x[3]))'.
# Approximate d f^{T}(x) / d x  at x = (1, 2, 3)'.
# The true value of the derivative is
# [ 3   3cos(3)    0
#  -2      0      0.2
#   0    cos(3)   0.2] .

f.fct <- function(x) {
  c(x[1]^3 - 2 * x[2] + 1,
    sin(x[1] * x[3]),
    log(x[2] + x[3]))
}
num.deriv.fct(f.fct, c(1, 2, 3))
# }

Run the code above in your browser using DataLab