Get explicit formula after matrix derivation with Mathematica

I want to calculate the derivative of a matrix with respect to a vector with mathematica, and I would like to know if it is possible to have a formula as an answer instead of an expanded matrix.

For example, I want to have such answer : $$\frac{d }{dx}x^\top A x= (A+A^\top)x$$

A = {{a11, a12}, {a21, a22}};
x = {{x1}, {x2}};
f = Transpose[x].A.x;


Grad[{{x1 (a11 x1 + a21 x2) + x2 (a12 x1 + a22 x2)}},{{x1}, {x2}}]

• Why do you expect such a result? The formula does not work if, say, A = {{a11 x1, a12}, {a21, a22}}. Mar 10 at 18:04

Try the following:

A = {{a11, a12}, {a21, a22}};
x = {{x1}, {x2}};
xt = Transpose@x;
vars = Variables[x];
f = First @@ (xt . A . x);

lhs = Plus @@ Reverse@Transpose@CoefficientList[Grad[f, vars], vars] . x;

rhs = (A + Transpose@A) . x;

lhs === rhs

(*True*)

• Thank you for your interesting response. However, I am looking to have explicit formulas of which I do not know the result. Mar 10 at 15:27