public E [ ] [ ] multiplyMatrix ( E [ ] [ ] matrix1 , E [ ] [ ] matrix2 ) { // Check bounds if ( matrix1 [ 0 ] . length != matrix2 . length ) { throw new SecretShareException ( "The matrices do not have compatible size" ) ; } // Create result matrix E [ ] [ ] result = //(E[][]) new Number[matrix1.length][matrix2[0].length]; create ( matrix1 . length , matrix2 [ 0 ] . length ) ; // Perform multiplication of two matrices for ( int i = 0 ; i < result . length ; i ++ ) { for ( int j = 0 ; j < result [ 0 ] . length ; j ++ ) { result [ i ] [ j ] = zero ( ) ; for ( int k = 0 ; k < matrix1 [ 0 ] . length ; k ++ ) { result [ i ] [ j ] = add ( result [ i ] [ j ] , multiply ( matrix1 [ i ] [ k ] , matrix2 [ k ] [ j ] ) ) ; } } } return result ; }
Multiply two matrices .