public Matrix subtract ( Matrix m ) throws MatrixException { // Validate m's size. if ( ( nRows != m . nRows ) && ( nCols != m . nCols ) ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } double dv [ ] [ ] = new double [ nRows ] [ nCols ] ; // difference values // Compute values of the difference. for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { dv [ r ] [ c ] = values [ r ] [ c ] - m . values [ r ] [ c ] ; } } return new Matrix ( dv ) ; }
Subtract another matrix from this matrix .