Class BidiagonalMatrix
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.diagonal.BidiagonalMatrix
-
- All Implemented Interfaces:
Matrix
,MatrixAccess
,MatrixRing
,MatrixTable
,Densifiable
,AbelianGroup<Matrix>
,Monoid<Matrix>
,Ring<Matrix>
,Table
,DeepCopyable
public class BidiagonalMatrix extends Object
A bi-diagonal matrix is either upper or lower diagonal. It has non-zero entries only on the main, and either the super-diagonal (upper) or sub-diagonal (lower).- See Also:
- Wikipedia: Bidiagonal matrix
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BidiagonalMatrix.BidiagonalMatrixType
the available types of bi-diagonal matrices
-
Constructor Summary
Constructors Constructor Description BidiagonalMatrix(double[][] data)
Constructs a bi-diagonal matrix from a 2Ddouble[][]
array.BidiagonalMatrix(int dim, BidiagonalMatrix.BidiagonalMatrixType type)
Constructs a 0 bi-diagonal matrix of dimension dim * dim.BidiagonalMatrix(BidiagonalMatrix that)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix
add(Matrix that)
this + thatBidiagonalMatrix
deepCopy()
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.boolean
equals(Object obj)
double
get(int i, int j)
Get the matrix entry at [i,j].Vector
getColumn(int j)
Get the specified column in the matrix as a vector.DenseVector
getDiagonal()
Gets the main diagonal of the matrix.Vector
getRow(int i)
Get the specified row in the matrix as a vector.DenseVector
getSubDiagonal()
Gets the sub-diagonal of the matrix.DenseVector
getSuperDiagonal()
Gets the super-diagonal of the matrix.BidiagonalMatrix.BidiagonalMatrixType
getType()
Gets the bi-diagonal matrix type.int
hashCode()
boolean
isUnreduced(double epsilon)
A bi-diagonal matrix is unreduced if it has no 0 on both the super and main diagonals.Matrix
minus(Matrix that)
this - thatMatrix
multiply(Matrix that)
this * thatVector
multiply(Vector v)
Right multiply this matrix, A, by a vector.int
nCols()
Gets the number of columns.int
nRows()
Gets the number of rows.BidiagonalMatrix
ONE()
Get an identity matrix that has the same dimension as this matrix.BidiagonalMatrix
opposite()
Get the opposite of this matrix.BidiagonalMatrix
scaled(double c)
Scale this matrix, A, by a constant.void
set(int i, int j, double value)
Set the matrix entry at [i,j] to a value.BidiagonalMatrix
t()
Get the transpose of this matrix.DenseMatrix
toDense()
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,DenseMatrix
.String
toString()
BidiagonalMatrix
ZERO()
Get a zero matrix that has the same dimension as this matrix.
-
-
-
Constructor Detail
-
BidiagonalMatrix
public BidiagonalMatrix(double[][] data)
Constructs a bi-diagonal matrix from a 2Ddouble[][]
array. There are always two rows. The longer row is the main diagonal and has one more element. If the first row is shorter, it is an upper bi-diagonal matrix. If the second row is shorter, it is a lower bi-diagonal matrix. For example,
gives \[ \begin{bmatrix} 1 & 2 & 0 & 0 & 0\\ 0 & 4 & 5 & 0 & 0\\ 0 & 0 & 7 & 8 & 0\\ 0 & 0 & 0 & 10 & 11\\ 0 & 0 & 0 & 0 & 13 \end{bmatrix} \] We allownew double[][]{ {2, 5, 8, 11}, {1, 4, 7, 10, 13} }
null
input when a diagonal is 0s, except for the main diagonal. For example,
gives \[ \begin{bmatrix} 1 & 0 & 0 & 0 & 0\\ 0 & 4 & 0 & 0 & 0\\ 0 & 0 & 7 & 0 & 0\\ 0 & 0 & 0 & 10 & 0\\ 0 & 0 & 0 & 0 & 13 \end{bmatrix} \] The following is not allowed because the dimension cannot be determined.new double[][]{ {1, 4, 7, 10, 13}, null }
This implementation treats a diagonal matrix as an upper bi-diagonal matrix.new double[][]{ null, null }
- Parameters:
data
- the 2D array input
-
BidiagonalMatrix
public BidiagonalMatrix(int dim, BidiagonalMatrix.BidiagonalMatrixType type)
Constructs a 0 bi-diagonal matrix of dimension dim * dim.- Parameters:
dim
- the dimension of the matrixtype
- the type of bi-diagonal matrix to create
-
BidiagonalMatrix
public BidiagonalMatrix(BidiagonalMatrix that)
Copy constructor.- Parameters:
that
- a bi-diagonal matrix
-
-
Method Detail
-
deepCopy
public BidiagonalMatrix deepCopy()
Description copied from interface:DeepCopyable
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.- Returns:
- an independent (deep) copy of the instance
-
getType
public BidiagonalMatrix.BidiagonalMatrixType getType()
Gets the bi-diagonal matrix type.- Returns:
- the bi-diagonal matrix type
-
isUnreduced
public boolean isUnreduced(double epsilon)
A bi-diagonal matrix is unreduced if it has no 0 on both the super and main diagonals.- Parameters:
epsilon
- a precision parameter: when a number |x| ≤ ε, it is considered 0- Returns:
true
ifthis
is unreduced
-
add
public Matrix add(Matrix that)
Description copied from interface:MatrixRing
this + that- Specified by:
add
in interfaceAbelianGroup<Matrix>
- Specified by:
add
in interfaceMatrixRing
- Parameters:
that
- a matrix- Returns:
- the sum of
this
andthat
-
minus
public Matrix minus(Matrix that)
Description copied from interface:MatrixRing
this - that- Specified by:
minus
in interfaceAbelianGroup<Matrix>
- Specified by:
minus
in interfaceMatrixRing
- Parameters:
that
- a matrix- Returns:
- the difference between
this
andthat
-
multiply
public Matrix multiply(Matrix that)
this * that When the two matrices have opposite types, i.e., one isBidiagonalMatrix.BidiagonalMatrixType.UPPER
and one isBidiagonalMatrix.BidiagonalMatrixType.LOWER
, the product of the two bi-diagonal matrices is a tridiagonal matrix.- Specified by:
multiply
in interfaceMatrixRing
- Specified by:
multiply
in interfaceMonoid<Matrix>
- Parameters:
that
- a matrix- Returns:
this
*that
-
scaled
public BidiagonalMatrix scaled(double c)
Description copied from interface:Matrix
Scale this matrix, A, by a constant.- Parameters:
c
- a double- Returns:
- cA
-
opposite
public BidiagonalMatrix opposite()
Description copied from interface:MatrixRing
Get the opposite of this matrix.- Returns:
- -this
- See Also:
- Wikipedia: Additive inverse
-
t
public BidiagonalMatrix t()
Description copied from interface:MatrixRing
Get the transpose of this matrix. This is the involution on the matrix ring.- Returns:
- the transpose of this matrix
-
ZERO
public BidiagonalMatrix ZERO()
Description copied from interface:MatrixRing
Get a zero matrix that has the same dimension as this matrix.- Returns:
- the 0 matrix
-
ONE
public BidiagonalMatrix ONE()
Description copied from interface:MatrixRing
Get an identity matrix that has the same dimension as this matrix. For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).- Returns:
- an identity matrix
-
toDense
public DenseMatrix toDense()
Description copied from interface:Densifiable
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,DenseMatrix
.- Specified by:
toDense
in interfaceDensifiable
- Returns:
- a matrix representation in
DenseMatrix
-
getDiagonal
public DenseVector getDiagonal()
Gets the main diagonal of the matrix.- Returns:
- the main diagonal
-
getSuperDiagonal
public DenseVector getSuperDiagonal()
Gets the super-diagonal of the matrix.- Returns:
- the super-diagonal
-
getSubDiagonal
public DenseVector getSubDiagonal()
Gets the sub-diagonal of the matrix.- Returns:
- the sub-diagonal
-
nRows
public int nRows()
Description copied from interface:Table
Gets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:Table
Gets the number of columns. Columns count from 1.
-
set
public void set(int i, int j, double value) throws MatrixAccessException
Description copied from interface:MatrixAccess
Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
set
in interfaceMatrixAccess
- Parameters:
i
- the row indexj
- the column indexvalue
- the value to set A[i,j] to- Throws:
MatrixAccessException
- if i or j is out of range
-
get
public double get(int i, int j) throws MatrixAccessException
Description copied from interface:MatrixAccess
Get the matrix entry at [i,j].- Specified by:
get
in interfaceMatrixAccess
- Parameters:
i
- the row indexj
- the column index- Returns:
- A[i,j]
- Throws:
MatrixAccessException
- if i or j is out of range
-
getRow
public Vector getRow(int i)
Description copied from interface:Matrix
Get the specified row in the matrix as a vector.
-
getColumn
public Vector getColumn(int j)
Description copied from interface:Matrix
Get the specified column in the matrix as a vector.
-
multiply
public Vector multiply(Vector v)
Description copied from interface:Matrix
Right multiply this matrix, A, by a vector.
-
-