00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00025 class OStream;
00026 template <class type>
00027 class PackArray;
00028 typedef PackArray<double> Vector;
00029
00031
00032
00033
00034
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
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 END_NAMESPACE;
00123
00124 #endif
00125