Esempio n. 1
0
 /// 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));
         }
     }
 }
Esempio n. 2
0
        /// Paste a given matrix into \a this sparse matrix at position (\a insrow, \a inscol).
        /// The matrix \a matra will be copied into \a this[insrow : insrow + \a matra.GetRows()][[inscol : inscol + matra.GetColumns()]]
        /// \param[in] matra The source matrix that will be copied;
        /// \param[in] insrow The row index where the first element will be copied;
        /// \param[in] inscol The column index where the first element will be copied;
        /// \param[in] overwrite Tells if the copied element will overwrite an existing element or be summed to it;
        /// \param[in] transp Tells if the \a matra matrix should be copied transposed.
        public virtual void PasteMatrix(ChMatrix matra, int insrow, int inscol, bool overwrite = true, bool transp = false)
        {
            var maxrows = matra.GetRows();
            var maxcols = matra.GetColumns();

            if (transp)
            {
                for (var i = 0; i < maxcols; i++)
                {
                    for (var j = 0; j < maxrows; j++)
                    {
                        this.SetElement(insrow + i, inscol + j, matra[j, i], overwrite);
                    }
                }
            }
            else
            {
                for (var i = 0; i < maxrows; i++)
                {
                    for (var j = 0; j < maxcols; j++)
                    {
                        this.SetElement(insrow + i, inscol + j, matra[i, j], overwrite);
                    }
                }
            }
        }
Esempio n. 3
0
 /// Copy a matrix "matra" into this matrix. Note that
 /// the destination matrix will be resized if necessary.
 //template<class doubleB>
 public void CopyFromMatrix(ChMatrix matra)
 {
     Resize(matra.GetRows(), matra.GetColumns());
     for (int i = 0; i < rows * columns; ++i)
     {
         address[i] = matra.GetAddress()[i];
     }
 }
Esempio n. 4
0
        //
        // 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);
                }
            }
        }
Esempio n. 5
0
 /// Copy the transposed lower triangulat part of "matra" in the upper triangular
 /// part of this matrix. (matra must be square)
 /// Note that the destination matrix will be resized if necessary.
 //                      _______     //
 public void CopyTLwMatrix(ChMatrix matra)        //    |\                \      |    //
 {                                                //    |  \      --->      \this|    //
     Resize(matra.GetRows(), matra.GetColumns()); //    |A'  \                \  |    //
     for (int i = 0; i < matra.GetRows(); i++)
     {                                            //    |______\                \|    //
         for (int j = 0; j < matra.GetRows(); j++)
         {
             SetElement(i, j, matra.GetElement(j, i));
         }
     }
 }
Esempio n. 6
0
 /// Copy the transposed upper triangular part of "matra" in the lower triangular
 /// part of this matrix. (matra must be square)
 /// Note that the destination matrix will be resized if necessary.
 //                                                      _______                       //
 public void CopyTUpMatrix(ChMatrix matra)        //    \      |          |\          //
 {                                                //      \  A'|   --->   |  \        //
     Resize(matra.GetRows(), matra.GetColumns()); //        \  |          |this\      //
     for (int i = 0; i < matra.GetRows(); i++)
     {                                            //          \|          |______\    //
         for (int j = 0; j < matra.GetRows(); j++)
         {
             SetElement(j, i, matra.GetElement(i, j));
         }
     }
 }
Esempio n. 7
0
 /// 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);
 }
Esempio n. 8
0
        /// Copy constructor from all types of base matrices
        public ChMatrixDynamic(ChMatrix msource)//:this()
        {
            matrix              = new ChMatrix();
            this.matrix.rows    = msource.GetRows();
            this.matrix.columns = msource.GetColumns();
            this.matrix.address = new double[this.matrix.rows * this.matrix.columns];

            /*this.address = (double*)Marshal.AllocHGlobal(this.rows * this.columns * sizeof(double));
             * double[] array = new double[this.rows * this.columns];
             * for (int i = 0; i < array.Length; i++)
             * {
             *  this.address[i] = array[i];
             * }*/
            for (int i = 0; i < this.matrix.rows * this.matrix.columns; ++i)
            {
                this.matrix.address[i] = msource.GetAddress()[i];
            }
        }
Esempio n. 9
0
        /// 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);
                }
            }
        }