Contents Previous Next Subchapters

Forward Difference Derivative Approximation
Syntax fordiff(function fxh)
See Also cendiff , coldiff , testder

Description
Returns the forward difference approximation for the Jacobian of f at x, where f is a function such that f(x) returns a column vector with the same type as x, x is a real or double-precision column vector specifying the point at which to approximate the Jacobian of f, and h is a column vector, with the same type and dimension as x, that specifies the step size for approximating partials of f.

A matrix valued function J(x) is the Jacobian of f(x) if the (i,j)-th element of J(x) is the partial of the i-th element of f(x) with respect to the j-th element of x. The return value of fordiff has the same type as x, the same number of rows as f(x), and the same number of columns as x has rows.

If h(j) is 0, partials with respect to x(j) are not approximated, and 0 is returned in the corresponding column of the return value.

The functions fordiff and cendiff can be used to approximate derivatives for both optimization and zero-finding algorithms. The cendiff function is more accurate, but it requires more function evaluations.

Example
The derivative of the function
             2
     f(x) = x

has the value 2 at x = 1. This example approximates this derivative using a forward difference with a .01 step size.

If you enter
     function f(x) begin 
          return x^2
     end
     x    = 1. 
     h    = .01
     print fordiff(function f, x, h)
O-Matrix will respond
     2.01