solve.gchol(a, b, full=T)
gchol
function.
b
is not present, the inverse of
a
is returned, otherwise the solution to
matrix equation.
A symmetric matrix A can be decomposed as LDL', where L is a lower
triangular matrix with 1's on the diagonal, L' is the transpose of
L, and D is diagonal.
This routine solves either the original problem Ay=b
(
full
argument) or the subproblem sqrt(D)L'y=b.
If
b
is missing it returns the inverse of
A or L, respectively.
# Create a matrix that is symmetric, but not positive definite # The matrix temp has column 6 redundant with cols 1-5 smat <- matrix(1:64, ncol=8) smat <- smat + t(smat) + diag(rep(20,8)) # smat is 8x8 symmetric temp <- smat[c(1:5, 5:8), c(1:5, 5:8)] ch1 <- gchol(temp) print(as.matrix(ch1)) # Print out L print(diag(ch1)) # Print out D aeq <- function(x,y) all.equal(as.vector(x), as.vector(y)) aeq(diag(ch1)[6], 0) # Check that it has a zero in the proper place ginv <- solve(ch1) # See if I get a generalized inverse aeq(temp %*% ginv %*% temp, temp) aeq(ginv %*% temp %*% ginv, ginv)