Package org.djunits.vecmat.def
Class SquareMatrix<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,M extends SquareMatrix<Q,U,M,SI,H>,SI extends SquareMatrix<SIQuantity,SIUnit,SI,?,?>,H extends SquareMatrix<?,?,?,?,?>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,U,M,SI,H>
org.djunits.vecmat.def.Matrix<Q,U,M,SI,H>
org.djunits.vecmat.def.SquareMatrix<Q,U,M,SI,H>
- Type Parameters:
Q- the quantity typeU- the unit typeM- the 'SELF' square matrix typeSI- the square matrix type with generics <SIQuantity, SIUnit<H- the generic square matrix type with generics <?, ?< for Hadamard operations
- All Implemented Interfaces:
Serializable,Additive<M>,Scalable<M>,Value<U,,M> Hadamard<H,SI>
- Direct Known Subclasses:
MatrixNxN,SquareDenseMatrix
public abstract class SquareMatrix<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>,M extends SquareMatrix<Q,U,M,SI,H>,SI extends SquareMatrix<SIQuantity,SIUnit,SI,?,?>,H extends SquareMatrix<?,?,?,?,?>>
extends Matrix<Q,U,M,SI,H>
SquareMatrix defines a number of operations that can be applied to square matrixes, such as transpose, invert, and
determinant.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract SIadjugate()Return the adjugate (classical adjoint) matrix for this matrix, often denoted as adj(M).Return the determinant of the square matrix as quantity with unit U^n where n is the order of the matrix.doubleReturn the determinant of the square matrix as a scalar in SI or BASE units.Q[]Retrieve the main diagonal of the matrix as an array of scalars.double[]Retrieve the main diagonal of the matrix as an array of doubles with SI-values.Retrieve the main diagonal of the matrix as a column vector.abstract SIinverse()Return the inverse of the square matrix, if the matrix is non-singular.booleanReturn whether the matrix is skew symmetric.booleanisSkewSymmetric(Q tolerance) Return whether the matrix is skew symmetric, up to a tolerance.booleanReturn whether the matrix is symmetric.booleanisSymmetric(Q tolerance) Return whether the matrix is symmetric, up to a tolerance.Return the Frobenius norm of the matrix, which is equal to sqrt(trace(A*.A)).intorder()Return the order (the number of rows/columns) of this matrix.trace()Return the trace of the matrix (the sum of the diagonal elements).Return the transposed square matrix.Methods inherited from class org.djunits.vecmat.def.Matrix
checkMultiply, checkMultiply, multiplyMethods inherited from class org.djunits.vecmat.def.VectorMatrix
abs, add, add, asMatrixNxM, asQuantityTable, checkCol, checkRow, cols, divideElements, divideElements, get, getColumnScalars, getColumnSi, getColumnVector, getDisplayUnit, getRowScalars, getRowSi, getRowVector, getScalarGrid, instantiateSi, instantiateSi, invertElements, isRelative, max, mcheckCol, mcheckRow, mean, median, mget, mgetColumnScalars, mgetColumnSi, mgetColumnVector, mgetRowScalars, mgetRowSi, mgetRowVector, min, mode, msi, multiplyElements, multiplyElements, multiplyElements, negate, rows, scaleBy, setDisplayUnit, si, si, subtract, subtract, sum, toString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideElementsMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
SquareMatrix
Create a new square matrix with a unit.- Parameters:
displayUnit- the display unit to use
-
-
Method Details
-
order
public int order()Return the order (the number of rows/columns) of this matrix.- Returns:
- the order (the number of rows/columns) of this matrix
-
transpose
Return the transposed square matrix. A transposed matrix has the same unit as the original one.- Returns:
- the transposed square matrix
-
determinantScalar
public double determinantScalar()Return the determinant of the square matrix as a scalar in SI or BASE units.- Returns:
- the determinant of the square matrix as a scalar in SI or BASE units
-
determinant
Return the determinant of the square matrix as quantity with unit U^n where n is the order of the matrix.- Returns:
- the determinant of the square matrix as a quantity
-
getDiagonalVector
Retrieve the main diagonal of the matrix as a column vector.- Returns:
- the main diagonal as a Vector
-
getDiagonalScalars
Retrieve the main diagonal of the matrix as an array of scalars.- Returns:
- the main diagonal as a Scalar array
-
getDiagonalSi
public double[] getDiagonalSi()Retrieve the main diagonal of the matrix as an array of doubles with SI-values.- Returns:
- the main diagonal as a doube array with SI-values
-
inverse
Return the inverse of the square matrix, if the matrix is non-singular. The unit of the matrix is U^(-1).- Returns:
- the inverse of the square matrix, if the matrix is non-singular
- Throws:
NonInvertibleMatrixException- when the matrix is singular or cannot be inverted
-
adjugate
Return the adjugate (classical adjoint) matrix for this matrix, often denoted as adj(M). The unit of adj(M) is U^(n-1) where n is the order of the matrix.- Returns:
- the adjugate (classical adjoint) matrix
-
trace
Return the trace of the matrix (the sum of the diagonal elements). It results in a quantity with the same unit as the original matrix.- Returns:
- the trace of this matrix
-
normFrobenius
Return the Frobenius norm of the matrix, which is equal to sqrt(trace(A*.A)). It results in a quantity with the same unit as the original matrix. See https://en.wikipedia.org/wiki/Matrix_norm#Frobenius_norm for more information.- Returns:
- the Frobenius norm of this matrix
-
isSymmetric
public boolean isSymmetric()Return whether the matrix is symmetric. Use a public tolerance of 1.0E-12 times the largest absolute si quantity.- Returns:
- whether the matrix is symmetric
-
isSymmetric
Return whether the matrix is symmetric, up to a tolerance.- Parameters:
tolerance- the tolerance, expressed as a quantity- Returns:
- whether the matrix is symmetric
-
isSkewSymmetric
public boolean isSkewSymmetric()Return whether the matrix is skew symmetric. Use a public tolerance of 1.0E-12 times the largest absolute si quantity.- Returns:
- whether the matrix is skew symmetric
-
isSkewSymmetric
Return whether the matrix is skew symmetric, up to a tolerance.- Parameters:
tolerance- the tolerance, expressed as a quantity- Returns:
- whether the matrix is skew symmetric
-