bandsolve: bandsolve

Description Usage Arguments Value Examples

View source: R/bandsolve.R

Description

Main function to solve efficiently and quickly a symmetric bandlinear system. Theses systems are solved much faster than standards system, dropping from complexity O(n<c2><b3>) to O(0.5*nk<c2><b2>), where k is the number of sub diagonal.

Usage

1
bandsolve(A, b = NULL, inplace = FALSE)

Arguments

A

Band square matrix in rotated form. The rotated form can be obtained with the function as.rotated: it's the visual rotation by 90 degrees of the matrix, where subdiagonal are discarded.

b

right hand side of the equation. Can be either a vector or a matrix. If not supplied, the function return the inverse of A.

inplace

Should results overwrite pre-existing data? Default set to false.

Value

Solution of the linear problem.

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
A=diag(4)
A[2,3]=2
A[3,2]=2
R=mat2rot(A)
solve(A)
bandsolve(ref)

set.seed(100)

n=1000;
D0=rep(1.25,n)
D1=rep(-0.5,n-1)
b=rnorm(n)

## Comparison with solve

if(require(microbenchmark)){
A=diag(D0);
A[-n,-1]=A[-n,-1]+diag(D1);
A[-1,-n]=A[-1,-n]+diag(D1);
R=mat2rot(list(D0,D1))
r=microbenchmark(
SOLVE=solve(A,b),
BANDSOLVE=bandsolve(R,b=b,inplace=TRUE),times=100)
boxplot(r)
}

Monneret/bandsolve documentation built on May 7, 2019, 4:59 p.m.