Constructs a function to calculate the Jacobian of a function produced
either using sourceCppAD or the composition operator %.%.
The returned function has the same argument signature as f but returns a matrix representing the
Jacobian of f evaluated at the functions arguments. The partial
derivatives are formed with respect to the arguments specified when f was created with sourceCppAD.
In what follows it is assumed that f has a single matrix argument (the
one with which f is differentiated with respect to). When this is not
the case, the other arguments will be considered constant at the point the
Jacobian is evaluated at. Consequently, the structure of the output of
the function produced by J is unchanged by the additional arguments.
The Jacobian matrix \({\bf J}\) is organised as follows.
If \(f:{\bf R}^{n} \rightarrow {\bf R}^{m}\) where \({\bf Y}_{n_{Y}
\times m_{Y}} = f({\bf X}_{n_{X} \times m_{X}})\) and
\(n=n_{X}m_{X}\), \(m=n_{Y}m_{Y}\) then by numbering the elements of
the matrices row-wise so that,
$$
{\bf Y} =
\left[
\begin{array}{ccc}
y_{1} & \dots & y_{m_{Y}} \\
y_{m_{Y}+1} & \dots & y_{2m_{Y}} \\
\vdots & \ddots & \vdots \\
y_{(n_{Y}-1)m_{Y}+1} & \dots & y_{n_{Y}m_{Y}}
\end{array}
\right]
$$
and
$$
{\bf X} =
\left[
\begin{array}{ccc}
x_{1} & \dots & x_{m_{X}} \\
x_{m_{X}+1} & \dots & x_{2m_{X}} \\
\vdots & \ddots & \vdots \\
x_{(n_{X}-1)m_{X}+1} & \dots & x_{n_{X}m_{X}}
\end{array}
\right]
$$
then the \(m \times n\) Jacobian matrix is given by
$$
\begingroup
\renewcommand*{\arraystretch}{1.5}
{\bf J} =
\left[ \begin{array}{ccc}
\frac{\partial y_{1}}{\partial x_1} & \dots & \frac{\partial y_{1}}{\partial x_n} \\
\vdots & \ddots & \vdots \\
\frac{\partial y_{m}}{\partial x_1} & \dots & \frac{\partial y_{m}}{\partial x_n}
\end{array} \right]
\endgroup
$$