Suppose that a matrix 



M


{\displaystyle M}

 contains complex numbers. Then the conjugate transpose of 



M


{\displaystyle M}

 is a matrix 




M

H




{\displaystyle M^{H}}

 containing the complex conjugates of the matrix transposition of 



M


{\displaystyle M}

.

 



(

M

H



)

j
i


=



M

i
j


¯




{\displaystyle (M^{H})_{ji}={\overline {M_{ij}}}}




This means that row 



j


{\displaystyle j}

, column 



i


{\displaystyle i}

 of the conjugate transpose equals the

complex conjugate of row 



i


{\displaystyle i}

, column 



j


{\displaystyle j}

 of the original matrix.



In the next list, 



M


{\displaystyle M}

 must also be a square matrix.

 A Hermitian matrix equals its own conjugate transpose: 




M

H


=
M


{\displaystyle M^{H}=M}

.
 A normal matrix is commutative in multiplication with its conjugate transpose: 




M

H


M
=
M

M

H




{\displaystyle M^{H}M=MM^{H}}

.
 A unitary matrix has its inverse equal to its conjugate transpose: 




M

H


=

M

−
1




{\displaystyle M^{H}=M^{-1}}

. 
 This is true iff 




M

H


M
=

I

n




{\displaystyle M^{H}M=I_{n}}

 and iff 



M

M

H


=

I

n




{\displaystyle MM^{H}=I_{n}}

, where 




I

n




{\displaystyle I_{n}}

 is the identity matrix.


Task

Given some matrix of complex numbers, find its conjugate transpose.

Also determine if the matrix is a:

 Hermitian matrix,
 normal matrix, or 
 unitary matrix.


See also

 MathWorld entry: conjugate transpose
 MathWorld entry: Hermitian matrix
 MathWorld entry: normal matrix
 MathWorld entry: unitary matrix


-V eps = 1e-10
 
F to_str(m)
   V r = ‘’
   L(row) m
      V i = L.index
      r ‘’= I i == 0 {‘[’} E ‘ ’
      L(val) row
         V j = L.index
         I j != 0
            r ‘’= ‘ ’
         r ‘’= ‘(#2.4, #2.4)’.format(val.real, val.imag)
      r ‘’= I i == m.len - 1 {‘]’} E "\n"
   R r
 
F conjugateTransposed(m)
   V r = [[0i] * m.len] * m.len
   L(i) 0 .< m.len
      L(j) 0 .< m.len
         r[j][i] = conjugate(m[i][j])
   R r
 
F mmul(m1, m2)
   V r = [[0i] * m1.len] * m1.len
   L(i) 0 .< m1.len
      L(j) 0 .< m1.len
         L(k) 0 .< m1.len
            r[i][j] += m1[i][k] * m2[k][j]
   R r
 
F isHermitian(m)
   L(i) 0 .< m.len
      L(j) 0 .< m.len
         I m[i][j] != conjugate(m[j][i])
            R 0B
   R 1B
 
F isEqual(m1, m2)
   L(i) 0 .< m1.len
      L(j) 0 .< m1.len
         I m1[i][j] != m2[i][j]
            R 0B
   R 1B
 
F isNormal(m)
   V h = conjugateTransposed(m)
   R isEqual(mmul(m, h), mmul(h, m))
 
F isIdentity(m)
   L(i) 0 .< m.len
      L(j) 0 .< m.len
         I i == j
            I abs(m[i][j] - 1.0) > :eps
               R 0B
         E
            I abs(m[i][j]) > :eps
               R 0B
   R 1B
 
F isUnitary(m)
   V h = conjugateTransposed(m)
   R isIdentity(mmul(m, h)) & isIdentity(mmul(h, m))
 
F test(m)
   print(‘Matrix’)
   print(‘------’)
   print(to_str(m))
   print(‘’)
   print(‘Conjugate transposed’)
   print(‘--------------------’)
   print(to_str(conjugateTransposed(m)))
   print(‘’)
   print(‘Hermitian: ’(I isHermitian(m) {‘true’} E ‘false’))
   print(‘Normal: ’(I isNormal(m) {‘true’} E ‘false’))
   print(‘Unitary: ’(I isUnitary(m) {‘true’} E ‘false’))
 
V M2 = [[3.0 + 0.0i, 2.0 + 1.0i],
        [2.0 - 1.0i, 1.0 + 0.0i]]
 
V M3 = [[1.0 + 0.0i, 1.0 + 0.0i, 0.0 + 0.0i],
        [0.0 + 0.0i, 1.0 + 0.0i, 1.0 + 0.0i],
        [1.0 + 0.0i, 0.0 + 0.0i, 1.0 + 0.0i]]
 
V SR2 = 1 / sqrt(2.0)
V SR2i = SR2 * 1i
V M4 = [[SR2 + 0.0i, SR2 + 0.0i, 0.0 + 0.0i],
        [0.0 + SR2i, 0.0 - SR2i, 0.0 + 0.0i],
        [0.0 + 0.0i, 0.0 + 0.0i, 0.0 + 1.0i]]
 
test(M2)
print("\n")
test(M3)
print("\n")
test(M4)