00001
00002
00003
00004
00005 #ifndef LINALG_H
00006 #define LINALG_H
00007
00008 #include <vector>
00009 #include <iostream>
00010 #include <iomanip>
00011 #include <cmath>
00012
00013
00014
00015
00016
00017
00018
00019
00020 class MatrixError
00021 {
00022 };
00023
00025 class Matrix
00026 {
00027 private:
00028 double *data;
00029 unsigned int nrows;
00030 unsigned int ncols;
00031
00032 std::vector<double> forward ( const Matrix* LU, const std::vector<double>& b );
00033 std::vector<double> backward ( const Matrix*LU, const std::vector<double>& y );
00034 public:
00035 Matrix ( const std::vector< std::vector<double> >& A );
00036 Matrix ( unsigned int nrows, unsigned int ncols);
00037 Matrix ( const Matrix& A );
00038 ~Matrix ( void ) { delete [] data; }
00039 double& operator() ( unsigned int i, unsigned int j ) const;
00040 void print ( void );
00041 unsigned int getnrows ( void ) const { return nrows; }
00042 unsigned int getncols ( void ) const { return ncols; }
00043 Matrix* cholesky_dec ( void ) const;
00044 Matrix* lu_dec ( void ) const;
00045 Matrix * qr_dec ( void ) const;
00046 Matrix * inverse_qr ( void ) const;
00047 Matrix * regularized_inverse ( double alpha ) const;
00048 std::vector<double> solve ( const std::vector<double>& b );
00049 Matrix* inverse ( void );
00050 std::vector<double> operator* ( std::vector<double>& x );
00051 void scale ( double a );
00052 bool symmetric ( void );
00053 };
00054
00055 std::vector<double> leastsq ( const Matrix *A, const std::vector<double>& b );
00056
00057 std::vector<double> leastsq ( const Matrix *M );
00058
00059 #endif