Symbolics.jl with Linear Algebra+derivative

I am trying to use Symbolics.derivative and Linear Algebra. I am confused with how things work and I am stuck with a specific problem that I have reduced to a MWE.

using Symbolics
@variables x A[1:3,1:3]
v=[1,x,x^2]
Symbolics.derivative(A[1:3,1:3]*v,x) # This outputs [0,0,0]
Symbolics.derivative(collect(A[1:3,1:3]*v),x) # This works as I want
Symbolics.derivative(transpose(hcat(v))*A[1:3,1:3]) # This does not work and gives an error

The reason why I also want to multiply a transposed vector in front is that I want to work with quadrics.
However I can’t seem to make it work even with combinations of collect. (They also give an error.)

It works if you scalarize. If you don’t scalarize it gives you an error saying that it cannot currently do array derivatives and tells you to scalarize. The comments you have here are consistent with that.

The easiest thing is probably just to Symbolics.scalarize(A).

We are of course going to work on adding matrix derivatives but until that feature exists this error will be there.

2 Likes