/// Scales a matrix, multiplying all element by all other elements of /// matra (it is not the classical matrix multiplication!) public void MatrScale(ChMatrix matra) { // Debug.Assert(matra.GetColumns() == columns && matra.GetRows() == rows); for (int nel = 0; nel < rows * columns; ++nel) { ElementN(nel) *= matra.ElementN(nel); } }
// // MATH MEMBER FUNCTIONS. // For speed reasons, sometimes size checking of operands is left to the user! // /// Subtract two matrices, and stores the result in "this" matrix: [this]=[A]-[B]. public void MatrSub(ChMatrix matra, ChMatrix matrb) { // Debug.Assert(matra.GetColumns() == matrb.GetColumns() && matra.rows == matrb.GetRows()); // Debug.Assert(this.columns == matrb.GetColumns() && this.rows == matrb.GetRows()); for (int nel = 0; nel < rows * columns; ++nel) { ElementN(nel) = (matra.ElementN(nel) - matrb.ElementN(nel)); } }
public void MatrAdd(ChMatrix matra, ChMatrix matrb) { //assert(matra.GetColumns() == matrb.GetColumns() && matra.rows == matrb.GetRows()); //assert(this->columns == matrb.GetColumns() && this->rows == matrb.GetRows()); for (int nel = 0; nel < rows * columns; ++nel) { ElementN(nel) = (double)(matra.ElementN(nel) + matrb.ElementN(nel)); } }
/// Computes dot product between two column-matrices (vectors) with /// same size. Returns a scalar value. public double MatrDot(ChMatrix ma, ChMatrix mb) { //ssert(ma.GetColumns() == mb.GetColumns() && ma.GetRows() == mb.GetRows()); double tot = 0; for (int i = 0; i < ma.GetRows(); ++i) { tot += (double)(ma.ElementN(i) * mb.ElementN(i)); } return(tot); }
/// Returns true if vector equals another vector, within a tolerance 'tol' public bool Equals(ChMatrix other, double tol) { if ((other.GetColumns() != this.columns) || (other.GetRows() != this.rows)) { return(false); } for (int nel = 0; nel < rows * columns; ++nel) { if (Mathfx.Abs(ElementN(nel) - other.ElementN(nel)) > tol) { return(false); } } return(true); }