JACOBIAN - Maple Help

# Online Help

###### All Products    Maple    MapleSim

codegen

 JACOBIAN
 compute the JACOBIAN matrix of a Maple procedure

 Calling Sequence JACOBIAN(F) JACOBIAN(F, X) JACOBIAN(F, X, ...)

Parameters

 F - list of Maple procedures X - list of symbols

Description

 • The first argument F is a list of Maple procedures f1,f2,...,fm which compute functions of x1,x2,...,xn.  The JACOBIAN command outputs a new procedure which when executed at given values for x1,x2,...,xn, returns a matrix J of the partial derivatives at the given values where ${J}_{i,j}=\frac{\partial }{\partial {x}_{j}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{f}_{i}$.  For example, given

 f := proc(x, y) y^2*exp(-x) end proc; g := proc(x, y) x*y*exp(-x) end proc;

 the output of J := JACOBIAN([f,g]); is the procedure

 proc(x, y) local df, dfr0, grd, t1, t2; t1 := y^2; t2 := exp(-x); df := array(1 .. 2); dfr0 := array(1 .. 4); df[2] := t1; df[1] := t2; dfr0[2] := x*y; grd := array(1 .. 2, 1 .. 2); grd[1, 1] := -df[2]*exp(-x); grd[1, 2] := 2*df[1]*y; grd[2, 1] := y*t2 - dfr0[2]*exp(-x); grd[2, 2] := x*t2; return grd end proc

 The J procedure can be optimized by optimize(J). When J is called with inputs $\left(1.0,1.0\right)$, it outputs the matrix

$\left[\begin{array}{cc}-0.3678794412& 0.7357588824\\ 0& 0.3678794412\end{array}\right]$

 • The JACOBIAN code is constructed by applying the joinprocs command to the procedures F then applying the GRADIENT command. The GRADIENT command uses automatic differentiation. See codegen[GRADIENT] for details. The remaining arguments to JACOBIAN are optional, they are described below.
 • By default, JACOBIAN computes the partial derivatives of all procedures in F w.r.t. all the parameters present in F[1]. The optional argument X, a list of symbols, may be used to specify which parameters to take the derivative w.r.t.
 • Two algorithms are supported, the so-called forward and reverse modes. By default, JACOBIAN tries to use the reverse mode since it usually leads to a more efficient code.  If it is unable to use the reverse mode, the forward mode is used.  The user may specify which algorithm is to be used by giving the optional argument mode=forward or mode=reverse.
 • The matrix of partial derivatives is, by default, returned as an array. The optional argument result_type=list, result_type=array, or result_type=seq specifies that the matrix of derivatives returned is to be a Maple list, array, and sequence respectively.
 • The command with(codegen,JACOBIAN) allows the use of the abbreviated form of this command.

Examples

 > $\mathrm{with}\left(\mathrm{codegen}\right):$
 > f := proc(x,y) x*y^2 end proc;
 ${f}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{*}{y}{^}{2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > g := proc(x,y) x^2*y end proc;
 ${g}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{x}{^}{2}{*}{y}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $J≔\mathrm{JACOBIAN}\left(\left[f,g\right]\right)$
 ${J}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{,}{\mathrm{dfr0}}{,}{\mathrm{grd}}{,}{\mathrm{t1}}{,}{\mathrm{t2}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t2}}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{≔}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{dfr0}}{≔}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{[}{1}{]}{≔}{x}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{dfr0}}{[}{2}{]}{≔}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}{≔}{\mathrm{array}}{}\left({1}{..}{2}{,}{1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}{[}{1}{,}{1}{]}{≔}{\mathrm{t1}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}{[}{1}{,}{2}{]}{≔}{2}{*}{\mathrm{df}}{[}{1}{]}{*}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}{[}{2}{,}{1}{]}{≔}{2}{*}{\mathrm{dfr0}}{[}{2}{]}{*}{x}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}{[}{2}{,}{2}{]}{≔}{\mathrm{t2}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{grd}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (3)
 > $\mathrm{print}\left(J\left(x,y\right)\right)$
 $\left[\begin{array}{cc}{{y}}^{{2}}& {2}{}{x}{}{y}\\ {2}{}{x}{}{y}& {{x}}^{{2}}\end{array}\right]$ (4)
 > $J≔\mathrm{JACOBIAN}\left(\left[f,g\right],\mathrm{result_type}=\mathrm{list}\right)$
 ${J}{≔}{\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{,}{\mathrm{dfr0}}{,}{\mathrm{t1}}{,}{\mathrm{t2}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t2}}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{≔}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{dfr0}}{≔}{\mathrm{array}}{}\left({1}{..}{2}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{df}}{[}{1}{]}{≔}{x}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{dfr0}}{[}{2}{]}{≔}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[\left[{\mathrm{t1}}{,}{2}{*}{\mathrm{df}}{[}{1}{]}{*}{y}\right]{,}\left[{2}{*}{\mathrm{dfr0}}{[}{2}{]}{*}{x}{,}{\mathrm{t2}}\right]\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (5)
 > $\mathrm{optimize}\left(J\right)$
 ${\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{,}{\mathrm{t2}}{,}{\mathrm{t4}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t1}}{≔}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t2}}{≔}{x}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{t4}}{≔}{2}{*}{y}{*}{x}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[\left[{\mathrm{t1}}{,}{\mathrm{t4}}\right]{,}\left[{\mathrm{t4}}{,}{\mathrm{t2}}\right]\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (6)
 > $\mathrm{joinprocs}\left(\left[f,g\right],\mathrm{result_type}=\mathrm{list}\right)$
 ${\mathbf{proc}}\left({x}{,}{y}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{,}{\mathrm{resultg}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultf}}{≔}{x}{*}{y}{^}{2}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{resultg}}{≔}{x}{^}{2}{*}{y}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\left[{\mathrm{resultf}}\right]{,}\left[{\mathrm{resultg}}\right]\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (7)

 See Also