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 with transpose of itself . We use ; Check if product is identity matrix ; Driver Code
< ? php function isOrthogonal ( $ a , $ m , $ n ) { if ( $ m != $ n ) return false ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) for ( $ j = 0 ; $ j < $ n ; $ j ++ ) $ trans [ $ i ] [ $ j ] = $ a [ $ j ] [ $ i ] ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { $ sum = 0 ; for ( $ k = 0 ; $ k < $ n ; $ k ++ ) { $ sum = $ sum + ( $ a [ $ i ] [ $ k ] * $ a [ $ j ] [ $ k ] ) ; } $ prod [ $ i ] [ $ j ] = $ sum ; } } for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ 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 ; } $ a = array ( array ( 1 , 0 , 0 ) , array ( 0 , 1 , 0 ) , array ( 0 , 0 , 1 ) ) ; if ( isOrthogonal ( $ a , 3 , 3 ) ) echo " Yes " ; else echo " No " ; ? >