Diagonal               package:Matrix               R Documentation

_C_r_e_a_t_e _D_i_a_g_o_n_a_l _M_a_t_r_i_x _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     Create a diagonal matrix object, i.e., an object inheriting from
     'diagonalMatrix'.

_U_s_a_g_e:

     Diagonal(n, x = NULL)
     .symDiagonal(n, x = rep.int(1,n), uplo = "U")

_A_r_g_u_m_e_n_t_s:

       n: integer specifying the dimension of the (square) matrix.  If
          missing, 'length(x)' is used.

       x: numeric or logical; if missing, a _unit_ diagonal n x n
          matrix is created.

    uplo: for '.symDiagonal', the resulting sparse 'symmetricMatrix'
          will have slot 'uplo' set from this argument, either '"U"' or
          '"L"'.  Only rarely will it make sense to change this from
          the default.

_V_a_l_u_e:

     'Diagonal()' returns an object of class 'ddiMatrix' or 'ldiMatrix'
     (with "superclass" 'diagonalMatrix').

     '.symDiagonal()' returns an object of class 'dsCMatrix' or
     'lsCMatrix', i.e., a _sparse_ _symmetric_ matrix.  This can be
     more efficient than 'Diagonal(n)' when the result is combined with
     further symmetric (sparse) matrices, however _not_ for matrix
     multiplications where 'Diagonal()' is clearly preferred.

_S_e_e _A_l_s_o:

     the generic function 'diag' for _extraction_ of the diagonal from
     a matrix works for all "Matrices".

     'bandSparse' constructs a _banded_ sparse matrix from its non-zero
     sub-/super - diagonals.

     'Matrix' for general matrix construction; further, class
     'diagonalMatrix'.

_E_x_a_m_p_l_e_s:

     Diagonal(3)
     Diagonal(x = 10^(3:1))
     Diagonal(x = (1:4) >= 2)#-> "ldiMatrix"

     ## Use Diagonal() + kronecker() for "repeated-block" matrices:
     M1 <- Matrix(0+0:5, 2,3)
     (M <- kronecker(Diagonal(3), M1))

     (S <- crossprod(Matrix(rbinom(60, size=1, prob=0.1), 10,6)))
     (SI <- S + 10*.symDiagonal(6)) # sparse symmetric still
     stopifnot(is(SI, "dsCMatrix"))

