Check whether a given matrix is orthogonal or not | C # code to check whether a 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
using System ; class GFG { static bool isOrthogonal ( int [ , ] a , int m , int n ) { if ( m != n ) return false ; int [ , ] trans = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) trans [ i , j ] = a [ j , i ] ; int [ , ] prod = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int sum = 0 ; for ( int k = 0 ; k < n ; k ++ ) { sum = sum + ( a [ i , k ] * a [ j , k ] ) ; } prod [ i , j ] = sum ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int 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 ; } static public void Main ( ) { int [ , ] a = { { 1 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 1 } } ; if ( isOrthogonal ( a , 3 , 3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }