Changeset 926 in Sophya for trunk/SophyaLib/TArray/sopemtx.h
- Timestamp:
- Apr 13, 2000, 8:39:39 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/sopemtx.h
r850 r926 7 7 #include "tvector.h" 8 8 9 // doivent imperativement reste avant le namespace SOPHYA ! 10 /*! 11 \class SOPHYA::SimpleMatrixOperation 12 \ingroup TArray 13 Class for simple operation on TMatrix 14 \sa TMatrix TArray 15 */ 16 /*! 17 \class SOPHYA::LinFitter 18 \ingroup TArray 19 Class for linear fitting 20 \sa TMatrix TArray 21 */ 22 9 23 namespace SOPHYA { 10 24 11 12 13 25 //////////////////////////////////////////////////////////////// 26 //! Class for simple operation on TMatrix 14 27 template <class T> 15 28 class SimpleMatrixOperation { 16 29 public: 17 // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes18 // operations sur la matrice B19 30 static TMatrix<T> Inverse(TMatrix<T> const & A); 20 31 static T GausPiv(TMatrix<T>& A, TMatrix<T>& B); 21 32 }; 22 33 34 //////////////////////////////////////////////////////////////// 23 35 // Resolution du systeme A*C = B 36 //! Solve A*C = B for C in place and return determinant 37 /*! \ingroup TArray \fn LinSolveInPlace */ 38 inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b) 39 { 40 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 41 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch")); 42 return SimpleMatrixOperation<r_4>::GausPiv(a,b); 43 } 44 45 //! Solve A*X = B in place and return determinant 46 /*! \ingroup TArray \fn LinSolveInPlace */ 24 47 inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b) 25 48 { … … 29 52 } 30 53 31 // Resolution du systeme A*C = B, avec C retourne dans B 32 inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) 33 { 54 //! Solve A*X = B in place and return determinant 55 /*! \ingroup TArray \fn LinSolveInPlace */ 56 inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b) 57 { 34 58 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 35 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch")); 36 c = b; 37 TMatrix<r_8> a1(a); 38 return SimpleMatrixOperation<r_8>::GausPiv(a1,c); 59 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch")); 60 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b); 39 61 } 40 62 41 inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) 42 { 63 //! Solve A*X = B in place and return determinant 64 /*! \ingroup TArray \fn LinSolveInPlace */ 65 inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b) 66 { 43 67 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 44 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch")); 45 c = b; 46 TMatrix<r_4> a1(a); 47 return SimpleMatrixOperation<r_4>::GausPiv(a1,c); 68 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch")); 69 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b); 48 70 } 49 71 50 // Inverse d'une matrice 51 inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A) 52 { 53 return SimpleMatrixOperation<r_8>::Inverse(A); 72 //////////////////////////////////////////////////////////////// 73 // Resolution du systeme A*C = B, avec C retourne dans B 74 //! Solve A*C = B and return C and determinant 75 /*! \ingroup TArray \fn LinSolve */ 76 inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) { 77 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 78 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch")); 79 c = b; TMatrix<r_4> a1(a); 80 return SimpleMatrixOperation<r_4>::GausPiv(a1,c); 54 81 } 55 82 56 inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A) 57 { 58 return SimpleMatrixOperation<r_4>::Inverse(A); 83 //! Solve A*C = B and return C and determinant 84 /*! \ingroup TArray \fn LinSolve */ 85 inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) { 86 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 87 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch")); 88 c = b; TMatrix<r_8> a1(a); 89 return SimpleMatrixOperation<r_8>::GausPiv(a1,c); 59 90 } 60 91 92 //! Solve A*C = B and return C and determinant 93 /*! \ingroup TArray \fn LinSolve */ 94 inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) { 95 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 96 throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch")); 97 c = b; TMatrix< complex<r_4> > a1(a); 98 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c); 99 } 100 101 //! Solve A*C = B and return C and determinant 102 /*! \ingroup TArray \fn LinSolve */ 103 inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) { 104 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 105 throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch")); 106 c = b; TMatrix< complex<r_8> > a1(a); 107 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c); 108 } 109 110 //////////////////////////////////////////////////////////////// 111 // Inverse d'une matrice 112 //! To inverse a TMatrix 113 /*! \ingroup TArray \fn Inverse */ 114 inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A) 115 {return SimpleMatrixOperation<r_4>::Inverse(A);} 116 //! To inverse a TMatrix 117 /*! \ingroup TArray \fn Inverse */ 118 inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A) 119 {return SimpleMatrixOperation<r_8>::Inverse(A);} 120 //! To inverse a TMatrix 121 /*! \ingroup TArray \fn Inverse */ 122 inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A) 123 {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);} 124 //! To inverse a TMatrix 125 /*! \ingroup TArray \fn Inverse */ 126 inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A) 127 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);} 61 128 62 129 //-------------------------------------- … … 64 131 //-------------------------------------- 65 132 133 //! Class for linear fitting 66 134 class LinFitter { 67 135 public :
Note:
See TracChangeset
for help on using the changeset viewer.