codegen
JACOBIAN
compute the JACOBIAN matrix of a Maple procedure
Calling Sequence
Parameters
Description
Examples
JACOBIAN(F)
JACOBIAN(F, X)
JACOBIAN(F, X, ...)
F
-
list of Maple procedures
X
list of symbols
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 Ji,j=∂∂xjfi. 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 1.0,1.0, it outputs the matrix
−0.36787944120.735758882400.3678794412
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.
with⁡codegen:
f := proc(x,y) x*y^2 end proc;
f ≔ procx,yx*y^2end proc
g := proc(x,y) x^2*y end proc;
g ≔ procx,yx^2*yend proc
J≔JACOBIAN⁡f,g
J ≔ procx,ylocaldf,dfr0,grd,t1,t2;t1 ≔ y^2;t2 ≔ x^2;df ≔ array⁡1..2;dfr0 ≔ array⁡1..2;df[1] ≔ x;dfr0[2] ≔ y;grd ≔ array⁡1..2,1..2;grd[1,1] ≔ t1;grd[1,2] ≔ 2*df[1]*y;grd[2,1] ≔ 2*dfr0[2]*x;grd[2,2] ≔ t2;returngrdend proc
print⁡J⁡x,y
y22⁢x⁢y2⁢x⁢yx2
J≔JACOBIAN⁡f,g,result_type=list
J ≔ procx,ylocaldf,dfr0,t1,t2;t1 ≔ y^2;t2 ≔ x^2;df ≔ array⁡1..2;dfr0 ≔ array⁡1..2;df[1] ≔ x;dfr0[2] ≔ y;returnt1,2*df[1]*y,2*dfr0[2]*x,t2end proc
optimize⁡J
procx,ylocalt1,t2,t4;t1 ≔ y^2;t2 ≔ x^2;t4 ≔ 2*y*x;t1,t4,t4,t2end proc
joinprocs⁡f,g,result_type=list
procx,ylocalresultf,resultg;resultf ≔ x*y^2;resultg ≔ x^2*y;returnresultf,resultgend proc
See Also
codegen[GRADIENT]
codegen[joinprocs]
codegen[optimize]
Download Help Document