Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 at 12:33
    
Yes @MichaelE2... –  Bravo Jan 16 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 at 12:38
    
@Wojciech: Same equation, but I need the zeros in the other question. Here it is the Jacobian. –  Bravo Jan 16 at 12:39
add comment

1 Answer

Define the elements and the function f:

n=2;
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}]
MatrixForm[%]

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 at 15:40
add comment

Your Answer

 
discard

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.