00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #ifndef SMATRIX_H
00021 #define SMATRIX_H
00022
00023 #ifdef WIN32
00024 #define EXPORTED_FUNCTION __declspec(dllexport)
00025 #else
00026 #define EXPORTED_FUNCTION
00027 #endif
00028
00029 #include <iostream>
00030 #include <cassert>
00031 #include <complex>
00032 using namespace std;
00033
00034 class Ket;
00035
00037
00043 class EXPORTED_FUNCTION SMatrix {
00044
00045 private:
00046 int dim;
00047 complex<double> *Mtab;
00048
00049
00050
00051
00052
00053
00054 int Mtabsize() const { return dim*dim; }
00055
00056 public:
00057
00058 SMatrix(int dim_i = 1);
00059 SMatrix(int dim_i, complex<double> diag);
00060 SMatrix(int dim_i, const complex<double> * Mtab_i);
00061 SMatrix(int dim_i, double *real, double *imag);
00062 SMatrix(const SMatrix & m);
00063 ~SMatrix();
00064
00065
00066 int getdim() const { return dim; }
00067 void redim(int ndim);
00068 void setdiag(complex<double> diag);
00069 void setdiag(complex<double> * tab_diag);
00070 void print(const char *option = "") const;
00071 void decompositionLU(SMatrix &L,SMatrix &U);
00072 void decompositionCholesky(SMatrix &L,SMatrix &U);
00073 void SolveCrout(Ket b,Ket &x,SMatrix Lm,SMatrix Um);
00074 void SolveSOR(Ket b,Ket &x);
00075 void SolveGaussSeidel(Ket b,Ket &x);
00076 complex<double> getdetformal() const;
00077 complex<double> getdet() const;
00078 complex<double> gettrace() const;
00079 double getnorm() const;
00080 double getmax(double a[],int n) const;
00081 SMatrix gettransposed() const;
00082 SMatrix gethermitiantransposed() const;
00083 SMatrix getreducedmatrix(int row, int col) const;
00084 SMatrix getinversedformal() const;
00085 SMatrix getinversed() const;
00086 SMatrix getabsmatrix() const;
00087 SMatrix getexpm() const;
00088
00090 complex<double> & operator() (int i, int j) {
00091 assert (i >= 1 && i <= dim);
00092 assert (j >= 1 && j <= dim);
00093 return Mtab[dim*(i-1) + (j-1)];
00094 }
00095
00097 complex<double> operator() (int i, int j) const {
00098 assert (i >= 1 && i <= dim);
00099 assert (j >= 1 && j <= dim);
00100 return Mtab[dim*(i-1) + (j-1)];
00101 }
00102
00103
00104 const SMatrix & operator=(const SMatrix & m);
00105 SMatrix operator+(const SMatrix & m) const;
00106 SMatrix operator-(const SMatrix & m) const;
00107 SMatrix operator*(const SMatrix & m) const;
00108 SMatrix operator/(const SMatrix & m) const;
00109
00110 friend EXPORTED_FUNCTION SMatrix operator*(complex<double> a, const SMatrix & m);
00111 friend EXPORTED_FUNCTION SMatrix operator*(double a, const SMatrix & m);
00112 friend EXPORTED_FUNCTION SMatrix operator*(const SMatrix & m,complex<double> a);
00113 friend EXPORTED_FUNCTION SMatrix operator*(const SMatrix & m,double a);
00114 friend EXPORTED_FUNCTION SMatrix operator*(complex<double> a,const SMatrix *m);
00115 friend EXPORTED_FUNCTION SMatrix operator/(const SMatrix & m,double a);
00116 friend EXPORTED_FUNCTION SMatrix operator/(const SMatrix & m,complex<double> a);
00117 friend EXPORTED_FUNCTION std::ostream & operator<< (std::ostream & out, const SMatrix & m);
00118
00119 };
00120
00121 #endif //SMATRIX_H
00122