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 type
U - the unit type
M - the 'SELF' square matrix type
SI - 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 Details

    • SquareMatrix

      public SquareMatrix(U displayUnit)
      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

      public M 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

      public SIQuantity 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

      public abstract Vector<Q,U,?,?,?> getDiagonalVector()
      Retrieve the main diagonal of the matrix as a column vector.
      Returns:
      the main diagonal as a Vector
    • getDiagonalScalars

      public Q[] 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

      public abstract SI inverse() throws NonInvertibleMatrixException
      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

      public abstract SI 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

      public Q 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

      public Q 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

      public boolean isSymmetric(Q tolerance)
      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

      public boolean isSkewSymmetric(Q tolerance)
      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