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


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] ?

  • 3
    $\begingroup$ 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/… $\endgroup$
    – Szabolcs
    Commented Jan 11, 2017 at 10:26
  • $\begingroup$ @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)? $\endgroup$
    – bonanza
    Commented Jan 11, 2017 at 12:38
  • $\begingroup$ No, I am not very familiar with these kinds of packages. Try searching on packagedata.net $\endgroup$
    – Szabolcs
    Commented Jan 11, 2017 at 12:43
  • $\begingroup$ Just wondering if you ever found a solution for this problem? $\endgroup$
    – oracle3001
    Commented Mar 16, 2017 at 10:35
  • $\begingroup$ @oracle3001 unfortunately no. I suppose its currently not possible with mathematica. $\endgroup$
    – bonanza
    Commented Mar 16, 2017 at 21:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.