Assume a 2x2 matrix U and a simple vector-matrix-vector product. If I calculate the gradient of it like
Grad[{x,y}.U.{x,y},{x,y}]
mathematica returns
{{1,0}.U.{x,y} + {x,y}.U.{{1,0},{0,1}}, {0,1}.U.{x, y} + {x,y}.U.{{1,0},{0,1}}}
which doesn't make sense because of the dimensions of the arrays. It should be
{{1,0}.U.{x,y} + {x,y}.U.{1,0}, {0,1}.U.{x,y} + {x,y}.U.{0,1}}}
Can anyone give me a hint for this unexpected result?
Grad[]has no way of knowing your assumption thatUis a matrix. Have you seen this already? – J. M.'s missing motivation May 12 '20 at 11:40Uis. On the other hand, whatever assumption is used internally regardingU, even if none, shouldn't the second argument in the call ofGrad[], i.e. the list{x,y}, define the outer level of the result, as described in the documentation forGrad[]. – Frank May 12 '20 at 12:42D[{x, y}.U.{x, y}, {{x, y}}]and{D[{x, y}.U.{x, y}, x], D[{x, y}.U.{x, y}, y]}differ. – Frank May 12 '20 at 15:07