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

Description Usage Arguments Value Author(s) Examples

View source: R/num.deriv.fct.R

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

1
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.

Author(s)

Joseph B. Lang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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))

cta documentation built on Aug. 24, 2021, 1:06 a.m.