# linear algebra derivative expressions

How do I differentiate $\mathbf{y}=\mathbf{A}\mathbf{x}$ symbolically in sagemath with respect to the vector $\mathbf{x}$? The result is obviously $\mathbf{A}$. Similarly, I would like to be able to calculate the derivative of the quadratic form $\alpha=\mathbf{x}'\mathbf{A}\mathbf{x}$. I would need these calculations in a more complex setting.

I started off with sympy as follows

from sympy import *
n=7
A = MatrixSymbol('A', n, n)
x = MatrixSymbol('x', n, 1)


Or is there a different library from sympy available for such a problem?

edit retag close merge delete

Sort by » oldest newest most voted

I'm out of my depth here, but I'd suggest a look at the Manifolds project, implemented in Sagemath.

more

I assume your matrix A has entries that do not depend on the entries of x? Then with $y=Ax$ you already define $y$ to be a linear function in $x$, so the derivative of $y$ with respect to $x$ is simply $x\mapsto A$.

Similarly, assuming that $A$ a symmetric matrix that is independent of $x$ (otherwise your function doesn't deserve the name quadratic form) you have that the total derivative of $\alpha$ with respect to $x$ is simply $x\mapsto x^t A$.

No computation necessary; just a calculus book.

more

You are right, but I am trying to create a procedure for much more complicated algebraic expressions.

I suspect you have to write things out in explicit variables then. It looks like you basically want to work with a fairly general vector field. I'm not so sure a computer algebra system can help you much with that without you doing some pretty specific preprocessing. The examples you gave are (trivially) resolved. Perhaps a different example closer to what you want to accomplish would help.