mitsuki31 / jmatrix

A lightweight Java library for basic introduction to matrix and linear algebra concepts.
https://mitsuki31.github.io/jmatrix/
Apache License 2.0
1 stars 0 forks source link

feat(matrix): Introduce `isIdentity` method along with static counterparts to `Matrix` class #112

Closed mitsuki31 closed 4 months ago

mitsuki31 commented 4 months ago

Summary

This change introduces a new method called isIdentity to the Matrix class. Along with its static counterparts, this method efficiently checks whether the matrix or the 2D (two-dimensional) array represents an identity matrix. An identity matrix is defined as a square matrix where all diagonal elements are $1$ and all other elements are $0$. This addition enhances the functionality of the Matrix class, providing users with a convenient tool for matrix identity verification. The change also includes comprehensive Javadoc documentation for the newly added method, including details on its functionality, parameters, exceptions, and performance analysis (including time complexity and space complexity).

An example of identity matrix:

\begin{bmatrix}
  1 & 0 & 0 & 0 & 0 \\
  0 & 1 & 0 & 0 & 0 \\
  0 & 0 & 1 & 0 & 0 \\
  0 & 0 & 0 & 1 & 0 \\
  0 & 0 & 0 & 0 & 1
 \end{bmatrix}

\; \leftrightarrow \;

\begin{bmatrix}
  1.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
  0.0 & 1.0 & 0.0 & 0.0 & 0.0 \\
  0.0 & 0.0 & 1.0 & 0.0 & 0.0 \\
  0.0 & 0.0 & 0.0 & 1.0 & 0.0 \\
  0.0 & 0.0 & 0.0 & 0.0 & 1.0
\end{bmatrix}

[!NOTE]
Please use the isDiagonal method if you just want to check whether the matrix or two-dimensional array represents a diagonal matrix. A diagonal matrix is a square matrix in which all the entries on the main diagonal is not equal to $0$ (it can be both negative and positive values, but not zero) and the entries outside of the main diagonal are $0$ (more precisely, it takes the absolute values and must be lower than Matrix.THRESHOLD).