Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.5K Views
|
8 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Jacobian matrix of two functions

Posted 9 months ago

Greetings --

Apologies if this is posted to the wrong forum. Have been using Maple and Maxima for 20+ years, and have only recently started using Mathematica (v. 14). Having a heck of a time getting Mathematica to do what is trivial in either Maple or Maxima (not a slam on Mathematica - just an honest statement of where I am on the learning curve). Simple example: 2 equations in 2 unknowns (say, x1 and x2). Want to derive the Jacobian of these equations wrt x1 and x2, and print said Jacobian in matrix form. This is basically 3-4 lines in Maple or Maxima. But in Mathematica? Here is what I've tried.

  (*Define the functions*)
  f1[x1_, x2_] := x1^2 + x2^2
  f2[x1_, x2_] := x1 x2

  (*Compute the Jacobian matrix with respect to x1 and x2*)
  jacobian = JacobianMatrix[{f1[x1, x2], f2[x1, x2]}, {x1, x2}]

  (*Display the Jacobian matrix*) 
  MatrixForm[jacobian]

But, the final command to display the Jacobian returns nada of any use. It simply returns the following:

  JacobianMatrix[{x1^2+x2^2,x1x2},{x1,x2}]

So, how the heck do I get Mathematica to output what Maple (for example - same code more or less in Maxima) outputs in one command, looking like what I expect (i.e., the formatted Jacobian matrix, below):

enter image description here

Many thanks in advance. I was warned the learning curve for Mathematica was appreciably steeper than (say) Maple, but I wasn't expected even something this simple to stump me quite so soon.

POSTED BY: Evan Cooch
8 Replies

You can simulate the Maple syntax quite easily:

f1 = x1^2 + x2^2;
f2 = x1*x2;
jac = D[{f1, f2}, {{x1, x2}}];
MatrixForm[jac]

The only notable difference is the display of the matrix.

POSTED BY: Gianluca Gorni
Posted 9 months ago

I don't know where you came across the symbol JacobianMatrix, but I don't think that's a built in symbol. You can just use the normal derivative.

D[{x1^2 + x2^2, x1 x2}, {{x1, x2}}]
(* {{2 x1, 2 x2}, {x2, x1}} *)

And just let me say proactively, that MatrixForm is only for display (which is fine for what you have so far), so don't try to compute further with that specific form.

POSTED BY: Eric Rimbey
Posted 9 months ago

Oh, if it's a resource function, then just "fetch" it from the resource repository.

f1[x1_, x2_] := x1^2 + x2^2;
f2[x1_, x2_] := x1 x2;
ResourceFunction["JacobianMatrix"][{f1[x1, x2], f2[x1, x2]}, {x1, x2}]
(* {{2 x1, 2 x2}, {x2, x1}} *)

If you don't like typing all of that each time, you can define a symbol for it:

myJacobian = ResourceFunction["JacobianMatrix"];
myJacobian[{f1[x1, x2], f2[x1, x2]}, {x1, x2}]

But I don't really see what's so cumbersome about just using the built in D symbol.

D[{f1[x1, x2], f2[x1, x2]}, {{x1, x2}}]
POSTED BY: Eric Rimbey
Posted 9 months ago
POSTED BY: Eric Rimbey
(* Define the functions *)
f1[x1_, x2_] := x1^2 + x2^2 f2[x1_, x2_] := x1 x2
(* Compute the Jacobian matrix with respect to x1 and x2 *)
jacobian = D[{f1[x1, x2], f2[x1, x2]}, {{x1, x2}}]
(* Display the Jacobian matrix *)
MatrixForm[jacobian]
POSTED BY: kaylene ginny
POSTED BY: Michael Rogers
Posted 9 months ago

Following works - but having to figure out/remember "ResourceFunction" is clunky...and I'm still nt entirely sure I know what a 'resource function' is.

f1 = (x1)^2+(x2)^2
f2 = (x1)*(x2)
jac = ResourceFunction["JacobianMatrix"][{f1,f2},{x1,x2}]
MatrixForm[jac]   

Compare this to (say) Maxima (lest someone think I'm only trolling a comparison of Maple and Mathematica) -- note that Maxima by default outputs each step, properly formatted so that it actually looks like math (still have no idea how to get Mathematica to do that).

enter image description here

POSTED BY: Evan Cooch
Posted 9 months ago

Simple - JacobianMatrix (or equivalent) is baked in to Maple, Maxima, MATLAB, and every other CAS or CAS-like environment I've used. And, it is in Mathematica, but apparently it is something called a 'Resource Function' (no idea what that is). See below:

enter image description here

What you suggested works, but it is cumbersome for large sets of equations.

POSTED BY: Evan Cooch
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard