Jacobian of a Matrix +- HP Forums (http://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Jacobian of a Matrix (/thread-3852.html) |
Jacobian of a Matrix - salvomic - 05-15-2015 03:20 PM hi all, here there is a CAS program to calc the Jacobian of a Matrix. Input: [f(1), f(2), ...], [x,y,...] Enjoy! Salvo Micciché Code:
RE: Jacobian of a Matrix - Rudi - 03-25-2017 09:51 AM 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 RE: Jacobian of a Matrix - Han - 03-25-2017 10:23 AM A slightly shorter program: Code:
Basically, the Jacobian is: transpose(diff([f1,f2,...,fm], [x1,x2,...,xn])) RE: Jacobian of a Matrix - Arno K - 04-09-2018 05:16 PM I improved Han's program a little bit, now you can enter what you desire, with and without substitution: Code: #cas Hope that helps Arno |