ph-math/src/main/java/com/helger/numbercruncher/matrix/Matrix.java
public Matrix add (final Matrix m) throws MatrixException
  {
    // Validate m's size.
    if ((m_nRows != m.m_nRows) && (m_nCols != m.m_nCols))
    {
      throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
    }

    final float sv[][] = new float [m_nRows] [m_nCols]; // sum values

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

    return new Matrix (sv);
  }
public Matrix add (final Matrix m) throws MatrixException
  {
    // Validate m's size.
    if ((m_nRows != m.m_nRows) && (m_nCols != m.m_nCols))
    {
      throw new MatrixException (MatrixException.INVALID_DIMENSIONS);
    }

    final float sv[][] = new float [m_nRows] [m_nCols]; // sum values

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

    return new Matrix (sv);
  }
public Matrix add ( final Matrix m ) throws MatrixException { // Validate m's size. if ( ( m_nRows != m . m_nRows ) && ( m_nCols != m . m_nCols ) ) { throw new MatrixException ( MatrixException . INVALID_DIMENSIONS ) ; } final float sv [ ] [ ] = new float [ m_nRows ] [ m_nCols ] ; // sum values // Compute values of the sum. for ( int r = 0 ; r < m_nRows ; ++ r ) { for ( int c = 0 ; c < m_nCols ; ++ c ) { sv [ r ] [ c ] = m_aValues [ r ] [ c ] + m . m_aValues [ r ] [ c ] ; } } return new Matrix ( sv ) ; }
Add another matrix to this matrix.

@param m
the matrix addend
@return the sum matrix
@throws MatrixException
for invalid size
Add another matrix to this matrix .