0

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?

Frank
  • 1
  • Grad[] has no way of knowing your assumption that U is a matrix. Have you seen this already? – J. M.'s missing motivation May 12 '20 at 11:40
  • Thanks for the fast response. You are right, I don't specify what U is. On the other hand, whatever assumption is used internally regarding U, even if none, shouldn't the second argument in the call of Grad[], i.e. the list {x,y}, define the outer level of the result, as described in the documentation for Grad[]. – Frank May 12 '20 at 12:42
  • There is a related issue using the derivative function. The results of D[{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

0 Answers0