csolve

Share:

Description

This is a wrapper for the Cholesky-solvers 'LLT' (dense case) or 'Simplicial-LLT' (sparse case) from Eigen. The function computes the solution:

\mathbf{b} = \mathbf{X}^{-1} \mathbf{y}

If no vector y is passed, an identity matrix will be assigned and the function returns the inverse of \mathbf{X}. In the case of multiple right hand sides (as is the case when computing an inverse matrix) multiple threads will solve equal parts of it.

Usage

1
csolve(X,y=NULL)	

Arguments

X

positive definite square matrix of type matrix or dgCMatrix

y

numeric vector of length equal to columns/rows of X

Value

Solution vector/matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Least Squares Solving

# Generate random data 

n = 1000
p = 500

M <- matrix(rnorm(n*p),n,p)
y <- rnorm(n)

# least squares solution:

b <- csolve(t(M) %c% M, t(M) %c% y)