Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Matrix.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file Matrix.h
00003 *  \brief Wrapper of CammVa Matrix & Matrix Library.
00004 *  \author Andrew Turner <ajturner@vt.edu>
00005 *  \version 0.1
00006 *  \date   2003
00007 //////////////////////////////////////////////////////////////////////////////////////////////////
00008 *  \todo Add overloading of operators
00009 *  \todo Reference cammva documentation
00010 */
00011 //////////////////////////////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef MATRIX_H
00014 #define MATRIX_H
00015 
00016 #include <iostream>
00017 
00018 #include "cammva.h"
00019 
00020 #include <math.h>
00021 
00022 namespace O_SESSAME {
00023 
00024 const int MatrixIndexBase = 1; /*!<< Beginning index of Matrix class */
00025 const int VectorIndexBase = 1; /*!<< Beginning index of Vector class */
00026 const int MatrixRowsIndex = 1; /*!<< Value referring to the "rows" index  */
00027 const int MatrixColsIndex = 2; /*!<< Value referring to the "columns" index  */
00028 typedef CAMdoubleMatrix Matrix; /*!<< Encapsulation of CAMdoubleMatrix class  */
00029 typedef CAMdoubleVector Vector; /*!<< Encapsulation of CAMdoubleVector class  */
00030 
00031 /** Returns the absolute value of a vector
00032  *  @param _vector
00033  */
00034 inline Vector Vabs( Vector _vector )
00035 {
00036         int num = _vector.getIndexCount( );
00037         Vector outVector(num);
00038         for( int ii=1; ii <= num; ii++ )
00039         {
00040                 if( _vector(ii) < 0 )
00041                 {
00042                         outVector(ii) = fabs( _vector(ii) );
00043                 }
00044                 else
00045                 {
00046                         outVector(ii) = _vector(ii);
00047                 }
00048         }
00049         return( outVector );
00050 }
00051 
00052 /** Creates an square identity matrix of specified size.
00053 * @param _rowColumns Number of rows and columns to size matrix (will be a square matrix).
00054 * \todo Implement eye as part of Vector or CAMdoubleVector class
00055 */
00056 inline Matrix eye(int _rowColumns)
00057 {
00058     Matrix eyeOutput(_rowColumns,_rowColumns);
00059     eyeOutput.setToValue(0.0);
00060     for(int ii = MatrixIndexBase;ii < _rowColumns + MatrixIndexBase; ++ii)
00061         eyeOutput(ii,ii) = 1.0;
00062     return eyeOutput;
00063 }
00064 
00065 /** Calculates the trace of matrix (sum of elements along diagonal).
00066 * @param _inMatrix Matrix to have trace calculated.
00067 * \todo Implement trace as part of Vector or CAMdoubleVector class
00068 */
00069 inline double trace(const Matrix &_inMatrix)
00070 {
00071     double Sum = 0;
00072     for(int ii = MatrixIndexBase;ii < _inMatrix[MatrixRowsIndex].getIndexCount() + MatrixIndexBase; ++ii)
00073         Sum += _inMatrix(ii,ii);
00074     return Sum;
00075 }
00076 
00077 /** Calculates the 2-norm of the vector (square-root of the sum of the squares).
00078 * \todo Implement norm2 as part of Vector or CAMdoubleVector class
00079 * @param _inVector Vector to calculate the 2-norm of.
00080 * @return Square-root of the sum of squares of elements in vector.
00081 */
00082 inline double norm2(const Vector &_inVector)
00083 {
00084     double Sum = 0;
00085     for(int ii = VectorIndexBase;ii < _inVector.getIndexCount() + VectorIndexBase; ++ii)
00086         Sum += _inVector(ii) * _inVector(ii);
00087     return sqrt(Sum);
00088 }
00089 
00090 /** Normalizes a vector.
00091  * @param _inVector Vector to be normalized.
00092 * \todo Implement normalize as part of Vector or CAMdoubleVector class
00093  */
00094 inline void normalize(Vector &_inVector)
00095 {
00096     _inVector /= norm2(_inVector);
00097     return;
00098 }
00099 
00100 /** Calculates the Infinity-norm of the vector (largest value of the components).
00101 * @param _inVector Vector to calculate the 2-norm of.
00102 * @return Absolute value of maximum component in vector.
00103 * \todo Implement normInf as part of Vector or CAMdoubleVector class
00104 */
00105 inline double normInf(const Vector &_inVector)
00106 {
00107     return _inVector.maxAbs();
00108 }
00109 
00110 /** Calculates the skew-symmetric matrix of a vector.
00111 * Equation:
00112 /f[
00113     \bf{v^{\times}} =
00114     \begin{bmatrix}
00115     0 & -v_3 & v_2\\
00116     v_3 & 0 & -v_1\\
00117     -v_2 & v_1 & 0
00118     \end{bmatrix}
00119 /f]
00120 * @param _inVector Vector to calculate the skew-symmetric matrix of.
00121 * @return Skew-symmetric matrix (3x3).
00122 * \todo Implement skew as part of Vector or CAMdoubleVector class
00123 */
00124 inline Matrix skew(const Vector &_inVector)
00125 {
00126     Matrix Rout(3,3);
00127     Rout.setToValue(0.0);
00128     Rout(MatrixIndexBase+0,MatrixIndexBase+1) =
00129         -_inVector(VectorIndexBase+2);
00130     Rout(MatrixIndexBase+0,MatrixIndexBase+2) =
00131         _inVector(VectorIndexBase+1);
00132     Rout(MatrixIndexBase+1,MatrixIndexBase+0) =
00133         _inVector(VectorIndexBase+2);
00134     Rout(MatrixIndexBase+1,MatrixIndexBase+2) =
00135         -_inVector(VectorIndexBase+0);
00136     Rout(MatrixIndexBase+2,MatrixIndexBase+0) =
00137         -_inVector(VectorIndexBase+1);
00138     Rout(MatrixIndexBase+2,MatrixIndexBase+1) =
00139         _inVector(VectorIndexBase+0);
00140     return Rout;
00141 }
00142 
00143 /** Calculates the cross product of 2 vectors.
00144 * Equation: /f$ v_3 = v_1 \cross v_2 = v_1/f$
00145 * @param _inVector Vector to calculate the 2-norm of.
00146 * @return Cross product of 2 vectors.
00147 * \todo Implement crossP as part of Vector or CAMdoubleVector class
00148 */
00149 inline Vector crossP(const Vector &_v1, const Vector &_v2)
00150 {
00151     return skew(_v1) * _v2;
00152 }
00153 }
00154 #endif
00155 
00156 

Generated on Wed Sep 5 12:54:22 2007 for DSACSS Operational Code by  doxygen 1.3.9.1