// // BOOKKEEPING // /// Paste a matrix "matra" into "this", inserting at location insrow-inscol /// and performing a sum with the preexisting values. public void PasteSumMatrix(ChMatrix matra, int insrow, int inscol) { for (int i = 0; i < matra.GetRows(); ++i) { for (int j = 0; j < matra.GetColumns(); ++j) { Element(i + insrow, j + inscol) += matra.Element(i, j); } } }
/// Copy the transpose of matrix "matra" into this matrix. Note that /// the destination matrix will be resized if necessary. public void CopyFromMatrixT(ChMatrix matra) { Resize(matra.GetColumns(), matra.GetRows()); for (int i = 0; i < matra.GetRows(); ++i) { for (int j = 0; j < matra.GetColumns(); ++j) { SetElement(j, i, matra.Element(i, j)); } } }
/// Paste a clipped portion of the matrix "matra" into "this", /// inserting the clip (of size nrows, ncolumns) at the location insrow-inscol. public void PasteClippedMatrix(ChMatrix matra, int cliprow, int clipcol, int nrows, int ncolumns, int insrow, int inscol) { for (int i = 0; i < nrows; ++i) { for (int j = 0; j < ncolumns; ++j) { Element(i + insrow, j + inscol) = matra.Element(i + cliprow, j + clipcol); } } }
/// Multiplies two matrices (the first is considered transposed): [this]=[A]'*[B] /// Faster than doing A.MatrTranspose(); result.MatrMultiply(A,B); public void MatrTMultiply(ChMatrix matra, ChMatrix matrb) { //Debug.Assert(matra.GetRows() == matrb.GetRows()); //Debug.Assert(this.rows == matra.GetColumns()); // Debug.Assert(this.columns == matrb.GetColumns()); int col, row, colres; double sum; for (colres = 0; colres < matrb.GetColumns(); ++colres) { for (row = 0; row < matra.GetColumns(); ++row) { sum = 0; for (col = 0; col < (matra.GetRows()); ++col) { sum += (matra.Element(col, row) * matrb.Element(col, colres)); } SetElement(row, colres, sum); } } }