Class BandMatrix
- All Implemented Interfaces:
Serializable
In numerical analysis, matrices from finite element or finite difference problems are often banded. Such matrices can be viewed as descriptions of the coupling between the problem variables; the bandedness corresponds to the fact that variables are not coupled over arbitrarily large distances. Such matrices can be further divided - for instance, banded matrices exist where every element in the band is nonzero. These often arise when discretizing one-dimensional problems. Problems in higher dimensions also lead to banded matrices, in which case the band itself also tends to be sparse. For instance, a partial differential equation on a square domain (using central differences) will yield a matrix with a half-bandwidth equal to the square root of the matrix dimension, but inside the band only 5 diagonals are nonzero. Unfortunately, applying Gaussian elimination (or equivalently an LU decomposition) to such a matrix results in the band being filled in by many non-zero elements. As sparse matrices lend themselves to more efficient computation than dense matrices, there has been much research focused on finding ways to minimize the bandwidth (or directly minimize the fill in) by applying permutations to the matrix, or other such equivalence or similarity transformations.
From a computational point of view, working with band matrices is always preferential to working with similarly dimensioned dense square matrices. A band matrix can be likened in complexity to a rectangular matrix whose row dimension is equal to the bandwidth of the band matrix. Thus, the work involved in performing operations such as multiplication falls significantly, often leading to huge savings in terms of calculation time and complexity.
Given an n-by-n band matrix with m1 rows below the diagonal
and m2 rows above. The matrix is compactly stored in an array
A[0,n-1][0,m1+m2]. The diagonal elements are in
A[0,n-1][m1]. The subdiagonal elements are in A[j,n-1][0,m1-1]
with j > 0
appropriate to the number of elements on each subdiagonal.
The superdiagonal elements are in A[0,j][m1+1,m2+m2]
with j < n-1
appropriate to the number of elements on each superdiagonal.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The Cholesky decomposition of a symmetric, positive-definite matrix.static class
The LU decomposition.Nested classes/interfaces inherited from class smile.math.matrix.IMatrix
IMatrix.Preconditioner
-
Constructor Summary
ConstructorDescriptionBandMatrix
(int m, int n, int kl, int ku) Constructor.BandMatrix
(int m, int n, int kl, int ku, double[][] AB) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncholesky()
Cholesky decomposition for symmetric and positive definite matrix.copy()
Returns a deep copy of matrix.boolean
boolean
equals
(BandMatrix o, double epsilon) Returns true if two matrices equal in given precision.double
get
(int i, int j) ReturnsA[i,j]
.boolean
Return true if the matrix is symmetric (uplo != null).int
kl()
Returns the number of subdiagonals.int
ku()
Returns the number of superdiagonals.layout()
Returns the matrix layout.int
ld()
Returns the leading dimension.lu()
LU decomposition.void
mv
(double[] work, int inputOffset, int outputOffset) Matrix-vector multiplicationA * x
.void
Matrix-vector multiplication.int
ncol()
Returns the number of columns.int
nrow()
Returns the number of rows.void
set
(int i, int j, double x) SetsA[i,j] = x
.long
size()
Returns the number of stored matrix elements.void
tv
(double[] work, int inputOffset, int outputOffset) Matrix-vector multiplicationA' * x
.uplo()
Gets the format of packed matrix.Sets the format of symmetric band matrix.
-
Constructor Details
-
BandMatrix
public BandMatrix(int m, int n, int kl, int ku) Constructor.- Parameters:
m
- the number of rows.n
- the number of columns.kl
- the number of subdiagonals.ku
- the number of superdiagonals.
-
BandMatrix
public BandMatrix(int m, int n, int kl, int ku, double[][] AB) Constructor.- Parameters:
m
- the number of rows.n
- the number of columns.kl
- the number of subdiagonals.ku
- the number of superdiagonals.AB
- the band matrix. A[i,j] is stored inAB[ku+i-j, j]
formax(0, j-ku) <= i <= min(m-1, j+kl)
.
-
-
Method Details
-
copy
Description copied from class:IMatrix
Returns a deep copy of matrix. -
nrow
public int nrow()Description copied from class:IMatrix
Returns the number of rows. -
ncol
public int ncol()Description copied from class:IMatrix
Returns the number of columns. -
size
public long size()Description copied from class:IMatrix
Returns the number of stored matrix elements. For conventional matrix, it is simply nrow * ncol. But it is usually much less for band, packed or sparse matrix. -
kl
public int kl()Returns the number of subdiagonals.- Returns:
- the number of subdiagonals.
-
ku
public int ku()Returns the number of superdiagonals.- Returns:
- the number of superdiagonals.
-
layout
Returns the matrix layout.- Returns:
- the matrix layout.
-
ld
public int ld()Returns the leading dimension.- Returns:
- the leading dimension.
-
isSymmetric
public boolean isSymmetric()Return true if the matrix is symmetric (uplo != null).- Returns:
- true if the matrix is symmetric (uplo != null).
-
uplo
Sets the format of symmetric band matrix.- Parameters:
uplo
- the format of symmetric band matrix.- Returns:
- this matrix.
-
uplo
Gets the format of packed matrix.- Returns:
- the format of packed matrix.
-
equals
-
equals
Returns true if two matrices equal in given precision.- Parameters:
o
- the other matrix.epsilon
- a number close to zero.- Returns:
- true if two matrices equal in given precision.
-
get
public double get(int i, int j) Description copied from class:IMatrix
ReturnsA[i,j]
. -
set
public void set(int i, int j, double x) Description copied from class:IMatrix
SetsA[i,j] = x
. -
mv
Description copied from class:IMatrix
Matrix-vector multiplication.
where op is the transpose operation.y = alpha * op(A) * x + beta * y
-
mv
public void mv(double[] work, int inputOffset, int outputOffset) Description copied from class:IMatrix
Matrix-vector multiplicationA * x
. -
tv
public void tv(double[] work, int inputOffset, int outputOffset) Description copied from class:IMatrix
Matrix-vector multiplicationA' * x
. -
lu
LU decomposition.- Returns:
- LU decomposition.
-
cholesky
Cholesky decomposition for symmetric and positive definite matrix.- Returns:
- Cholesky decomposition.
- Throws:
ArithmeticException
- if the matrix is not positive definite.
-