Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Compute the square root of a complex matrix

Hello,

I can't find how to compute the square root of a complex matrix... I tried m.sqrt(), sqrt(m) (display only symbolic sqrt), sqrt(m).n()... None of them work. What is the regular way to compute the root of a complex matrix? (you can assume the matrix is self-adjoint if needed).

Thanks!

def test():
    phi = matrix(CC, [[1/sqrt(2)],[i]])
    m = phi * phi.C.T
    print("Matrix: {}".format(m))
    s = sqrt(m).n() # Does not work: AttributeError: 'ComplexField_class_with_category' object has no attribute 'complex_field'
    #s = m^(1/2) # Does not work either, NotImplementedError: non-integral exponents not supported
    # s = m.sqrt() # Does not work either, no attribute sqrt
    print("Sqrt: {}".format(s))
    print("s*s: {}".format(s*s))
    if s*s == m:
        print("Ok")
    else:
        print("Nope :(")

Compute the square root of a complex matrix

Hello,

I can't find how to compute the square root of a complex matrix... I tried m.sqrt(), sqrt(m) (display only symbolic sqrt), sqrt(m).n()... None of them work. What is the regular way to compute the root of a complex matrix? (you can assume the matrix is self-adjoint if needed).

Thanks!

def test():
    phi = matrix(CC, [[1/sqrt(2)],[i]])
    m = phi * phi.C.T
    print("Matrix: {}".format(m))
    s = sqrt(m).n() # Does not work: AttributeError: 'ComplexField_class_with_category' object has no attribute 'complex_field'
    #s = m^(1/2) # Does not work either, NotImplementedError: non-integral exponents not supported
    # s = m.sqrt() # Does not work either, no attribute sqrt
    print("Sqrt: {}".format(s))
    print("s*s: {}".format(s*s))
    if s*s == m:
        print("Ok")
    else:
        print("Nope :(")

EDIT: For now I'm using the numpy backend with manual diagonalisation, but I'd like to know if there is a better way to proceed...

 phi = matrix(CDF, [[1/sqrt(2)],[i]])
 D, P = m.eigenmatrix_right()
 s = P*diagonal_matrix([sqrt(x) for x in D.diagonal()])*P^-1

Compute the square root of a complex matrix

Hello,

I can't find how to compute the square root of a complex matrix... I tried m.sqrt(), sqrt(m) (display only symbolic sqrt), sqrt(m).n()... None of them work. What is the regular way to compute the root of a complex matrix? (you can assume the matrix is self-adjoint if needed).

Thanks!

def test():
    phi = matrix(CC, [[1/sqrt(2)],[i]])
    m = phi * phi.C.T
    print("Matrix: {}".format(m))
    s = sqrt(m).n() # Does not work: AttributeError: 'ComplexField_class_with_category' object has no attribute 'complex_field'
    #s = m^(1/2) # Does not work either, NotImplementedError: non-integral exponents not supported
    # s = m.sqrt() # Does not work either, no attribute sqrt
    print("Sqrt: {}".format(s))
    print("s*s: {}".format(s*s))
    if s*s == m:
        print("Ok")
    else:
        print("Nope :(")

EDIT: For now I'm using the numpy backend with manual diagonalisation, but I'd like to know if there is a better way to proceed...

 phi = matrix(CDF, [[1/sqrt(2)],[i]])
 D, P = m.eigenmatrix_right()
 s = P*diagonal_matrix([sqrt(x) for x in D.diagonal()])*P^-1