num.deriv.fct {cta}R Documentation

Numerical Derivatives Based on Central Difference Formula

Description

Computes the numerical derivative of the transpose of the vector-valued function ff evaluated at the point mm, based on the central difference formula.

If ff is a mapping from RpR^p to RqR^q, then the result is a pp-by-qq matrix. i.e. The result is an approximation to f(m)/m\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 ff.

m

A vector, indicating the point mm 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 ff evaluated at mm.

Author(s)

Joseph B. Lang

Examples

# 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))

[Package cta version 1.3.0 Index]