smile.math.matrix

## Class BandMatrix

• All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

```public class BandMatrix
extends DMatrix```
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.

Serialized Form
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
`static class ` `BandMatrix.Cholesky`
The Cholesky decomposition of a symmetric, positive-definite matrix.
`static class ` `BandMatrix.LU`
The LU decomposition.
• ### Constructor Summary

Constructors
Constructor and Description
```BandMatrix(int m, int n, int kl, int ku)```
Constructor.
```BandMatrix(int m, int n, int kl, int ku, double[][] AB)```
Constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`BandMatrix.Cholesky` `cholesky()`
Cholesky decomposition for symmetric and positive definite matrix.
`BandMatrix` `clone()`
`boolean` ```equals(BandMatrix o, double eps)```
Returns if two matrices equals given an error margin.
`boolean` `equals(java.lang.Object o)`
`double` ```get(int i, int j)```
Returns A[i, j].
`boolean` `isSymmetric()`
Return if the matrix is symmetric (uplo != null).
`int` `kl()`
Returns the number of subdiagonals.
`int` `ku()`
Returns the number of superdiagonals.
`Layout` `layout()`
Returns the matrix layout.
`int` `ld()`
`BandMatrix.LU` `lu()`
LU decomposition.
`void` ```mv(double[] work, int inputOffset, int outputOffset)```
Matrix-vector multiplication A * x.
`void` ```mv(Transpose trans, double alpha, double[] x, double beta, double[] y)```
Matrix-vector multiplication.
`int` `ncols()`
Returns the number of columns.
`int` `nrows()`
Returns the number of rows.
`BandMatrix` ```set(int i, int j, double x)```
Sets A[i, j] = x.
`long` `size()`
Returns the number of stored matrix elements.
`void` ```tv(double[] work, int inputOffset, int outputOffset)```
Matrix-vector multiplication A' * x.
`UPLO` `uplo()`
Gets the format of packed matrix.
`BandMatrix` `uplo(UPLO uplo)`
Sets the format of symmetric band matrix.
• ### Methods inherited from class smile.math.matrix.DMatrix

`apply, diag, market, mv, mv, mv, trace, tv, tv, tv, update`
• ### Methods inherited from class smile.math.matrix.IMatrix

`colName, colNames, colNames, rowName, rowNames, rowNames, toString, toString, toString`
• ### Methods inherited from class java.lang.Object

`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### 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 in AB[ku+i-j, j] for max(0, j-ku) <= i <= min(m-1, j+kl).
• ### Method Detail

• #### clone

`public BandMatrix clone()`
Overrides:
`clone` in class `java.lang.Object`
• #### nrows

`public int nrows()`
Description copied from class: `IMatrix`
Returns the number of rows.
Specified by:
`nrows` in class `IMatrix<double[]>`
• #### ncols

`public int ncols()`
Description copied from class: `IMatrix`
Returns the number of columns.
Specified by:
`ncols` in class `IMatrix<double[]>`
• #### size

`public long size()`
Description copied from class: `IMatrix`
Returns the number of stored matrix elements. For conventional matrix, it is simplify nrows * ncols. But it is usually much less for band, packed or sparse matrix.
Specified by:
`size` in class `IMatrix<double[]>`
• #### kl

`public int kl()`
Returns the number of subdiagonals.
• #### ku

`public int ku()`
Returns the number of superdiagonals.
• #### layout

`public Layout layout()`
Returns the matrix layout.
• #### ld

`public int ld()`
• #### isSymmetric

`public boolean isSymmetric()`
Return if the matrix is symmetric (uplo != null).
• #### uplo

`public BandMatrix uplo(UPLO uplo)`
Sets the format of symmetric band matrix.
• #### uplo

`public UPLO uplo()`
Gets the format of packed matrix.
• #### equals

`public boolean equals(java.lang.Object o)`
Overrides:
`equals` in class `java.lang.Object`
• #### equals

```public boolean equals(BandMatrix o,
double eps)```
Returns if two matrices equals given an error margin.
Parameters:
`o` - the other matrix.
`eps` - the error margin.
• #### get

```public double get(int i,
int j)```
Description copied from class: `DMatrix`
Returns A[i, j].
Specified by:
`get` in class `DMatrix`
• #### set

```public BandMatrix set(int i,
int j,
double x)```
Description copied from class: `DMatrix`
Sets A[i, j] = x.
Specified by:
`set` in class `DMatrix`
• #### mv

```public void mv(Transpose trans,
double alpha,
double[] x,
double beta,
double[] y)```
Description copied from class: `DMatrix`
Matrix-vector multiplication.
``````
y = alpha * op(A) * x + beta * y
``````
where op is the transpose operation.
Specified by:
`mv` in class `DMatrix`
• #### mv

```public void mv(double[] work,
int inputOffset,
int outputOffset)```
Description copied from class: `IMatrix`
Matrix-vector multiplication A * x.
Specified by:
`mv` in class `IMatrix<double[]>`
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.
• #### tv

```public void tv(double[] work,
int inputOffset,
int outputOffset)```
Description copied from class: `IMatrix`
Matrix-vector multiplication A' * x.
Specified by:
`tv` in class `IMatrix<double[]>`
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.
• #### lu

`public BandMatrix.LU lu()`
LU decomposition.
• #### cholesky

`public BandMatrix.Cholesky cholesky()`
Cholesky decomposition for symmetric and positive definite matrix.
Throws:
`java.lang.ArithmeticException` - if the matrix is not positive definite.