Examples for 'Matrix::Cholesky-class'


Cholesky and Bunch-Kaufman Decompositions

Aliases: Cholesky-class pCholesky-class BunchKaufman-class pBunchKaufman-class show,BunchKaufman-method show,pBunchKaufman-method show,Cholesky-method show,pCholesky-method

Keywords: classes algebra

### ** Examples

(sm <- pack(Matrix(diag(5) + 1))) # dspMatrix
5 x 5 Matrix of class "dspMatrix"
     [,1] [,2] [,3] [,4] [,5]
[1,]    2    1    1    1    1
[2,]    1    2    1    1    1
[3,]    1    1    2    1    1
[4,]    1    1    1    2    1
[5,]    1    1    1    1    2
signif(csm <- chol(sm), 4)
5 x 5 Matrix of class "pCholesky"
     [,1]   [,2]   [,3]   [,4]   [,5]  
[1,] 1.4140 0.7071 0.7071 0.7071 0.7071
[2,]      . 1.2250 0.4082 0.4082 0.4082
[3,]      .      . 1.1550 0.2887 0.2887
[4,]      .      .      . 1.1180 0.2236
[5,]      .      .      .      . 1.0950
(pm <- crossprod(Matrix(rnorm(18), nrow = 6, ncol = 3)))
3 x 3 Matrix of class "dpoMatrix"
           [,1]      [,2]       [,3]
[1,]  2.9508587 -3.139874 -0.9308733
[2,] -3.1398741 10.681652 -4.0600871
[3,] -0.9308733 -4.060087  4.1461200
(ch <- chol(pm))
3 x 3 Matrix of class "Cholesky"
     [,1]       [,2]       [,3]      
[1,]  1.7178064 -1.8278394 -0.5418965
[2,]          .  2.7093643 -1.8641225
[3,]          .          .  0.6144230
if (toupper(ch@uplo) == "U") # which is TRUE
   crossprod(ch)
3 x 3 Matrix of class "dpoMatrix"
           [,1]      [,2]       [,3]
[1,]  2.9508587 -3.139874 -0.9308733
[2,] -3.1398741 10.681652 -4.0600871
[3,] -0.9308733 -4.060087  4.1461200
stopifnot(all.equal(as(crossprod(ch), "matrix"),
                    as(pm, "matrix"), tolerance=1e-14))

[Package Matrix version 1.5-3 Index]