Changeset 999 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
May 3, 2000, 6:39:26 PM (25 years ago)
Author:
ansari
Message:

mise en template des inline + new GausPiv+Determinant cmv 3/5/00

Location:
trunk/SophyaLib/TArray
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/sopemtx.cc

    r976 r999  
    447447//! Gaussian pivoting
    448448/*!
    449   Diagonalize matrix \b a, doing the same operations on matrix \b b
    450   \return determinat of \b a.
    451 
    452   If \b b is identity matrix, return inverse of \b a
     449  Do Gauss pivoting of \b a, doing the same operations on matrix \b b
     450  \return determinant of \b a.
     451  \verbatim
     452  Solve linear system A(n,n) * X(n,m) = B(n,m)
     453  and put solution X in B for return.
     454  \endverbatim
     455  \warning If \b b is identity matrix, return inverse of \b a
     456  \warning matrix \b a and \b b are modified.
    453457 */ 
    454458template <class T>
  • trunk/SophyaLib/TArray/sopemtx.h

    r958 r999  
    2323  \sa TMatrix TArray
    2424*/
    25 
    2625//! Class for simple operation on TMatrix
    2726template <class T>
     
    4746// Resolution du systeme A*C = B
    4847//------------------------------------------------------------
    49 
    50 /*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_4>&,TVector<r_4>&)
     48/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<T>&,TVector<T>&)
    5149    \brief  Solve A*C = B for C in place and return determinant
    5250*/
    53 inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
     51template <class T>
     52inline T LinSolveInPlace(TMatrix<T>& a, TVector<T>& b)
    5453{
    5554if(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"));
     56return SimpleMatrixOperation<T>::GausPiv(a,b);
    8957}
    9058
     
    9260// Resolution du systeme A*C = B, avec C retourne dans B
    9361//------------------------------------------------------------
    94 
    9562/*! \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>&)
    9764    \brief Solve A*C = B and return C and determinant
    9865*/
    99 
    100 inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {
     66template <class T>
     67inline T LinSolve(const TMatrix<T>& a, const TVector<T>& b, TVector<T>& c) {
    10168  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);
    13872}
    13973
     
    15185
    15286/*! \ingroup TArray
    153     \fn Inverse(TMatrix<r_4> const &)
     87    \fn Inverse(TMatrix<T> const &)
    15488    \brief To inverse a TMatrix
    15589*/
    156 inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
    157   {return SimpleMatrixOperation<r_4>::Inverse(A);}
     90template <class T>
     91inline TMatrix<T> Inverse(TMatrix<T> const & A)
     92  {return SimpleMatrixOperation<T>::Inverse(A);}
     93
    15894/*! \ingroup TArray
    159     \fn Inverse(TMatrix<r_8> const &)
    160     \brief To inverse a TMatrix
     95    \fn Determinant(TMatrix<T> const &)
     96    \brief Give the TMatrix determinant
    16197*/
    162 inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
    163   {return SimpleMatrixOperation<r_8>::Inverse(A);}
     98template <class T>
     99inline 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
    164105/*! \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>&)
    167110*/
    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);}
     111template <class T>
     112inline T GausPiv(TMatrix<T> const & A,TMatrix<T> & B) {
     113  TMatrix<T> a(A,false);
     114  return SimpleMatrixOperation<T>::GausPiv(a,B);
     115}
     116
    176117
    177118} // Fin du namespace
Note: See TracChangeset for help on using the changeset viewer.