Class UpperTriangularMatrix
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.triangle.UpperTriangularMatrix
-
- All Implemented Interfaces:
Matrix
,MatrixAccess
,MatrixRing
,MatrixTable
,Densifiable
,AbelianGroup<Matrix>
,Monoid<Matrix>
,Ring<Matrix>
,Table
,DeepCopyable
public class UpperTriangularMatrix extends Object implements Matrix, Densifiable
An upper triangular matrix has 0 entries where row index is greater than column index. An upper triangular matrix is always square.
-
-
Constructor Summary
Constructors Constructor Description UpperTriangularMatrix(double[][] data)
Constructs an upper triangular matrix from a 2Ddouble[][]
array.UpperTriangularMatrix(int dim)
Constructs an upper triangular matrix of dimension dim * dim.UpperTriangularMatrix(Matrix A)
Constructs an upper triangular matrix from a matrix.UpperTriangularMatrix(UpperTriangularMatrix U)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix
add(Matrix that)
this + thatUpperTriangularMatrix
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.Vector
getRow(int i)
Get the specified row in the matrix as a vector.int
hashCode()
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.UpperTriangularMatrix
ONE()
Get an identity matrix that has the same dimension as this matrix.UpperTriangularMatrix
opposite()
Get the opposite of this matrix.UpperTriangularMatrix
scaled(double scalar)
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.LowerTriangularMatrix
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()
UpperTriangularMatrix
ZERO()
Get a zero matrix that has the same dimension as this matrix.
-
-
-
Constructor Detail
-
UpperTriangularMatrix
public UpperTriangularMatrix(int dim)
Constructs an upper triangular matrix of dimension dim * dim.- Parameters:
dim
- the matrix dimension
-
UpperTriangularMatrix
public UpperTriangularMatrix(double[][] data)
Constructs an upper triangular matrix from a 2Ddouble[][]
array.- Parameters:
data
- the 2D array input- Throws:
IllegalArgumentException
- when the inputdata
is not a upper triangular
-
UpperTriangularMatrix
public UpperTriangularMatrix(Matrix A)
Constructs an upper triangular matrix from a matrix.- Parameters:
A
- a matrix- Throws:
IllegalArgumentException
- whenA
is not square
-
UpperTriangularMatrix
public UpperTriangularMatrix(UpperTriangularMatrix U)
Copy constructor.- Parameters:
U
- an upper triangular matrix
-
-
Method Detail
-
deepCopy
public UpperTriangularMatrix 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.- Specified by:
deepCopy
in interfaceDeepCopyable
- Specified by:
deepCopy
in interfaceMatrix
- Returns:
- an independent (deep) copy of the instance
-
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
-
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.
-
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)
Description copied from interface:MatrixRing
this * that- Specified by:
multiply
in interfaceMatrixRing
- Specified by:
multiply
in interfaceMonoid<Matrix>
- Parameters:
that
- a matrix- Returns:
- the product of
this
andthat
-
t
public LowerTriangularMatrix t()
Description copied from interface:MatrixRing
Get the transpose of this matrix. This is the involution on the matrix ring.- Specified by:
t
in interfaceMatrixRing
- Returns:
- the transpose of this matrix
-
scaled
public UpperTriangularMatrix scaled(double scalar)
Description copied from interface:Matrix
Scale this matrix, A, by a constant.
-
opposite
public UpperTriangularMatrix opposite()
Description copied from interface:MatrixRing
Get the opposite of this matrix.- Specified by:
opposite
in interfaceAbelianGroup<Matrix>
- Specified by:
opposite
in interfaceMatrixRing
- Returns:
- -this
- See Also:
- Wikipedia: Additive inverse
-
multiply
public Vector multiply(Vector v)
Description copied from interface:Matrix
Right multiply this matrix, A, by a vector.
-
ZERO
public UpperTriangularMatrix ZERO()
Description copied from interface:MatrixRing
Get a zero matrix that has the same dimension as this matrix.- Specified by:
ZERO
in interfaceAbelianGroup<Matrix>
- Specified by:
ZERO
in interfaceMatrixRing
- Returns:
- the 0 matrix
-
ONE
public UpperTriangularMatrix 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).- Specified by:
ONE
in interfaceMatrixRing
- Specified by:
ONE
in interfaceMonoid<Matrix>
- Returns:
- an identity matrix
-
-