public class BandMatrix extends Object implements IMatrix
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 |
|---|---|
void |
asolve(double[] b,
double[] x)
Solve Ad * x = b for the preconditioner matrix Ad.
|
void |
atx(double[] x,
double[] y)
y = A' * x
|
void |
atxpy(double[] x,
double[] y)
y = A' * x + y
|
void |
atxpy(double[] x,
double[] y,
double b)
y = A' * x + b * y
|
void |
ax(double[] x,
double[] y)
y = A * x
|
void |
axpy(double[] x,
double[] y)
y = A * x + y
|
void |
axpy(double[] x,
double[] y,
double b)
y = A * x + b * y
|
void |
decompose()
LU decomposition.
|
double |
det()
Returns the matrix determinant.
|
double |
eigen(double[] v)
Returns the largest eigen pair of matrix with the power iteration
under the assumptions A has an eigenvalue that is strictly greater
in magnitude than its other its other eigenvalues and the starting
vector has a nonzero component in the direction of an eigenvector
associated with the dominant eigenvalue.
|
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)
Set the entry value at row i and column j.
|
void |
solve(double[] b)
Solve A*x = b.
|
void |
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()
IMatrixpublic int ncols()
IMatrixpublic double get(int i,
int j)
IMatrixpublic BandMatrix set(int i, int j, double x)
IMatrixpublic BandMatrix transpose()
public double eigen(double[] v)
v - is the non-zero initial guess of the eigen vector on input.
On output, it is the eigen vector corresponding largest eigen value.public EigenValueDecomposition eigen(int k)
public double det()
public void decompose()
public void ax(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y,
double b)
IMatrixpublic void atx(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y,
double b)
IMatrixpublic void asolve(double[] b,
double[] x)
IMatrixpublic void solve(double[] b)
b - a vector with as many rows as A.RuntimeException - if matrix is singular.public void solve(double[] b,
double[] x)
b - a vector with as many rows as A.x - is output vector so that L*U*X = b(piv,:)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.Copyright © 2015. All rights reserved.