solve {RandomFieldsUtils}R Documentation

Solve a System of Equations for Positive Definite Matrices

Description

This function solves the equality a x = b for x where a is a positive definite matrix and b is a vector or a matrix. It is slightly faster than the inversion by the cholesky decomposition and clearly faster than solve. It also returns the logarithm of the determinant at no additional computational costs.

Usage

solvex(a, b=NULL, logdeterminant=FALSE)

Arguments

a

a square real-valued matrix containing the coefficients of the linear system. Logical matrices are coerced to numeric.

b

a numeric or complex vector or matrix giving the right-hand side(s) of the linear system. If missing, b is taken to be an identity matrix and solvex will return the inverse of a.

logdeterminant

logical. whether the logarithm of the determinant should also be returned

Details

If the matrix is diagonal direct calculations are performed.

Else if the matrix is sparse the package spam is used.

Else the Cholesky decomposition is tried. If it fails, the eigen value decomposition is tried.

Value

If logdeterminant=FALSE the function returns a vector or a matrix, depending on b which is the solution to the linear equation. Else the function returns a list containing both the solution to the linear equation and the logarithm of the determinant of a.

Author(s)

Martin Schlather, schlather@math.uni-mannheim.de

References

See chol.spam of the package spam

See Also

chol.spam in the package spam

Examples

if (FALSE) {
## This examples shows that 'solvex' can be much faster than 'solve'

## creating a covariance matrix for a temporal process
covmatrix <- function(model, x) {
  x <- as.matrix(dist(x))
  return(eval(substitute(model)))
}

size <- 600
x <- runif(size, 0, size / 10)
M <- covmatrix((1 - x) * (x < 1) , x) ## Askey's model of covariance
b <- seq(0, 1, len=size)
system.time(inv2 <- solve(M, b))
system.time(inv1 <- solvex(M, b)) ## much faster in this case
range(inv2 - inv1)
stopifnot(all(abs(inv2 - inv1) < 10^{-9}))

}


[Package RandomFieldsUtils version 0.3.25 Index]