Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mmatrix.h

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003     copyright            : (C) 2000 by Marko Grönroos
00004     email                : magi@iki.fi
00005  ***************************************************************************
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************
00013  *
00014  **/
00015 
00016 #ifndef __MATRIX_H__
00017 #define __MATRIX_H__
00018 
00019 #include "magic/mobject.h"
00020 #include "magic/mtable.h"
00021 
00022 BEGIN_NAMESPACE (MagiC);
00023 
00024 // External declarations
00025 class OStream;
00026 template <class type>
00027 class PackArray;
00028 typedef PackArray<double> Vector;
00029 
00031 //                         |   |               o                             //
00032 //                         |\ /|  ___   |                                    //
00033 //                         | V |  ___| -+- |/\ | \ /                         //
00034 //                         | | | (   |  |  |   |  X                          //
00035 //                         |   |  \__|   \ |   | / \                         //
00037 
00040 class Matrix : public PackTable<double> {
00041   public:
00042                     Matrix          () : PackTable<double> () {;}
00043                     Matrix          (int rows, int cols) : PackTable<double> (rows, cols) {}
00044                     Matrix          (int rows, int cols, double* data);
00045                     Matrix          (const Matrix& o) : PackTable<double> (o) {;}
00046                     ~Matrix         () {}
00047 
00048     void            make            (int rs, int cs);
00049     void            load            (const String& filename);
00050     void            load            (FILE* in);
00051     void            save            (FILE* out) const;
00052     
00053     const Matrix&   transpose       ();
00054     const Matrix&   multiplyToSum   (double s);
00055     double          sum             () const;
00056     double          det             () const;
00057 
00058     void            splitVertical   (Matrix& a, Matrix& b, int column) const;
00059     void            splitHorizontal (Matrix& a, Matrix& b, int column) const;
00060 
00061     Matrix          sub             (int row0, int row1, int col0, int col1) const;
00062     void            mulRowByScalar  (int row, double scalar);
00063     void            addRowByScalar  (int srcrow, int dstrow, double scalar);
00064     void            swaprows        (int row1, int row2);
00065     Matrix          complement      (int row, int col) const;
00066     void            insertColumn    (int cols);
00067     
00068     enum iters {end=-1};
00069 
00070     void            joinVertical    (const Matrix& a, const Vector& b);
00071     void            joinVertical    (const Matrix& a, const Matrix& b);
00072     void            joinHorizontal  (const Matrix& a, const Matrix& b);
00073     
00074     const Matrix&   operator=		(double x);
00075     const Matrix&   operator+=		(const Matrix& other);
00076     const Matrix&   operator+       (const Matrix& other) const {return Matrix(*this)+=other;}
00077     const Matrix&   operator+=		(double k);
00078     const Matrix&   operator+       (double k) const {return Matrix(*this)+=k;}
00079     const Matrix&   operator*=		(const Matrix& other);
00080     const Matrix&   operator*       (const Matrix& other) const {return Matrix(*this)*=other;}
00081     const Matrix&   operator*=		(double k);
00082     const Matrix&   operator*       (double k) const {return Matrix(*this)*=k;}
00083     const Matrix&   operator/       (double k) const {return Matrix(*this)*=1/k;}
00084     const Matrix&   operator/=      (double k) {return operator *= (1/k);}
00085 
00086     TextOStream&    operator>>      (TextOStream&) const;
00087     const Matrix&   operator= (const Matrix& other);
00088 
00089   private:
00090 };
00091 
00092 inline Matrix transpose (const Matrix& m) {
00093     Matrix res = m;
00094     res.transpose ();
00095     return res;
00096 }
00097 
00098 int solveLinear (const Matrix& mat, const Vector& b, Vector& result);
00099 int solveLinear (const Matrix& augmat, Vector& result, int* nbv_set = NULL);
00100 
00101 
00102 /*
00103 class SubMatrix : public Matrix {
00104     Matrix& matrix;
00105     int srow, scol, erow, ecol;
00106   public:
00107                     SubMatrix       (Matrix& m, int sr, int sc, int er, int ec) : matrix (m) {
00108                         ASSERT (sr<m.rows);
00109                         ASSERT (sc<m.cols);
00110                         ASSERT (er<m.rows);
00111                         ASSERT (ec<m.cols);
00112                         ASSERT (sr<=er);
00113                         ASSERT (sc<=ec);
00114                         srow=sr, scol=sc, erow=er, ecol=ec;
00115                         rows = erow-srow+1;
00116                         cols = ecol-scol+1;
00117                     }
00118     double&         get             (int row, int col);
00119 };
00120 */
00121 
00122 END_NAMESPACE;
00123 
00124 #endif
00125 

Generated on Thu Feb 10 20:06:42 2005 for LibMagiC by doxygen1.2.18