Class SymmetricMatrix
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.triangle.SymmetricMatrix
-
- All Implemented Interfaces:
Matrix,MatrixAccess,MatrixRing,MatrixTable,Densifiable,AbelianGroup<Matrix>,Monoid<Matrix>,Ring<Matrix>,Table,DeepCopyable
- Direct Known Subclasses:
BorderedHessian,Hessian,HilbertMatrix
public class SymmetricMatrix extends Object implements Matrix, Densifiable
A symmetric matrix is a square matrix such that its transpose equals to itself, i.e.,A[i][j] = A[j][i]- See Also:
- Wikipedia: Symmetric matrix
-
-
Constructor Summary
Constructors Constructor Description SymmetricMatrix(double[][] data)Construct a symmetric matrix from a 2Ddouble[][]array.SymmetricMatrix(int dim)Construct a symmetric matrix of dimension dim * dim.SymmetricMatrix(Matrix A)Cast an (almost) symmetric matrix into SymmetricMatrix by averaging A(i,j) and A(j,i).SymmetricMatrix(Matrix A, boolean copyLower)Cast an (almost) symmetric matrix into SymmetricMatrix.SymmetricMatrix(SymmetricMatrix S)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrixadd(Matrix that)this + thatSymmetricMatrixdeepCopy()The implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.booleanequals(Object obj)doubleget(int i, int j)Get the matrix entry at [i,j].VectorgetColumn(int j)Get the specified column in the matrix as a vector.VectorgetRow(int i)Get the specified row in the matrix as a vector.inthashCode()Matrixminus(Matrix that)this - thatMatrixmultiply(Matrix that)this * thatVectormultiply(Vector v)Right multiply this matrix, A, by a vector.intnCols()Gets the number of columns.intnRows()Gets the number of rows.SymmetricMatrixONE()Get an identity matrix that has the same dimension as this matrix.SymmetricMatrixopposite()Get the opposite of this matrix.SymmetricMatrixscaled(double scalar)Scale this matrix, A, by a constant.voidset(int row, int col, double value)Set the matrix entry at [i,j] to a value.SymmetricMatrixt()The transpose of a symmetric matrix is the same as itself.DenseMatrixtoDense()Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,DenseMatrix.StringtoString()SymmetricMatrixZERO()Get a zero matrix that has the same dimension as this matrix.
-
-
-
Constructor Detail
-
SymmetricMatrix
public SymmetricMatrix(int dim)
Construct a symmetric matrix of dimension dim * dim.- Parameters:
dim- the matrix dimension
-
SymmetricMatrix
public SymmetricMatrix(double[][] data)
Construct a symmetric matrix from a 2Ddouble[][]array. The array specifies only the lower triangular part (main diagonal inclusive) of the whole matrix. For example,
gives \[ \begin{bmatrix} 1 & 2 & 4 & 7 & 11\\ 2 & 3 & 5 & 8 & 12\\ 4 & 5 & 6 & 9 & 13\\ 7 & 8 & 9 & 10 & 14\\ 11 & 12 & 13 & 14 & 15 \end{bmatrix} \] This constructor uses lower instead of upper triangular representation for visual reason.new double[][]{ {1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}, {11, 12, 13, 14, 15}});- Parameters:
data- the lower triangular specification
-
SymmetricMatrix
public SymmetricMatrix(Matrix A)
Cast an (almost) symmetric matrix into SymmetricMatrix by averaging A(i,j) and A(j,i).- Parameters:
A- an (almost) symmetric matrix
-
SymmetricMatrix
public SymmetricMatrix(Matrix A, boolean copyLower)
Cast an (almost) symmetric matrix into SymmetricMatrix.- Parameters:
A- an (almost) symmetric matrixcopyLower-trueif the lower triangular portion of A is used; otherwise, the average values of A(i,j) and A(j,i) are used
-
SymmetricMatrix
public SymmetricMatrix(SymmetricMatrix S)
Copy constructor.- Parameters:
S- a symmetric matrix
-
-
Method Detail
-
nRows
public int nRows()
Description copied from interface:TableGets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:TableGets the number of columns. Columns count from 1.
-
deepCopy
public SymmetricMatrix deepCopy()
Description copied from interface:DeepCopyableThe implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.- Specified by:
deepCopyin interfaceDeepCopyable- Specified by:
deepCopyin interfaceMatrix- Returns:
- an independent (deep) copy of the instance
-
toDense
public DenseMatrix toDense()
Description copied from interface:DensifiableDensify a matrix, i.e., convert a matrix implementation to the standard dense matrix,DenseMatrix.- Specified by:
toDensein interfaceDensifiable- Returns:
- a matrix representation in
DenseMatrix
-
set
public void set(int row, int col, double value) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessSet the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
setin interfaceMatrixAccess- Parameters:
row- the row indexcol- 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 MatrixAccessExceptionDescription copied from interface:MatrixAccessGet the matrix entry at [i,j].- Specified by:
getin 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) throws MatrixAccessException
Description copied from interface:MatrixGet the specified row in the matrix as a vector.- Specified by:
getRowin interfaceMatrix- Parameters:
i- the row index- Returns:
- the vector A[i, ]
- Throws:
MatrixAccessException- when i < 1, or when i > the number of rows
-
getColumn
public Vector getColumn(int j) throws MatrixAccessException
Description copied from interface:MatrixGet the specified column in the matrix as a vector.- Specified by:
getColumnin interfaceMatrix- Parameters:
j- the column index- Returns:
- a vector A[, j]
- Throws:
MatrixAccessException- when j < 1, or when j > the number of columns
-
add
public Matrix add(Matrix that)
Description copied from interface:MatrixRingthis + that- Specified by:
addin interfaceAbelianGroup<Matrix>- Specified by:
addin interfaceMatrixRing- Parameters:
that- a matrix- Returns:
- the sum of
thisandthat
-
minus
public Matrix minus(Matrix that)
Description copied from interface:MatrixRingthis - that- Specified by:
minusin interfaceAbelianGroup<Matrix>- Specified by:
minusin interfaceMatrixRing- Parameters:
that- a matrix- Returns:
- the difference between
thisandthat
-
multiply
public Matrix multiply(Matrix that)
Description copied from interface:MatrixRingthis * that- Specified by:
multiplyin interfaceMatrixRing- Specified by:
multiplyin interfaceMonoid<Matrix>- Parameters:
that- a matrix- Returns:
- the product of
thisandthat
-
t
public SymmetricMatrix t()
The transpose of a symmetric matrix is the same as itself.- Specified by:
tin interfaceMatrixRing- Returns:
- a copy of itself
-
scaled
public SymmetricMatrix scaled(double scalar)
Description copied from interface:MatrixScale this matrix, A, by a constant.
-
opposite
public SymmetricMatrix opposite()
Description copied from interface:MatrixRingGet the opposite of this matrix.- Specified by:
oppositein interfaceAbelianGroup<Matrix>- Specified by:
oppositein interfaceMatrixRing- Returns:
- -this
- See Also:
- Wikipedia: Additive inverse
-
ZERO
public SymmetricMatrix ZERO()
Description copied from interface:MatrixRingGet a zero matrix that has the same dimension as this matrix.- Specified by:
ZEROin interfaceAbelianGroup<Matrix>- Specified by:
ZEROin interfaceMatrixRing- Returns:
- the 0 matrix
-
ONE
public SymmetricMatrix ONE()
Description copied from interface:MatrixRingGet 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:
ONEin interfaceMatrixRing- Specified by:
ONEin interfaceMonoid<Matrix>- Returns:
- an identity matrix
-
multiply
public Vector multiply(Vector v)
Description copied from interface:MatrixRight multiply this matrix, A, by a vector.
-
-