UNPKG

@rayyamhk/matrix

Version:

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

56 lines (46 loc) 1.28 kB
"use strict"; /** * Determines whether a square Matrix is orthogonal or not.<br><br> * * Orthogonal Matrix is a Matrix in which all rows and columns are * orthonormal vectors.<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 orthogonal */ function isOrthogonal() { var digit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._digit; if (this._isOrthogonal !== undefined) { return this._isOrthogonal; } if (!this.isSquare()) { this._isOrthogonal = false; 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 = i; j < size; j++) { var entry = 0; for (var k = 0; k < size; k++) { entry += A[i][k] * A[j][k]; } if (i === j && Math.abs(entry - 1) >= EPSILON) { this._isOrthogonal = false; return false; } if (i !== j && Math.abs(entry) >= EPSILON) { this._isOrthogonal = false; return false; } } } this._isOrthogonal = true; return true; } ; module.exports = isOrthogonal;