/**
* Determines whether a square Matrix is symmetric or not.<br><br>
*
* Symmetric Matrix is a square Matrix that is equal to its transpose.<br><br>
*
* The result is cached.
* @memberof Matrix
* @instance
* @param {number} [digit=8] - Number of significant digits
* @returns {boolean} Returns true if the square Matrix is symmetric
*/
function isSymmetric(digit = this._digit) {
if (this._isSymmetric !== undefined) {
return this._isSymmetric;
}
if (!this.isSquare()) {
return false;
}
const A = this._matrix;
const EPSILON = 1 / ((10 ** digit) * 2);
const size = A.length;
for (let i = 0; i < size; i++) {
for (let j = 0; j <= i; j++) {
if (Math.abs(A[i][j] - A[j][i]) >= EPSILON) {
this._isSymmetric = false;
return false;
}
}
}
this._isSymmetric = true;
return true;
};
module.exports = isSymmetric;