Post Reply 
Jacobian of a Matrix
03-25-2017, 02:51 PM
Post: #2
RE: Jacobian of a Matrix
hi all,
I've improved the Code of the Jacobian Matrix by salvomic - 15.05.2015 21:20

Enjoy!

Rudi Steeger

For Example:

jacob(grad([e^(x*y^2)*sin(z)],[x,y,z]),[x,y,z]);

The same Example with the new Feature in this Code:
jacob2([e^(x*y^2)*sin(z)],[x,y,z])
==>
[[[y^4*e^(x*y^2)*sin(z)],[2*y*(x*y^2+1)*e^(x*y^2)*sin(z)],[y^2*cos(z)*e^(x*y^2)]],[[2*y*(x*y^2+1)*e^(x*y^2)*sin(z)],[2*x*(2*x*y^2+1)*e^(x*y^2)*sin(z)],[2*x*y*cos(z)*e^(x*y^2)]],[[y^2*cos(z)*e^(x*y^2)],[2*x*y*cos(z)*e^(x*y^2)],[-e^(x*y^2)*sin(z)]]];

Code:
#cas
jacob2(args):=
// Jacobian Matrix by Salvo Micciché
// input vectorial expression, vector of variables
BEGIN
local argv, argc, mat, f, var, fn, fg, j, k, gr, vd;
argv:=args;
argc:=size(argv);
IF argc !=2 THEN
return "Input:[f1(x),f1(y),f1(z)...], [x,y,z,...]";
ELSE
f:=argv(1);
var:=argv(2);
fn:=size(f);
vd:=size(var);
IF fn:=1 THEN
fg:=grad(f(1),var);
f:=fg;
fn:=size(f);
END;
mat:=makemat(0,fn,vd);
FOR j FROM 1 TO fn DO // gradients
gr:=grad(f(j),var);
FOR k FROM 1 TO vd DO // items
mat[j,k]:=factor(gr(k));
END; // for k
END; // for j
return mat;
END; // if-else
END;
#end
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Jacobian of a Matrix - salvomic - 05-15-2015, 08:20 PM
RE: Jacobian of a Matrix - Rudi - 03-25-2017 02:51 PM
RE: Jacobian of a Matrix - Han - 03-25-2017, 03:23 PM
RE: Jacobian of a Matrix - Rudi - 03-26-2017, 11:36 AM
RE: Jacobian of a Matrix - sitomix - 04-09-2018, 12:49 PM
RE: Jacobian of a Matrix - salvomic - 04-09-2018, 03:00 PM
RE: Jacobian of a Matrix - Arno K - 04-15-2018, 10:38 PM
RE: Jacobian of a Matrix - Arno K - 04-09-2018, 10:16 PM



User(s) browsing this thread: 1 Guest(s)