Learn R Programming

cpgen (version 0.1)

csolve: csolve

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

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

Run this code
# 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)

Run the code above in your browser using DataLab