bool ON_Matrix::Multiply( const ON_Matrix& a, const ON_Matrix& b ) { int i, j, k, mult_count; double x; if (a.ColCount() != b.RowCount() ) return false; if ( a.RowCount() < 1 || a.ColCount() < 1 || b.ColCount() < 1 ) return false; if ( this == &a ) { ON_Matrix tmp(a); return Multiply(tmp,b); } if ( this == &b ) { ON_Matrix tmp(b); return Multiply(a,tmp); } Create( a.RowCount(), b.ColCount() ); mult_count = a.ColCount(); double const*const* am = a.ThisM(); double const*const* bm = b.ThisM(); double** this_m = ThisM(); for ( i = 0; i < m_row_count; i++ ) for ( j = 0; j < m_col_count; j++ ) { x = 0.0; for (k = 0; k < mult_count; k++ ) { x += am[i][k] * bm[k][j]; } this_m[i][j] = x; } return true; }
bool ON_Matrix::Add( const ON_Matrix& a, const ON_Matrix& b ) { int i, j; if (a.ColCount() != b.ColCount() ) return false; if (a.RowCount() != b.RowCount() ) return false; if ( a.RowCount() < 1 || a.ColCount() < 1 ) return false; if ( this != &a && this != &b ) { Create( a.RowCount(), b.ColCount() ); } double const*const* am = a.ThisM(); double const*const* bm = b.ThisM(); double** this_m = ThisM(); for ( i = 0; i < m_row_count; i++ ) for ( j = 0; j < m_col_count; j++ ) { this_m[i][j] = am[i][j] + bm[i][j]; } return true; }