Matrix Library. v1.6.4 + some changes

Revision:
1:48f417da268e
Parent:
0:3abd8c2d7c34
Child:
2:493402568a5e
--- a/Matrix.h	Fri Sep 23 21:12:17 2011 +0000
+++ b/Matrix.h	Mon Sep 26 03:23:35 2011 +0000
@@ -9,10 +9,12 @@
  *
  */
 
+#ifndef MATRIX_H
+#define MATRIX_H
+
 #include <vector>
 
-#ifndef MATRIX_H
-#define MATRIX_H
+using namespace std;
 
 /**
  * @brief This class is intended to provide basic functionality to a Matrix like vector
@@ -32,7 +34,7 @@
  * myMatrix.print();      // Re-prints Matrix
  *
  * Matrix anotherMatrix (3);  // Squared 3x3 Matrix
- * anotherMatrix = myMatrix;  // Re-Sizes 'anotherMatrix' to fit myMatrix
+ * anotherMatrix = myMatrix;  // Re-Sizes 'anotherMatrix' to fit myMatrix and copies data.
  * anotherMatrix += myMatrix; // Adds one-by-one elements and saves to anotherMatrix
  * anotherMatrix.print();
  * @endcode
@@ -44,7 +46,7 @@
     /// Creates a nex Matrix of Size [ Row x Cols ]
     Matrix( int Rows, int Cols );
 
-    /// Creats a Square Matrix o Size [ Roxs x Rows ]
+    /// Creats a Square Matrix o Size [ Rows x Rows ]
     Matrix( int Rows );
 
     
@@ -57,14 +59,15 @@
 
 
 
-    /** @brief Description:
+    /** @brief
      * This is the '=' Overloaded operator. It RESIZES assigned the matrix.
      * Overwrites all data. To be used Carefully!
      */
     Matrix& operator = ( const Matrix &rightM );
 
 
-    /**@brief Description:
+    
+    /** @brief
      * Overload opeartor for the compare Matrices
      *
      * @param rightM
@@ -74,7 +77,7 @@
 
 
 
-    /**@brief Description:
+    /** @brief
      * Overload opeartor for the compare Matrices
      *
      * @param rightM
@@ -82,8 +85,9 @@
      */
     bool operator != ( const Matrix &rightM );
 
-    /**@brief
-     * Description:
+    
+    
+    /** @brief
      * Overload Copmpound assignment.
      * @param rightM
      * @return A new Matrix to be assigned to itself.
@@ -92,8 +96,7 @@
 
 
 
-    /**@brief
-     * Description:
+    /** @brief
      * Overload Compund decrease.
      * @param rightM Right hand matrix
      * @return A new Matrix to be assigned to itself
@@ -102,58 +105,25 @@
 
 
 
-    /**@brief
-     * Description:
+    /** @brief
      * Overloads the Plus, returns a new object.
      * @param rightM right side Matrix
      * @return Retuns an instance of the answer.
      */
     const Matrix operator +( const Matrix &rightM );
 
+    
 
-    /**@brief
-     * Description:
+    /** @brief
      * Overloads the Minus, returns a new object
      * @param rightM
      * @return Returns an instance of the asnwer
      */
     const Matrix operator -( const Matrix &rightM );
 
-
-
-    /** @brief
-     * Description:
-     * This method extracts a Row from a Matrix.
-     * If Row is out of the parameters, it returns
-     * an empty Row and prints a warning
-     * @param Matrix: Matrix to extract from
-     * @param Row: row number of the matrix
-     */
-    Matrix GetRow(Matrix mat, int Row);
-
-
-
+     
+    
     /** @brief
-     * Description:
-     * This method extracts a Column from a Matrix.
-     * If Row is out of the parameters, it returns
-     * an empty Column and prints a warning
-     */
-    Matrix GetCol(Matrix mat, int Col);
-
-
-
-    /** @brief
-     * Description:
-     * Shatters the matrix into a single Row Vector.
-     * Important: Returns NEW matrix, does no modify existing one.
-     */
-    Matrix ToPackedVector();
-
-
-
-    /** @brief
-     * Description:
      * Returns TRUE if the matrix is zero, FALSE otherwhise
      * @param mat: Matrix to be tested
      */
@@ -162,25 +132,30 @@
 
 
     /** @brief
-     * Description:
      * Determines weather a Matrix is a Single Column or Row.
      */
     bool isVector();
 
 
+ 
+    /** @brief
+     * Shatters the matrix into a single Row Vector.
+     * Important: Returns NEW matrix, does no modify existing one.
+     */
+    Matrix ToPackedVector();
 
-    /**@brief
-     * Description:
+
+     
+    /** @brief
      * Determines if two matrices are equal.
      * @param mat1: First Matrix
      * @param mat2: Sencond Matrix
      */
-    static const bool Equals( Matrix mat1, Matrix mat2 );
+    static bool Equals( const Matrix mat1, const Matrix mat2 );
 
 
 
     /**@brief
-     * Description:
      * This Funcrions instanciates a new Row Matrix. Since this is a
      * static function it needs to be assigned to an Empy Matrix Object
      * @param Rows: Number of Rows
@@ -189,9 +164,7 @@
 
 
 
-
-    /**@brief
-     * Description:
+    /** @brief
      * This function instanciates a new Column Matrix. Since this is a
      * static function it needs to be assigned to an Empty Matrix object
      * @param Cols: Number of Columns in Matrix
@@ -200,8 +173,7 @@
 
 
 
-    /**@brief
-     * Description:
+    /** @brief
      * This STATIC function Clones two Matrices.
      * The Source Matrix can be any Size.
      * The Receip Matrix MUST be just initialized
@@ -209,12 +181,30 @@
      * @param Source: Base Matrix to Clone.
      * @param Receip: Destination shell matrix
      */
-    static void Clone( const Matrix &Source, Matrix Receip );
-
+    static void Clone( const Matrix &Source, Matrix &Receip );
 
+    
+    /** @brief
+     * Invoking this static method will increase a Row in Mat in the desired 
+     * position.
+     * The current Row will be moved down to allocate space, and all elements will
+     * be initialized to zero in the new row.
+     * @param Mat: Matrix in wich to insert a Row 
+     * @param Row: Number of row to insert, starts with one, not zero.
+     */   
+    static void AddRow( Matrix &Mat, int Row );
 
-    /**@brief
-     * Description:
+    
+    /** @brief
+     * Invoking this static method will increase a Column in Matrix in the 
+     * desired Position.
+     * @param Mat: Matrix in wich to insert a Column
+     * @param Col: Number of column, strats with one, not zero.
+     */
+    static void AddColumn( Matrix &Mat, int Col );
+    
+
+    /** @brief
      * Static Function Deletes Row from Matrix, Static to prevent missuse
      * @param Mat: Matrix to delete Row from
      * @param Row: Number of Row (first Row = 1)
@@ -222,32 +212,43 @@
     static void DeleteRow( Matrix &Mat, int Row );
 
 
-    /**@brief
-     * Description:
+    /** @brief
      * Static Function Deletes Column from Matrix, it's Static to prevent
      * missuse.
      * Print error and does nothing if out of limits.
-     * @Mat: Matrix to delete column from
      * @param Col: Number of Col to delete (first Col = 1)
+     * @param Mat: Matrix to delete from.
      */
     static void DeleteCol( Matrix &Mat, int Col );
 
 
 
-    /**@brief
-     * Description:
-     * Assigns a float number to the matrix in position
-     *
-     * @param number:   Number to be set
-     * @param Row:      Row of Matrix
-     * @param Col:      Column of Matrix
+
+     /** @brief
+     * This method extracts a Row from a Matrix and Saves it in Mat.
+     * If Row is out of the parameters it does nothing, but prints a warning.
+     * @param Row: number of row to extract elements. this->_nRows.
+     * @param Mat: Matrix to resize if neccesaty and save data.
      */
-    void Add( int Row, int Col, float number );
+     void ExportRow( int Row, Matrix &Mat);
+
+
+     
+     
+     
+     
+
+    /** @brief
+     * This method extracts a Column from a Matrix and saves it to Mat.
+     * If Row is out of the parameters, it does nothing and prints a warning.
+     * @param Col: number of Column to extract elements. this->_nCols.
+     * @param Mat: Matrix to save data to.
+     */
+     void ExportCol( int Col, Matrix &Mat );
 
 
 
-    /**@brief
-     * Description:
+    /** @brief
      * This function resizes the Matrix to fit new data.
      * @param Rows: New Number of Rows
      * @param Cols: New numbler of columns
@@ -257,53 +258,64 @@
 
 
     /** @brief
-     * Description:
-     * Asks user for numbers to fill the Matrix elements. One by one
+     * Asks user for numbers to fill the Matrix elements, one by one.
+     * It uses printf(); by default the USBTX, USBRX, 9600, 1N8.
      */
     void FillMatrix();
 
 
 
     /** @brief
-     * Description:
-     * Makes all values on Matrix object zero.
-     */
-    void Clear();
-
-
-
-    /** @brief
-     * Description:
      * Prints the entire Matrix
      */
     void print();
 
 
+    
+    /** @brief
+     * Makes all values on Matrix object zero.
+     */
+    void Clear();
 
-    /** \brief
-     * Description:
-     * Returns the sum of every cell in the Matrix.
+    
+    /** @brief
+     * Assigns a float number to the matrix in a specified position
+     * Index starts at [1][1].
+     *
+     * @param number:   Number to be set
+     * @param Row:      Row of Matrix
+     * @param Col:      Column of Matrix
      */
-    float Sum();
+    void add( int Row, int Col, float number );
+
 
 
     /** @brief
-     * Description:
+     * Returns the sum of every cell in the Matrix.
+     */
+    float sum();
+
+
+    /** @brief
      * Return the number in position [Row],[Col]
      * @param Row = number of row in matrix
      * @param Col = number of Col in matrix
      * @return Num = float number in matrix
      */
-    float GetNumber( int Row, int Col );
+    float getNumber( int Row, int Col );
 
 
     
-    /**Retuns the number of Columns in Matrix*/
+    /**@brief
+     * Retuns the number of Columns in Matrix
+     */
     int  getCols();
 
 
 
-    /**Retruns the number of Rows in Matrix */
+    /**@brief
+     *Retruns the number of Rows in Matrix 
+     */
     int  getRows();
 
 
@@ -313,10 +325,10 @@
     vector < vector<float> > _matrix;
 
     /** Number of Rows in Matrix*/
-    int _Rows;
+    int _nRows;
 
     /**Number of Columns in Matrix*/
-    int _Cols;
+    int _nCols;
 
 };