Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an equation for which I would like to compute the Jacobian symbolically.

$$f(x)=Ax-diag(x)(Ax+b)$$, where $x\in \mathbb{R}^n$, $A\in \mathbb{R}^{n\times n}$ and $b\in \mathbb{R}^n$.

I am new to Mathematica, and I have seen this relevant question, but I am not aware of how to automatically ensure Mathematica recognises the different dimensions. Can someone help me how to code that in Mathematica?

share|improve this question
Just to clarify, are $n$, $A$, and $b$ unknown symbolic constants? – Michael E2 Jan 16 '14 at 12:33
Yes @MichaelE2... – Bravo Jan 16 '14 at 12:37
You posted another question, but formulated the problem differently. I assume it is the same problem in both questions? – Wojciech Jan 16 '14 at 12:38
@Wojciech: Same equation, but I need the zeros in the other question. Here it is the Jacobian. – Bravo Jan 16 '14 at 12:39

Define the elements and the function f:

aMat = Array[a, {n, n}];
xVec = Array[x, n];
bVec = Array[b, n];
f[xVec_] := aMat.xVec - DiagonalMatrix[xVec].(aMat.xVec + bVec);

The Jacobian is:

D[f[xVec], {xVec}]

enter image description here

It seems to work fine for fairly large values of n.

share|improve this answer
just to note the JacobianMatrix defined in the linked answer works fine with these defs JacobianMatrix[f[xVec], xVec] - now what would be really nice is to do this symbolically (i.e. w/o pre defining the matrix terms) – george2079 Jan 16 '14 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.