solve_chol: Solve using cholesky decomposition

Description Usage Arguments Details Author(s) See Also Examples

View source: R/solve_chol.R

Description

solve_chol solves a system of equations using the cholesky decomposition of a positive definite matrix A, i.e., using a = chol(A).

Usage

1
2
3
4
solve_chol(a, b, ...)

## S3 method for class 'chol'
solve(a, b, ...)

Arguments

a

The cholesky decomposition of a positive definite matrix.

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 solve will return the inverse of a.

...

Currently unused.

Details

Note: Unless you have good reason to suspect that the cholesky decomposition of your matrix will be stable, it is recommended that you use solve or perform the solve using the qr decomposition.

Author(s)

Joshua French

See Also

solve, chol, qr, solve.qr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
set.seed(10)
# create positive definite matrix a
a = crossprod(matrix(rnorm(25^2), nrow = 25))
# create vector x and matrix b
# x can be used to check the stability of the solution
x = matrix(rnorm(25))
b = a %*% x

# standard solve
x1 = solve(a, b)
all.equal(x, x1)

# solve using cholesky decomposition
chola = chol(a)
x2 = solve_chol(chola, b)
all.equal(x, x2)

# solve using qr decomposition
qra = qr(a)
x3 = solve.qr(qra, b)
all.equal(x, x3)

# compare direct inversion
ai1 = solve(a)
ai2 = solve_chol(chola) #using cholesky decomposition
all.equal(ai1, ai2) # should be TRUE

gear documentation built on April 14, 2020, 5:12 p.m.

Related to solve_chol in gear...