Changeset 999 in Sophya for trunk/SophyaLib/TArray/sopemtx.h
- Timestamp:
- May 3, 2000, 6:39:26 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/sopemtx.h
r958 r999 23 23 \sa TMatrix TArray 24 24 */ 25 26 25 //! Class for simple operation on TMatrix 27 26 template <class T> … … 47 46 // Resolution du systeme A*C = B 48 47 //------------------------------------------------------------ 49 50 /*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_4>&,TVector<r_4>&) 48 /*! \ingroup TArray \fn LinSolveInPlace(TMatrix<T>&,TVector<T>&) 51 49 \brief Solve A*C = B for C in place and return determinant 52 50 */ 53 inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b) 51 template <class T> 52 inline T LinSolveInPlace(TMatrix<T>& a, TVector<T>& b) 54 53 { 55 54 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 56 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch")); 57 return SimpleMatrixOperation<r_4>::GausPiv(a,b); 58 } 59 60 /*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_8>&,TVector<r_8>&) 61 \brief Solve A*X = B in place and return determinant 62 */ 63 inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b) 64 { 65 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 66 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch")); 67 return SimpleMatrixOperation<r_8>::GausPiv(a,b); 68 } 69 70 /*! \ingroup TArray 71 \fn LinSolveInPlace(TMatrix< complex<r_4> >&, TVector< complex<r_4> >&) 72 \brief Solve A*X = B in place and return determinant */ 73 inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b) 74 { 75 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 76 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch")); 77 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b); 78 } 79 80 /*! \ingroup TArray 81 \fn LinSolveInPlace(TMatrix< complex<r_8> >&, TVector< complex<r_8> >&) 82 \brief Solve A*X = B in place and return determinant 83 */ 84 inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b) 85 { 86 if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) 87 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch")); 88 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b); 55 throw(SzMismatchError("LinSolveInPlace(TMatrix<T>,TVector<T>) size mismatch")); 56 return SimpleMatrixOperation<T>::GausPiv(a,b); 89 57 } 90 58 … … 92 60 // Resolution du systeme A*C = B, avec C retourne dans B 93 61 //------------------------------------------------------------ 94 95 62 /*! \ingroup TArray 96 \fn LinSolve(const TMatrix< r_4>&, const TVector<r_4>&, TVector<r_4>&)63 \fn LinSolve(const TMatrix<T>&, const TVector<T>&, TVector<T>&) 97 64 \brief Solve A*C = B and return C and determinant 98 65 */ 99 100 inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {66 template <class T> 67 inline T LinSolve(const TMatrix<T>& a, const TVector<T>& b, TVector<T>& c) { 101 68 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 102 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch")); 103 c = b; TMatrix<r_4> a1(a); 104 return SimpleMatrixOperation<r_4>::GausPiv(a1,c); 105 } 106 107 /*! \ingroup TArray 108 \fn LinSolve(const TMatrix<r_8>&, const TVector<r_8>&, TVector<r_8>&) 109 \brief Solve A*C = B and return C and determinant 110 */ 111 inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) { 112 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 113 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch")); 114 c = b; TMatrix<r_8> a1(a); 115 return SimpleMatrixOperation<r_8>::GausPiv(a1,c); 116 } 117 118 /*! \ingroup TArray 119 \fn LinSolve(const TMatrix< complex<r_4> >&, const TVector< complex<r_4> >&, TVector< complex<r_4> >&) 120 \brief Solve A*C = B and return C and determinant 121 */ 122 inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) { 123 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 124 throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch")); 125 c = b; TMatrix< complex<r_4> > a1(a); 126 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c); 127 } 128 129 /*! \ingroup TArray 130 \fn LinSolve(const TMatrix< complex<r_8> >&, const TVector< complex<r_8> >&, TVector< complex<r_8> >&) 131 \brief Solve A*C = B and return C and determinant 132 */ 133 inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) { 134 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) 135 throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch")); 136 c = b; TMatrix< complex<r_8> > a1(a); 137 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c); 69 throw(SzMismatchError("LinSolve(TMatrix<T>,TVector<T>) size mismatch")); 70 c = b; TMatrix<T> a1(a); 71 return SimpleMatrixOperation<T>::GausPiv(a1,c); 138 72 } 139 73 … … 151 85 152 86 /*! \ingroup TArray 153 \fn Inverse(TMatrix< r_4> const &)87 \fn Inverse(TMatrix<T> const &) 154 88 \brief To inverse a TMatrix 155 89 */ 156 inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A) 157 {return SimpleMatrixOperation<r_4>::Inverse(A);} 90 template <class T> 91 inline TMatrix<T> Inverse(TMatrix<T> const & A) 92 {return SimpleMatrixOperation<T>::Inverse(A);} 93 158 94 /*! \ingroup TArray 159 \fn Inverse(TMatrix<r_8> const &)160 \brief To inverse a TMatrix95 \fn Determinant(TMatrix<T> const &) 96 \brief Give the TMatrix determinant 161 97 */ 162 inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A) 163 {return SimpleMatrixOperation<r_8>::Inverse(A);} 98 template <class T> 99 inline T Determinant(TMatrix<T> const & A) { 100 TMatrix<T> a(A,false); 101 TMatrix<T> b(a.NCols(),a.NRows()); b = IdentityMatrix(1.); 102 return SimpleMatrixOperation<T>::GausPiv(a,b); 103 } 104 164 105 /*! \ingroup TArray 165 \fn Inverse(TMatrix< complex<r_4> > const &) 166 \brief To inverse a TMatrix (complex numbers) 106 \fn GausPiv(TMatrix<T> const &,TMatrix<T> &) 107 \brief Gauss pivoting on matrix \b A, doing the same operations 108 on matrix \b B and return determinant of \b A. 109 \sa SOPHYA::SimpleMatrixOperation::GausPiv(TMatrix<T>&,TMatrix<T>&) 167 110 */ 168 inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A) 169 {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);} 170 /*! \ingroup TArray 171 \fn Inverse(TMatrix< complex<r_8> > const &) 172 \brief To inverse a TMatrix (complex numbers) 173 */ 174 inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A) 175 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);} 111 template <class T> 112 inline T GausPiv(TMatrix<T> const & A,TMatrix<T> & B) { 113 TMatrix<T> a(A,false); 114 return SimpleMatrixOperation<T>::GausPiv(a,B); 115 } 116 176 117 177 118 } // Fin du namespace
Note:
See TracChangeset
for help on using the changeset viewer.