# Symbolic diagonalization, matrix differentiation and the wedge product

May I ask whether symbolic entry-wise differentiation of matrices can be done using SageMath? I would like to conduct the following operations:

1.Diagonalize a complicated symbolic matrix.

2.Entry-wise differentiation.

3.The wedge product. I need to be able to take the n-th power of a matrix of 1-forms.

4.Integration (I will take the trace first before integrations so integrations will not be done on matrices. The result is likely to be completely crazy but I assume this can be done)

Please let me know whether this is possible. Thank you very much!

edit retag close merge delete

yes, in pple all this can be done in Sage! of course in practice it'll depend on the complexity of your problem :) for entrywise differentiation, see my answer below for some hints. for point 3, it could be relevant to check this question. and let me add that you may get better answers in this site if you include some code with attempts / a concrete example.

( 2017-02-12 18:18:15 +0200 )edit

Sort by » oldest newest most voted

The apply_map method is a handy command for entrywise operations. For instance, let

A = matrix([[sin(x), cos(x)],[cos(x), -sin(x)]]);  # define a matrix function of x
A


$$\begin{pmatrix} \sin\left(x\right) & \cos\left(x\right) \\ \cos\left(x\right) & -\sin\left(x\right) \end{pmatrix}.$$

Let's compute the entrywise derivative with apply_map:

A.apply_map(lambda a : a.derivative(x))


$$\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} \cos\left(x\right) & -\sin\left(x\right) \\ -\sin\left(x\right) & -\cos\left(x\right) \end{array}\right),$$

and the Jordan canonical form

A.jordan_form()


$$\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r|r} -\sqrt{\cos\left(x\right)^{2} + \sin\left(x\right)^{2}} & 0 \\ \hline 0 & \sqrt{\cos\left(x\right)^{2} + \sin\left(x\right)^{2}} \end{array}\right).$$

Another small example, this time with symbolic functions:

var('x y')
m=2; n=4

# create a mxn matrix of symbolic functions in x and y
F = matrix([[function('f'+str(i)+str(j))(x, y) for j in [1..n]] for i in [1..m]]);
F


$$\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr} f_{11}\left(x, y\right) & f_{12}\left(x, y\right) & f_{13}\left(x, y\right) & f_{14}\left(x, y\right) \\ f_{21}\left(x, y\right) & f_{22}\left(x, y\right) & f_{23}\left(x, y\right) & f_{24}\left(x, y\right) \end{array}\right).$$

Now, let's ask for the entrywise integral with respect to $y$ of the 2nd derivative with respect to $x$:

F.apply_map(lambda f : (f.derivative(x, 2)).integrate(y))


$$\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr} \int \frac{\partial^{2}}{(\partial x)^{2}}f_{11}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{12}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{13}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{14}\left(x, y\right)\,{d y} \\ \int \frac{\partial^{2}}{(\partial x)^{2}}f_{21}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{22}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{23}\left(x, y\right)\,{d y} & \int \frac{\partial^{2}}{(\partial x)^{2}}f_{24}\left(x, y\right)\,{d y} \end{array}\right).$$

more