1

Let ${\bf A}$ be a symmetric matrix, and I would like to find $\sqrt{\bf A}$ of a $3\times 3$ matrix. I am interested in finding the $\sqrt{\rm A}$ which is equivalent to the "sqrtm" built-in function in python (which is based on the Schur method: LINK).

I found this formulation, $$ \sqrt{\bf A} = \frac{{\bf A} + \sqrt{\operatorname{det}{\bf A}}\ {\tt I}} {\sqrt{\,{\operatorname{tr}\left(\bf A\right) + 2 \sqrt{\,{\operatorname{det}\left(\bf A\right)}\,}}}} $$ in one of the previous posts LINK. This formulation gives the exact results as the sqrtm in python. However, it is valid for ONLY a $2\times2$ matrix.

My question: is there a similar formulation that can be valid for a $3\times3$ matrix?

Many thanks in advance!

Felix Marin
  • 89,464
  • Does $A$ have real entries or complex? If real, are you looking only for $\sqrt{A}$ that have real entries, or could they have complex entries? (I am not familiar with what sqrtm returns.) – 2'5 9'2 Nov 27 '22 at 23:38
  • $A$ has only real entries, and I am looking for only the real entries of $\sqrt{A}$. I just checked out the values returned by sqrtm; it returns real entries, in my case, as well. – I. Mohamed Nov 28 '22 at 02:48
  • In the equation you posted for a 2x2 square root, if $A$ has a negative determinant, then that formula returns something with non-real entries. For example if $A=\begin{bmatrix}1&0\0&-1\end{bmatrix}$, then you get $\frac{1}{\sqrt{2i}}\begin{bmatrix}1+i&0\0&-1+i\end{bmatrix}=\begin{bmatrix}1&0\0&i\end{bmatrix}$. – 2'5 9'2 Nov 28 '22 at 05:42
  • Another thing about that formula is that some care is needed about which $\sqrt{\phantom{x}}$ to use. If $A=-I$, then naively, the numerator (and denominator) of that expression is $0$ so the formula fails. But if we take $\sqrt{\det(-I)}=\sqrt{1}=-1$ (instead of $\sqrt{1}=1$) then it all works out. – 2'5 9'2 Nov 28 '22 at 06:11
  • I agree with you. In my case, all entries are positive and real. Thus, I did not record any failures. – I. Mohamed Nov 28 '22 at 16:31

2 Answers2

1

Your link to the sqrtm method has a link to that function's source.

The algorithm does a Schuur decomposition of $A$, finding $Z$ and $T$ such that $A=ZTZ^*$ with $Z$ unitary and $T$ is upper triangular.

Then it tries to find $\sqrt{T}$ using _sqrtm_triu. This method is for finding the square root of an upper triangular. Once it find that (if it succeeds) it returns $\sqrt{A}$ as $Z\sqrt{T}Z^*$.

So now the question is about how _sqrtm_triu works. Consider that if you know $T$ is upper triangular, then (as long as you allow non-real entries) it is easy to find the diagonal entries of an upper triangular $\sqrt{T}$: they have to be square roots of the diagonal entries of $T$. After these are established, you can solve for the entries of the first off-diagonal. And repeat. I can't think of a nice way to write this in a succinct formula at present.

2'5 9'2
  • 54,717
  • Thanks, @2'5 9'2 for your help; it is really appreciated. I got your point, I have tried what you recommended, but I faced many issues with the implementation on the GPU. For instance, this code LINK gives the same results as sqrtm; however, after converting it to cublas to be compatible with GPU, it does not work. This is the reason behind looking for a formulation like the one I provided in the post, which will be easier to be implemented and will reduce the computational burden (which is a very good factor in our work). – I. Mohamed Nov 28 '22 at 16:44
  • 1
    Hi everyone, many thanks again for your help. I have implemented this formulation Link, and it works perfectly as the one in python. It requires only the calculation of the eigenvalues. – I. Mohamed Dec 12 '22 at 14:44
0

I'm not sure about a formulation for all $3\times 3$ matrices, but we can pretty easily find the square root of diagonalizable matrices. Suppose $$A = \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix} \begin{bmatrix} \lambda_1 & 0 & 0\\ 0 & \lambda_2 & 0\\ 0 & 0 & \lambda_3 \end{bmatrix} \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix}^{-1}$$ For eigenvalues $\lambda_i$ and eigenvectors $v_i$. Then $$\sqrt{A}= \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix} \begin{bmatrix} \sqrt{\lambda_1} & 0 & 0\\ 0 & \sqrt{\lambda_2} & 0\\ 0 & 0 & \sqrt{\lambda_3} \end{bmatrix} \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix}^{-1}$$ since $$\sqrt{A}^2 = \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix} \begin{bmatrix} \sqrt{\lambda_1} & 0 & 0\\ 0 & \sqrt{\lambda_2} & 0\\ 0 & 0 & \sqrt{\lambda_3} \end{bmatrix} \begin{bmatrix} \sqrt{\lambda_1} & 0 & 0\\ 0 & \sqrt{\lambda_2} & 0\\ 0 & 0 & \sqrt{\lambda_3} \end{bmatrix} \begin{bmatrix} \\ v_1 & v_2 & v_3 \\ \\\end{bmatrix}^{-1} = A.$$

Pel34
  • 1
  • Thanks, @Pel34 for your help; it is really appreciated. In fact, I have seen the formulation you posted. Yours requires the calculation of the eigenvalues and eigenvectors. The issue for me is that I need a simple form to be implemented on the GPU. This is the reason behind looking for a formulation like the one I provided in the post. – I. Mohamed Nov 28 '22 at 02:58