@rayyamhk/matrix
Version:
A professional, comprehensive and high-performance library for you to manipulate matrices.
49 lines (41 loc) • 1.15 kB
JavaScript
/**
* Determines whether a square Matrix is skew symmetric or not.<br><br>
*
* Skew symmetric Matrix is a square Matrix whose transpose equals its negative.<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 skew symmetric
*/
function isSkewSymmetric() {
var digit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._digit;
if (this._isSkewSymmetric !== undefined) {
return this._isSkewSymmetric;
}
if (!this.isSquare()) {
this._isSkewSymmetric = false;
return false;
}
var A = this._matrix;
var EPSILON = 1 / (Math.pow(10, digit) * 2);
var size = A.length;
if (size === 0) {
this._isSkewSymmetric = true;
return true; // []
}
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._isSkewSymmetric = false;
return false;
}
}
}
this._isSkewSymmetric = true;
return true;
}
;
module.exports = isSkewSymmetric;
;