Class BandMatrix
- java.lang.Object
-
- smile.math.matrix.Matrix
-
- smile.math.matrix.BandMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, LinearSolver
public class BandMatrix extends Matrix implements LinearSolver
A band matrix is a sparse matrix, whose non-zero entries are confined to a diagonal band, comprising the main diagonal and zero or more diagonals on either side.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.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description BandMatrixaat()Returns A * A'BandMatrixata()Returns A' * Adouble[]atx(double[] x, double[] y)y = A' * xdouble[]atxpy(double[] x, double[] y)y = A' * x + ydouble[]atxpy(double[] x, double[] y, double b)y = A' * x + b * ydouble[]ax(double[] x, double[] y)y = A * xdouble[]axpy(double[] x, double[] y)y = A * x + ydouble[]axpy(double[] x, double[] y, double b)y = A * x + b * yvoiddecompose()LU decomposition.doubledet()Returns the matrix determinant.double[]diag()Returns the diagonal elements.doubleget(int i, int j)Returns the entry value at row i and column j.voidimprove(double[] b, double[] x)Iteratively improve a solution to linear equations.intncols()Returns the number of columns.intnrows()Returns the number of rows.BandMatrixset(int i, int j, double x)double[]solve(double[] b, double[] x)Solve A*x = b.BandMatrixtranspose()Returns the matrix transpose.-
Methods inherited from class smile.math.matrix.Matrix
apply, diag, eigen, eigen, eye, eye, isSymmetric, newInstance, newInstance, newInstance, ones, randn, randn, setSymmetric, svd, svd, toString, toString, trace, zeros
-
-
-
-
Constructor Detail
-
BandMatrix
public BandMatrix(int n, int m)Constructor of an n-by-n band-diagonal matrix A with m subdiagonal rows and m superdiagonal rows.- Parameters:
n- the dimensionality of matrix.m- the number of subdiagonal and superdiagonal rows.
-
BandMatrix
public 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.- Parameters:
n- the dimensionality of matrix.m1- the number of subdiagonal rows.m2- the number of superdiagonal rows.
-
-
Method Detail
-
nrows
public int nrows()
Description copied from class:MatrixReturns the number of rows.
-
ncols
public int ncols()
Description copied from class:MatrixReturns the number of columns.
-
get
public double get(int i, int j)Description copied from class:MatrixReturns the entry value at row i and column j.
-
set
public BandMatrix set(int i, int j, double x)
-
transpose
public BandMatrix transpose()
Returns the matrix transpose.
-
ata
public BandMatrix ata()
Description copied from class:MatrixReturns A' * A
-
aat
public BandMatrix aat()
Description copied from class:MatrixReturns A * A'
-
det
public double det()
Returns the matrix determinant.
-
decompose
public void decompose()
LU decomposition.
-
ax
public double[] ax(double[] x, double[] y)Description copied from class:Matrixy = A * x
-
axpy
public double[] axpy(double[] x, double[] y)Description copied from class:Matrixy = A * x + y
-
axpy
public double[] axpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A * x + b * y
-
atx
public double[] atx(double[] x, double[] y)Description copied from class:Matrixy = A' * x
-
atxpy
public double[] atxpy(double[] x, double[] y)Description copied from class:Matrixy = A' * x + y
-
atxpy
public double[] atxpy(double[] x, double[] y, double b)Description copied from class:Matrixy = A' * x + b * y
-
diag
public double[] diag()
Description copied from class:MatrixReturns the diagonal elements.
-
solve
public double[] solve(double[] b, double[] x)Solve A*x = b.- Specified by:
solvein interfaceLinearSolver- Parameters:
b- a vector with as many rows as A.x- is output vector so that L*U*X = b(piv,:)- Returns:
- the solution vector x
- Throws:
java.lang.RuntimeException- if matrix is singular.
-
improve
public void improve(double[] b, double[] x)Iteratively improve a solution to linear equations.- Parameters:
b- right hand side of linear equations.x- a solution to linear equations.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG