forceSymmetric            package:Matrix            R Documentation

_F_o_r_c_e _a _M_a_t_r_i_x _t_o '_s_y_m_m_e_t_r_i_c_M_a_t_r_i_x' _W_i_t_h_o_u_t _S_y_m_m_e_t_r_y _C_h_e_c_k_s

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

     Force 'x' (inheriting from 'Matrix' class) to 'symmetricMatrix',
     *without* a symmetry check (which _is_ applied for all 'as(x,
     "symmetricMatrix")' alikes).

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

     forceSymmetric(x, uplo)

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

       x: a (classed) square matrix.

    uplo: optional string, '"U"' or '"L"'. The default is '"U"' unless
          'x' already has a 'uplo' slot (i.e., when it is
          'symmetricMatrix', or  'triangularMatrix'), where the default
          will be 'x@uplo'.

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

     a square matrix inheriting from class 'symmetricMatrix'.

_S_e_e _A_l_s_o:

     'symmpart' for the symmetric part, or the coercions 'as(x,
     <symmetricMatrix class>)'.

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

      ## Hilbert matrix
      i <- 1:6
      h6 <- 1/outer(i - 1L, i, "+")
      sd <- sqrt(diag(h6))
      hh <- t(h6/sd)/sd # theoretically symmetric
      isSymmetric(hh, tol=0) # FALSE; hence
      try( as(hh, "symmetricMatrix") ) # fails, but this works fine:
      H6 <- forceSymmetric(hh)

      ## result can be pretty surprising:
      (M <- Matrix(1:36, 6))
      forceSymmetric(M) # symmetric, hence very different in lower triangle
      (tm <- tril(M))
      forceSymmetric(tm)

