MatSqrt                package:mixAK                R Documentation

_S_q_u_a_r_e _r_o_o_t _o_f _a _m_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     For a matrix A its square root is such a matrix B which satisfies
     A = B B.

     Computation is done using spectral decomposition. When calculating
     the square roots of eigenvalues, always a root with positive real
     part and a sign of the imaginary part the same as the sign of the
     imaginary eigenvalue part is taken.

_U_s_a_g_e:

       MatSqrt(A)

_A_r_g_u_m_e_n_t_s:

       A: either a numeric vector in which case square roots of each
          element of A is returned or a squared matrix.

_V_a_l_u_e:

     Either a numeric vector or a matrix.

_A_u_t_h_o_r(_s):

     Arno&#353t Kom&#225rek arnost.komarek[AT]mff.cuni.cz

_E_x_a_m_p_l_e_s:

     MatSqrt(0:4)
     MatSqrt((-4):0)
     MatSqrt(c(-1, 1, -2, 2))

     A <- (1:4) %*% t(1:4)
     sqrtA <- MatSqrt(A)
     sqrtA
     round(sqrtA %*% sqrtA - A, 13)

     B <- -A
     sqrtB <- MatSqrt(B)
     sqrtB
     round(Re(sqrtB %*% sqrtB - B), 13)
     round(Im(sqrtB %*% sqrtB - B), 13)

     V <- eigen(A)$vectors
     sqrtV <- MatSqrt(V)
     sqrtV
     round(sqrtV %*% sqrtV - V, 14)

     Sigma <- matrix(c(1, 1, 1.5,  1, 4, 4.2,  1.5, 4.2, 9), nrow=3)
     sqrtSigma <- MatSqrt(Sigma)
     sqrtSigma
     round(sqrtSigma %*% sqrtSigma - Sigma, 13)

     D4 <- matrix(c(5, -4,  1,  0,  0,
                   -4,  6, -4,  1,  0,
                    1, -4,  6, -4,  1,
                    0,  1, -4,  6, -4,
                    0,  0,  1, -4,  5), nrow=5)
     sqrtD4 <- MatSqrt(D4)
     sqrtD4[abs(sqrtD4) < 1e-15] <- 0
     sqrtD4
     round(sqrtD4 %*% sqrtD4 - D4, 14)

     X <- matrix(c(7, 15, 10, 22), nrow=2)
     sqrtX <- MatSqrt(X)
     sqrtX %*% sqrtX - X

