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 . 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 , it outputs the matrix
|
•
|
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
|
|
>
|
|
>
|
f := proc(x,y) x*y^2 end proc;
|
| (1) |
>
|
g := proc(x,y) x^2*y end proc;
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
|
|