Пример #1
0
//! compute this = this - B
bool DenseMatrix::Subtract( const DenseMatrix & B )
{
	if ( Rows() != B.Rows() || Columns() != B.Columns() )
		return false;			// matrices are incompatible

	for ( unsigned int r = 0; r < m_nRows; ++r ) {
		for ( unsigned int c = 0; c < m_nCols; ++c ) {
			M(r,c) -= M_B(c,r);
		}
	}
	return true;
}
Пример #2
0
//! compute C = this*B;
bool DenseMatrix::Multiply(const DenseMatrix & B, DenseMatrix & C) const
{
	unsigned int nRowsA = Rows();
	unsigned int nColsA = Columns();
	unsigned int nRowsB = B.Rows();
	unsigned int nColsB = B.Columns();

	if ( nColsA != nRowsB )
		return false;			// matrices are incompatible

	C.Resize(nRowsA,nColsB);
	for ( unsigned int ra = 0; ra < nRowsA; ++ra ) {
		for ( unsigned int cb = 0; cb < nColsB; ++cb ) {

			double rcsum = 0;
			for ( unsigned int ca = 0; ca < nColsA; ++ca )
				rcsum += M(ra,ca) * M_B(ca,cb);

			M_C(ra,cb) = rcsum;
		}
	}

	return true;
}