Band Matrices
A band matrix is a matrix whose only nonzero elements lie on diagonal bands above and/or below the main diagonal. The number of nonzero diagonals above the main diagonal is called the upper bandwidth. The number of nonzero diagonals below the main diagonal is called the lower bandwidth.
Band matrices exist in the usual variations. A general band matrix has nonzero elements both above and below the main diagonal. An upper band matrix only has elements on and above the main diagonal. A lower band matrix has elements on and below the main diagonal. A symmetric band matrix has identical elements on either side of the main diagonal.
All these variations of band matrices are implemented by the BandMatrix<T> class.
Constructing band matrices
Band matrices are created using static methods of the Matrix class.
The CreateBanded creates general band matrices. It has two overloads. The first overload takes four arguments: the number of rows and columns of the matrix, the upper bandwidth, and the lower bandwidth. The element type must be specified as a generic type argument. The second overload takes an additional Boolean argument that specifies whether extra space should be allocated to compute an LU decomposition. The factors of an LU decomposition of a band matrix that uses partial pivoting have a larger upper bandwidth than the original matrix. As a result, extra storage space must be reserved to store these elements.
The shape of the band matrix is fixed. Once created, the upper and lower bandwidth cannot be changed. If the lower bandwidth is zero, the matrix is considered to be an upper band matrix. If the upper bandwidth is zero, the matrix is considered to be a lower band matrix.
The following example constructs a 5x7 band matrix with a lower bandwidth of 2 and an upper bandwidth of 1:
var b1 = Matrix.CreateBanded<double>(5, 7, 2, 1);
The CreateUpperBanded and CreateLowerBanded methods create upper and lower banded matrices. The first two arguments are the number of rows and columns. Next is the bandwidth above or below the diagonal. The last, optional argument is a MatrixDiagonal value that specifies whether the main diagonal of the matrix contains all ones.
The code below creates two band matrices. The first is a 7x6 upper band matrix with a bandwidth of 2 with unit diagonal. The second is a 7x7 lower band matrix with a bandwidth of 3.
var b2 = Matrix.CreateUpperBanded<double>(7, 6, 2, MatrixDiagonal.UnitDiagonal);
var b3 = Matrix.CreateLowerBanded<double>(7, 7, 3);
Finally, the CreateSymmetricBanded<T> method creates a symmetric band matrix. The first argument is the number of rows and columns. The second argument is the upper and lower bandwidth. The example below constructs a 6x6 symmetrical tridiagonal matrix:
var b4 = Matrix.CreateSymmetricBanded<double>(6, 1);
Properties
The BandMatrix<T>> class has a number of unique properties.
The UpperBandwidth and LowerBandwidth properties return the number of non-zero diagonals above and below the main diagonal, respectively. The TotalBandwidth property returns the total number of diagonals that may contain nonzero elements, including the main diagonal.
A group of properties returns information about the structure of the matrix. The IsSymmetrical, IsUpperTriangular, IsLowerTriangular and IsUnitDiagonal properties fall in this category. Their names are self-explanatory.
Rows and Columns
The GetRow and The GetColumn methods of a BandMatrix<T> usually return a vector of type BlockVector<T>. If the vector contains only zeros, a ConstantVector<T> is returned.
Band Matrix Decompositions
The LU decomposition for a general band matrix and the Cholesky decomposition of a symmetric band matrix also have a special form. Two special classes have been defined to take advantage of this special structure.