Symbolic derivatives with vectors and matrices

I'm currently trying to solve some problems using symbolic vectors and matrices of arbitrary size. However, I have some problems with understanding and verifying the results:

I defined the vectors as mentioned here

\$Assumptions = { Element[x, Matrices[{m, 1}, Reals]],
Element[a, Matrices[{m, 1}, Reals]] };


Now I'm trying to compute the gradient (m x 1 matrix) and hessian (m x m matrix) of the function f

f[x_, a_] := Dot[a, x]^2


using

In[144]:= D[f[x, a], x]
Out[144]= 2 a.1 a.x

In[143]:= D[f[x, a], x, Transpose[x]]
Out[143]= 0


What does a.1 mean? is it just a or more like sum[a] ? And why does the second term for the hessian just give 0? Shouldn't it be something like 2*a*Transpose[a] ?

• Derivatives for symbolic tensors are not supported. You would either have to write out components explicitly (which you can't if you don't know m), or use packages that can do this. I would look at NCAlgebra and see if it has support for derivatives. math.ucsd.edu/~ncalg/DOWNLOAD2010/DOCUMENTATION/html/… Commented Jan 11, 2017 at 10:26
• @Szabolcs thanks a lot (also for the sad news ;-) ). I had a look at NCAlgebra but find it very hard to learn/understand the syntax. Do you know further alternatives (even commercial if need be)? Commented Jan 11, 2017 at 12:38
• No, I am not very familiar with these kinds of packages. Try searching on packagedata.net Commented Jan 11, 2017 at 12:43
• Just wondering if you ever found a solution for this problem? Commented Mar 16, 2017 at 10:35
• @oracle3001 unfortunately no. I suppose its currently not possible with mathematica. Commented Mar 16, 2017 at 21:39

Version 14.1 introduced Symbolic Vectors, Matrices and Arrays, which you can also use to calculate symbolic derivatives of vectors and matrices.

x = VectorSymbol["x", m];
a = VectorSymbol["a", m];

D[(a . x)^2, x]
(* 2 VectorSymbol["a", m] . VectorSymbol["x", m] VectorSymbol["a", m] *)


$$2 \vec{a} (\vec{a}\cdot \vec{x})$$

D[(a . x)^2, {x, 2}]
(* 2 SymbolicOnesArray[{m}] \[TensorProduct] VectorSymbol["a", m] *
VectorSymbol["a", m] *)


$$2 \vec{a} (\vec{1}_m\otimes \vec{a})$$