We can solve A %*% x = b by first computing the Cholesky decomposition A =
t(R)%*%R), then solving t(R)%*%y = b for y, and
finally solving R%*%x = y for x.
solve combines chol, a Cholesky decomposition of a
symmetric positive definite sparse matrix, with forwardsolve and
then backsolve.
In case a is from a chol call, then solve is an
efficient way to calculate backsolve(a, forwardsolve( t(a), b)).
However, for a.spam and a.mat from a chol call
with a sparse and ordinary matrix, note that
forwardsolve( a.mat, b, transpose=T, upper.tri=T)
is equivalent to
forwardsolve( t(a.mat), b)
and backsolve(a.spam, forwardsolve(a.spam, b, transpose=T, upper.tri=T))
yields the desired result. But
backsolve(a.spam,forwardsolve(t(a.spam), resid)) is
wrong because t(a.spam) is a spam and not a
spam.chol.NgPeyton object.
forwardsolve and backsolve solve a system of linear
equations where the coefficient matrix is lower (forwardsolve) or
upper (backsolve) triangular. Usually, the triangular matrix is
result from a chol call and it is not required to transpose it
for forwardsolve. Note that arguments of the default
methods k, upper.tri and transpose do not have any
effects here.
Notice that it is more efficient to solve successively the linear
equations (both triangular solves) than to implement these in the
Fortran code.
If the right-hand-side in solve is missing it will compute
the inverse of a matrix. For details about the specific Cholsesky
decomposition, see chol.
Recall that the Cholesky factors are from ordered matrices.
chol2inv(x) is a faster way to solve(x).