public Matrix add(Matrix m) throws MatrixException
    {
        // Validate m's size.
        if ((nRows != m.nRows) && (nCols != m.nCols)) {
            throw new MatrixException(
                                MatrixException.INVALID_DIMENSIONS);
        }

        double sv[][] = new double[nRows][nCols]; // sum values

        // Compute values of the sum.
        for (int r = 0; r < nRows; ++r) {
            for (int c = 0; c < nCols; ++c) {
                sv[r][c] = values[r][c] + m.values[r][c];
            }
        }

        return new Matrix(sv);
    }
public Matrix add ( Matrix m ) throws MatrixException { if ( ( nRows != m . nRows ) && ( nCols != m . nCols ) ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } double sv [ ] [ ] = new double [ nRows ] [ nCols ] ; for ( int r = 0 ; r < nRows ; ++ r ) { for ( int c = 0 ; c < nCols ; ++ c ) { sv [ r ] [ c ] = values [ r ] [ c ] + m . values [ r ] [ c ] ; } } return new Matrix ( sv ) ; }
Add another matrix to this matrix.
@param m the matrix addend
@return the sum matrix
@throws numbercruncher.MatrixException for invalid size