// This may look like C code, but it is really -*- C++ -*- #ifndef SOpeMatrix_SEEN #define SOpeMatrix_SEEN #include "machdefs.h" #include "tmatrix.h" #include "tvector.h" //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //------------------------------------------------------------// // La classe de calcul simple sur les TMatrix // //------------------------------------------------------------// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// namespace SOPHYA { /*! \class SimpleMatrixOperation \ingroup TArray Class for simple operation on TMatrix \sa TMatrix TArray */ //! Class for simple operation on TMatrix template class SimpleMatrixOperation { public: static TMatrix Inverse(TMatrix const & A); static T GausPiv(TMatrix& A, TMatrix& B); }; } // Fin du namespace //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //------------------------------------------------------------// // Resolution de systemes lineaires // //------------------------------------------------------------// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// namespace SOPHYA { //------------------------------------------------------------ // Resolution du systeme A*C = B //------------------------------------------------------------ /*! \ingroup TArray \fn LinSolveInPlace(TMatrix&, TVector&) \brief Solve A*C = B for C in place and return determinant */ inline r_4 LinSolveInPlace(TMatrix& a, TVector& b) { if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) throw(SzMismatchError("LinSolveInPlace(TMatrix,TVector) size mismatch")); return SimpleMatrixOperation::GausPiv(a,b); } /*! \ingroup TArray \fn LinSolveInPlace (TMatrix&, TVector&) \brief Solve A*X = B in place and return determinant */ inline r_8 LinSolveInPlace(TMatrix& a, TVector& b) { if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) throw(SzMismatchError("LinSolveInPlace(TMatrix,TVector) size mismatch")); return SimpleMatrixOperation::GausPiv(a,b); } /*! \ingroup TArray \fn LinSolveInPlace(TMatrix< complex >&, TVector< complex >&) \brief Solve A*X = B in place and return determinant */ inline complex LinSolveInPlace(TMatrix< complex >& a, TVector< complex >& b) { if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) throw(SzMismatchError("LinSolveInPlace(TMatrix< complex >,TVector< complex >) size mismatch")); return SimpleMatrixOperation< complex >::GausPiv(a,b); } /*! \ingroup TArray \fn LinSolveInPlace(TMatrix< complex >&, TVector< complex >&) \brief Solve A*X = B in place and return determinant */ inline complex LinSolveInPlace(TMatrix< complex >& a, TVector< complex >& b) { if(a.NCols() != b.NRows() || a.NCols() != a.NRows()) throw(SzMismatchError("LinSolveInPlace(TMatrix< complex >,TVector< complex >) size mismatch")); return SimpleMatrixOperation< complex >::GausPiv(a,b); } //------------------------------------------------------------ // Resolution du systeme A*C = B, avec C retourne dans B //------------------------------------------------------------ /*! \ingroup TArray \fn LinSolve(const TMatrix&, const TVector&, TVector&) \brief Solve A*C = B and return C and determinant */ inline r_4 LinSolve(const TMatrix& a, const TVector& b, TVector& c) { if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) throw(SzMismatchError("LinSolve(TMatrix,TVector) size mismatch")); c = b; TMatrix a1(a); return SimpleMatrixOperation::GausPiv(a1,c); } /*! \ingroup TArray \fn LinSolve(const TMatrix&, const TVector&, TVector&) \brief Solve A*C = B and return C and determinant */ inline r_8 LinSolve(const TMatrix& a, const TVector& b, TVector& c) { if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) throw(SzMismatchError("LinSolve(TMatrix,TVector) size mismatch")); c = b; TMatrix a1(a); return SimpleMatrixOperation::GausPiv(a1,c); } /*! \ingroup TArray \fn LinSolve(const TMatrix< complex >&, const TVector< complex >&, TVector< complex >&) \brief Solve A*C = B and return C and determinant */ inline complex LinSolve(const TMatrix< complex >& a, const TVector< complex >& b, TVector< complex >& c) { if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) throw(SzMismatchError("LinSolve(TMatrix< complex >,TVector< complex >) size mismatch")); c = b; TMatrix< complex > a1(a); return SimpleMatrixOperation< complex >::GausPiv(a1,c); } /*! \ingroup TArray \fn LinSolve(const TMatrix< complex >&, const TVector< complex >&, TVector< complex >&) \brief Solve A*C = B and return C and determinant */ inline complex LinSolve(const TMatrix< complex >& a, const TVector< complex >& b, TVector< complex >& c) { if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows()) throw(SzMismatchError("LinSolve(TMatrix< complex >,TVector< complex >) size mismatch")); c = b; TMatrix< complex > a1(a); return SimpleMatrixOperation< complex >::GausPiv(a1,c); } } // Fin du namespace //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //------------------------------------------------------------// // Inverse d'une matrice // //------------------------------------------------------------// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// namespace SOPHYA { /*! \ingroup TArray \fn Inverse(TMatrix const &) \brief To inverse a TMatrix */ inline TMatrix Inverse(TMatrix const & A) {return SimpleMatrixOperation::Inverse(A);} /*! \ingroup TArray \fn Inverse(TMatrix const &) \brief To inverse a TMatrix */ inline TMatrix Inverse(TMatrix const & A) {return SimpleMatrixOperation::Inverse(A);} /*! \ingroup TArray \fn Inverse(TMatrix< complex > const &) \brief To inverse a TMatrix (complex numbers) */ inline TMatrix< complex > Inverse(TMatrix< complex > const & A) {return SimpleMatrixOperation< complex >::Inverse(A);} /*! \ingroup TArray \fn Inverse(TMatrix< complex > const &) \brief To inverse a TMatrix (complex numbers) */ inline TMatrix< complex > Inverse(TMatrix< complex > const & A) {return SimpleMatrixOperation< complex >::Inverse(A);} } // Fin du namespace //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //------------------------------------------------------------// // Linear fitting // //------------------------------------------------------------// //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// namespace SOPHYA { /*! \class LinFitter \ingroup TArray Class for linear fitting \sa TMatrix TArray */ //! Class for linear fitting template class LinFitter { public : LinFitter(); virtual ~LinFitter(); //! Linear fitting r_8 LinFit(const TVector& x, const TVector& y, uint_4 nf, T (*f)(uint_4,T), TVector& c); //! Linear fitting r_8 LinFit(const TMatrix& fx, const TVector& y, TVector& c); //! Linear fitting with errors r_8 LinFit(const TVector& x, const TVector& y, const TVector& errY2, uint_4 nf,T (*f)(uint_4,T), TVector& c, TVector& errC); //! Linear fitting with errors r_8 LinFit(const TMatrix& fx, const TVector& y, const TVector& errY2, TVector& c, TVector& errC); }; } // Fin du namespace #endif