UNPKG

@rayyamhk/matrix

Version:

A professional, comprehensive and high-performance library for you to manipulate matrices.

43 lines (36 loc) 990 B
"use strict"; /** * 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() { var digit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._digit; if (this._isSymmetric !== undefined) { return this._isSymmetric; } if (!this.isSquare()) { return false; } var A = this._matrix; var EPSILON = 1 / (Math.pow(10, digit) * 2); var size = A.length; for (var i = 0; i < size; i++) { for (var 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;