csolve

Share:

Description

This is a wrapper for the Cholesky-solver 'llt' 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 functions returns the inverse of \mathbf{X}.

Usage

1
csolve(X,y=NULL)	

Arguments

X

positive definite square matrix

y

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)