This function solves the equation Ax=b for x, when A is a block diagonal sparse matrix (an object of class bdsmatrix).

# S3 method for class 'bdsmatrix'
solve(a, b, full=TRUE, tolerance=1e-10, ...)

Arguments

a

a block diagonal sparse matrix object

b

a numeric vector or matrix, that forms the right-hand side of the equation.

full

if true, return the full inverse matrix; if false return only that portion corresponding to the blocks. This argument is ignored if b is present. If the bdsmatrix a has a non-sparse portion, i.e., if the rmat component is present, then the inverse of a will not be block-diagonal sparse. In this case setting full=F returns only a portion of the inverse. The elements that are returned are those of the full inverse, but the off-diagonal elements that are not returned would not have been zero.

tolerance

the tolerance for detecting singularity in the a matrix

...

other arguments are ignored

Value

if argument b is not present, the inverse of a is returned, otherwise the solution to matrix equation. The equation is solved using a generalized Cholesky decomposition.

Details

The matrix a consists of a block diagonal sparse portion with an optional dense border. The inverse of a, which is to be computed if y is not provided, will have the same block diagonal structure as a only if there is no dense border, otherwise the resulting matrix will not be sparse.

However, these matrices may often be very large, and a non sparse version of one of them will require gigabytes of even terabytes of space. For one of the common computations (degrees of freedom in a penalized model) only those elements of the inverse that correspond to the non-zero part of a are required; the full=F option returns only that portion of the (block diagonal portion of) the inverse matrix.

See also

bdsmatrix, gchol

Examples

tmat <- bdsmatrix(c(3,2,2,4), 
              c(22,1,2,21,3,20,19,4,18,17,5,16,15,6,7, 8,14,9,10,13,11,12),
              matrix(c(1,0,1,1,0,0,1,1,0,1,0,10,0,
                       0,1,1,0,1,1,0,1,1,0,1,0,10), ncol=2))
dim(tmat)
#> [1] 13 13
solve(tmat, cbind(1:13, rep(1,13)))
#>              [,1]        [,2]
#>  [1,] -0.01219425 0.037189721
#>  [2,]  0.03599769 0.037428728
#>  [3,]  0.02852513 0.032808664
#>  [4,]  0.10898346 0.039556695
#>  [5,]  0.18852216 0.042410678
#>  [6,]  0.19492085 0.041051839
#>  [7,]  0.30313564 0.044747545
#>  [8,] -0.10110693 0.026851076
#>  [9,] -0.07807923 0.031178493
#> [10,] -0.07959864 0.031045468
#> [11,]  1.02454712 0.004460442
#> [12,]  1.17522556 0.078780083
#> [13,]  1.17066732 0.078381008