Check whether a given matrix is orthogonal or not | Function to check orthogonalilty ; Find transpose ; Find product of a [ ] [ ] and its transpose ; Since we are multiplying transpose of itself . We use ; Check if product is identity matrix ; Driver code
function isOrthogonal ( a , m , n ) { if ( m != n ) return false ; let trans = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { trans [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) trans [ i ] [ j ] = a [ j ] [ i ] ; } let prod = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { prod [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { let sum = 0 ; for ( let k = 0 ; k < n ; k ++ ) { sum = sum + ( a [ i ] [ k ] * a [ j ] [ k ] ) ; } prod [ i ] [ j ] = sum ; } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i != j && prod [ i ] [ j ] != 0 ) return false ; if ( i == j && prod [ i ] [ j ] != 1 ) return false ; } } return true ; } let a = [ [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] , [ 0 , 0 , 1 ] ] ; if ( isOrthogonal ( a , 3 , 3 ) ) document . write ( " " ) ; else document . write ( " " ) ;