Solve.banded {limSolve}R Documentation

Solution of a banded system of linear equations

Description

Solves the linear system of equations

Ax=B

by Gaussion elimination
where A has to be square, and banded, i.e. with the only nonzero elements in bands near the diagonal.

The matrix A is either inputted as a full square matrix or as the non-zero bands
uses subroutines dgbfa and dgbsl (FORTRAN) from the Linpack routines

Usage

Solve.banded(abd, nup, nlow,rhs=rep(0,times=ncol(abd)), 
full=(nrow(abd)==ncol(abd)))

Arguments

abd either a matrix containing the (nonzero) bands, rotated row-wise (anti-clockwise) only or a full square matrix
nup number of nonzero bands above the diagonal; ignored if full matrix is inputted
nlow number of nonzero bands below the diagonal; ignored if full matrix is inputted
rhs numeric vector containing right hand side
full if true: full matrix is passed, if false:banded

Details

If the input matrix abd is square, it is assumed that the full, square A is inputted, unless full is false.
is abd is not square, then the number of columns denote the number of unknowns, while the number of rows equals the nonzero bands, i.e. nup+nlow+1

Value

vector with solution, x, of banded system of equations Ax=B

Author(s)

Karline Soetaert <k.soetaert@nioo.knaw.nl>

References

J.J. Dongarra, J.R. Bunch, C.B. Moler, G.W. Stewart, LINPACK Users' Guide, SIAM, 1979.

See Also

Solve.tridiag To solve a tridiagonal system of linear equations.
Solve the generalised inverse solution,
solve the R default

Examples

# Generate a banded matrix of random numbers
nup  <- 2                         # nr nonzero bands above diagonal
ndwn <- 3                         # nr nonzero bands below diagonal
nn   <- 10                        # nr rows and columns of A
A <- matrix(nrow=nn,ncol=nn,data=runif(1:(nn*nn)))
A [row(A)<col(A)-nup | row(A)>col(A)+ndwn]<-0 
diag(A) <- 1                      # 1 on diagonal is easily recognised 
# right hand side
B<-runif(nrow(A))                
# solve it, using the default solver and banded (inputting full matrix)
Full <- solve(A,B)
Band1<- Solve.banded(A,nup,ndwn,B)

# create banded form of matrix A
Aext <- rbind(matrix(nc=ncol(A),nr=nup,0),
              A,matrix(nc=ncol(A),nr=ndwn,0))
abd  <- matrix(nrow=nup+ndwn+1,ncol=nn,
  data=Aext[(col(Aext))<=row(Aext)&col(Aext)>=row(Aext)-ndwn-nup])
# print both to screen
A
abd
# solve problem with banded version
Band2 <- Solve.banded(abd,nup,ndwn,B)
# compare 3 methods of solution
rbind(Full,Band1,Band2)

[Package limSolve version 1.3 Index]