Function jacobian2
Calculate the Jacobian using forward-/backward-difference methods, also known as 2-point formulas.
MatrixView!Real jacobian2(Real, Func)
(
scope Func f,
int m,
Real[] x,
real scale = 1.00000,
Real[] fx = null,
Real[] buffer = null
);
This is less accurate than the central-difference method
used in the jacobian()
function, but requires only half
as many function evaluations. The relative accuracy is,
at best, on the order of sqrt(real
.
Parameters
Name | Description |
---|---|
f | The set of functions. This is typically a function or delegate which takes a vector as input and returns a vector. If the function takes a second vector parameter, this is assumed to be a buffer for the return value, and will be used as such. |
m | The number of functions in f .
|
x | The point at which to take the derivative. |
scale | abs(scale) is the characteristic scale of the
function, and the sign of scale determines which
differentiation method is used. If scale is
negative, the backward difference method is used, and
if it is positive, forward differences are used.
(optional)
|
fx | The result of evaluating the function at the point x .
Providing this saves one function evaluation if you
for some reason have already calculated the value. (optional)
|
buffer | A buffer of length at least m*n, for storing the calculated Jacobian matrix. (optional) |
Examples
// Continuing with the example for the jacobian() function,
// we make it even faster by using a 2-point formula.
auto gp = g(p);
auto jFastest = jacobian2(&g, p, 1.0, gp, buffer, workspace);