public class BandMatrix extends java.lang.Object implements Matrix, LinearSolver
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 a 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]. Subdiagonal elements are in A[j,n-1][0,m1-1] with j > 0 appropriate to the number of elements on each subdiagonal. Superdiagonal elements are in A[0,j][m1+1,m2+m2] with j < n-1 appropriate to the number of elements on each superdiagonal.
| Constructor and Description |
|---|
BandMatrix(int n,
int m)
Constructor of an n-by-n band-diagonal matrix A with m subdiagonal
rows and m superdiagonal rows.
|
BandMatrix(int n,
int m1,
int m2)
Constructor of an n-by-n band-diagonal matrix A with m1 subdiagonal
rows and m2 superdiagonal rows.
|
| Modifier and Type | Method and Description |
|---|---|
BandMatrix |
aat()
Returns A * A'
|
BandMatrix |
ata()
Returns A' * A
|
double[] |
atx(double[] x,
double[] y)
y = A' * x
|
double[] |
atxpy(double[] x,
double[] y)
y = A' * x + y
|
double[] |
atxpy(double[] x,
double[] y,
double b)
y = A' * x + b * y
|
double[] |
ax(double[] x,
double[] y)
y = A * x
|
double[] |
axpy(double[] x,
double[] y)
y = A * x + y
|
double[] |
axpy(double[] x,
double[] y,
double b)
y = A * x + b * y
|
void |
decompose()
LU decomposition.
|
double |
det()
Returns the matrix determinant.
|
double[] |
diag()
Returns the diagonal elements.
|
EigenValueDecomposition |
eigen(int k)
Returns the k largest eigen pairs.
|
double |
get(int i,
int j)
Returns the entry value at row i and column j.
|
void |
improve(double[] b,
double[] x)
Iteratively improve a solution to linear equations.
|
int |
ncols()
Returns the number of columns.
|
int |
nrows()
Returns the number of rows.
|
BandMatrix |
set(int i,
int j,
double x) |
double[] |
solve(double[] b,
double[] x)
Solve A*x = b.
|
BandMatrix |
transpose()
Returns the matrix transpose.
|
public BandMatrix(int n,
int m)
n - the dimensionality of matrix.m - the number of subdiagonal and superdiagonal rows.public BandMatrix(int n,
int m1,
int m2)
n - the dimensionality of matrix.m1 - the number of subdiagonal rows.m2 - the number of superdiagonal rows.public int nrows()
Matrixpublic int ncols()
Matrixpublic double get(int i,
int j)
Matrixpublic BandMatrix set(int i, int j, double x)
public BandMatrix transpose()
public BandMatrix ata()
Matrixpublic BandMatrix aat()
Matrixpublic EigenValueDecomposition eigen(int k)
public double det()
public void decompose()
public double[] ax(double[] x,
double[] y)
Matrixpublic double[] axpy(double[] x,
double[] y)
Matrixpublic double[] axpy(double[] x,
double[] y,
double b)
Matrixpublic double[] atx(double[] x,
double[] y)
Matrixpublic double[] atxpy(double[] x,
double[] y)
Matrixpublic double[] atxpy(double[] x,
double[] y,
double b)
Matrixpublic double[] diag()
Matrixpublic double[] solve(double[] b,
double[] x)
solve in interface LinearSolverb - a vector with as many rows as A.x - is output vector so that L*U*X = b(piv,:)java.lang.RuntimeException - if matrix is singular.public void improve(double[] b,
double[] x)
b - right hand side of linear equations.x - a solution to linear equations.