Working matrix square root

I am trying to take the square root of a matrix. This is to find the matrix B, therefore B*B=A. None of the methods I found give a working result.

First I found this formula on Wikipedia :

Set Y_0 = Aand Z_0 = Ithen iteration:

Y_{k+1} = .5*(Y_k + Z_k^{-1}),

Z_{k+1} = .5*(Z_k + Y_k^{-1}).

Then it Yshould converge to B.

However, the implementation of the algorithm in python (using numpy for inverse matrices) gave me garbage results:

>>> def denbev(Y,Z,n):
    if n == 0: return Y,Z
    return denbev(.5*(Y+Z**-1), .5*(Z+Y**-1), n-1)

>>> denbev(matrix('1,2;3,4'), matrix('1,0;0,1'), 3)[0]**2
matrix([[ 1.31969074,  1.85986159],
        [ 2.78979239,  4.10948313]])

>>> denbev(matrix('1,2;3,4'), matrix('1,0;0,1'), 100)[0]**2
matrix([[ 1.44409972,  1.79685675],
        [ 2.69528512,  4.13938485]])

As you can see, a repetition of 100 times gives worse results than three repetitions, and not one of the results falls within the 40% margin of error.

Then I tried the scipy sqrtm method, but it was even worse:

>>> scipy.linalg.sqrtm(matrix('1,2;3,4'))**2
array([[ 0.09090909+0.51425948j,  0.60606061-0.34283965j],
       [ 1.36363636-0.77138922j,  3.09090909+0.51425948j]])

>>> scipy.linalg.sqrtm(matrix('1,2;3,4')**2)
array([[ 1.56669890+0.j,  1.74077656+0.j],
       [ 2.61116484+0.j,  4.17786374+0.j]])

, , , , ?

+3
3

(1) [1,2; 3,4] - , . .

(2) linalg.sqrtm , . , * . , , , .

: :

asmatrix(scipy.linalg.sqrtm(matrix('1,2;3,4')))**2
+7

[1 2; 3 4] , .

+3

, ? , (, ), .

, LU-, . : http://en.wikipedia.org/wiki/Cholesky_decomposition

Another practical example: if your matrices are rotations, you can first decompose the matrix log and simply divide by 2 in the log space, and then return to the rotation with the matrix exponent ... in any case, it seems strange to you that you ask for a β€œcommon square matrix root, "you probably want to understand more about a particular application.

+2
source

Source: https://habr.com/ru/post/1776087/


All Articles