[772] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | #ifndef SOpeMatrix_SEEN
|
---|
| 3 | #define SOpeMatrix_SEEN
|
---|
| 4 |
|
---|
| 5 | #include "machdefs.h"
|
---|
| 6 | #include "tmatrix.h"
|
---|
| 7 | #include "tvector.h"
|
---|
| 8 |
|
---|
[935] | 9 | ////////////////////////////////////////////////////////////////
|
---|
| 10 | ////////////////////////////////////////////////////////////////
|
---|
| 11 | //------------------------------------------------------------//
|
---|
[939] | 12 | // La classe de calcul simple sur les TMatrix //
|
---|
[935] | 13 | //------------------------------------------------------------//
|
---|
| 14 | ////////////////////////////////////////////////////////////////
|
---|
| 15 | ////////////////////////////////////////////////////////////////
|
---|
| 16 |
|
---|
| 17 | namespace SOPHYA {
|
---|
| 18 |
|
---|
[926] | 19 | /*!
|
---|
[935] | 20 | \class SimpleMatrixOperation
|
---|
[926] | 21 | \ingroup TArray
|
---|
| 22 | Class for simple operation on TMatrix
|
---|
| 23 | \sa TMatrix TArray
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | //! Class for simple operation on TMatrix
|
---|
[772] | 27 | template <class T>
|
---|
| 28 | class SimpleMatrixOperation {
|
---|
| 29 | public:
|
---|
| 30 | static TMatrix<T> Inverse(TMatrix<T> const & A);
|
---|
| 31 | static T GausPiv(TMatrix<T>& A, TMatrix<T>& B);
|
---|
| 32 | };
|
---|
| 33 |
|
---|
[935] | 34 | } // Fin du namespace
|
---|
| 35 |
|
---|
[926] | 36 | ////////////////////////////////////////////////////////////////
|
---|
[935] | 37 | ////////////////////////////////////////////////////////////////
|
---|
| 38 | //------------------------------------------------------------//
|
---|
| 39 | // Resolution de systemes lineaires //
|
---|
| 40 | //------------------------------------------------------------//
|
---|
| 41 | ////////////////////////////////////////////////////////////////
|
---|
| 42 | ////////////////////////////////////////////////////////////////
|
---|
| 43 |
|
---|
| 44 | namespace SOPHYA {
|
---|
| 45 |
|
---|
| 46 | //------------------------------------------------------------
|
---|
[772] | 47 | // Resolution du systeme A*C = B
|
---|
[935] | 48 | //------------------------------------------------------------
|
---|
| 49 |
|
---|
[926] | 50 | //! Solve A*C = B for C in place and return determinant
|
---|
| 51 | /*! \ingroup TArray \fn LinSolveInPlace */
|
---|
| 52 | inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
|
---|
| 53 | {
|
---|
| 54 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 55 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
|
---|
| 56 | return SimpleMatrixOperation<r_4>::GausPiv(a,b);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //! Solve A*X = B in place and return determinant
|
---|
| 60 | /*! \ingroup TArray \fn LinSolveInPlace */
|
---|
[772] | 61 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
| 62 | {
|
---|
| 63 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 64 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 65 | return SimpleMatrixOperation<r_8>::GausPiv(a,b);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[926] | 68 | //! Solve A*X = B in place and return determinant
|
---|
| 69 | /*! \ingroup TArray \fn LinSolveInPlace */
|
---|
| 70 | inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
|
---|
| 71 | {
|
---|
[772] | 72 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
[926] | 73 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
| 74 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
|
---|
[772] | 75 | }
|
---|
| 76 |
|
---|
[926] | 77 | //! Solve A*X = B in place and return determinant
|
---|
| 78 | /*! \ingroup TArray \fn LinSolveInPlace */
|
---|
| 79 | inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
|
---|
| 80 | {
|
---|
[850] | 81 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
[926] | 82 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
| 83 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
|
---|
[850] | 84 | }
|
---|
| 85 |
|
---|
[935] | 86 | //------------------------------------------------------------
|
---|
[926] | 87 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
[935] | 88 | //------------------------------------------------------------
|
---|
| 89 |
|
---|
[926] | 90 | //! Solve A*C = B and return C and determinant
|
---|
| 91 | /*! \ingroup TArray \fn LinSolve */
|
---|
| 92 | inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {
|
---|
| 93 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 94 | throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
|
---|
| 95 | c = b; TMatrix<r_4> a1(a);
|
---|
| 96 | return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
|
---|
[850] | 97 | }
|
---|
| 98 |
|
---|
[926] | 99 | //! Solve A*C = B and return C and determinant
|
---|
| 100 | /*! \ingroup TArray \fn LinSolve */
|
---|
| 101 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) {
|
---|
| 102 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 103 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 104 | c = b; TMatrix<r_8> a1(a);
|
---|
| 105 | return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
|
---|
[850] | 106 | }
|
---|
| 107 |
|
---|
[926] | 108 | //! Solve A*C = B and return C and determinant
|
---|
| 109 | /*! \ingroup TArray \fn LinSolve */
|
---|
| 110 | inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) {
|
---|
| 111 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 112 | throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
| 113 | c = b; TMatrix< complex<r_4> > a1(a);
|
---|
| 114 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c);
|
---|
| 115 | }
|
---|
[850] | 116 |
|
---|
[926] | 117 | //! Solve A*C = B and return C and determinant
|
---|
| 118 | /*! \ingroup TArray \fn LinSolve */
|
---|
| 119 | inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) {
|
---|
| 120 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 121 | throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
| 122 | c = b; TMatrix< complex<r_8> > a1(a);
|
---|
| 123 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[935] | 126 | } // Fin du namespace
|
---|
| 127 |
|
---|
[926] | 128 | ////////////////////////////////////////////////////////////////
|
---|
[935] | 129 | ////////////////////////////////////////////////////////////////
|
---|
| 130 | //------------------------------------------------------------//
|
---|
| 131 | // Inverse d'une matrice //
|
---|
| 132 | //------------------------------------------------------------//
|
---|
| 133 | ////////////////////////////////////////////////////////////////
|
---|
| 134 | ////////////////////////////////////////////////////////////////
|
---|
| 135 |
|
---|
| 136 | namespace SOPHYA {
|
---|
| 137 |
|
---|
[926] | 138 | //! To inverse a TMatrix
|
---|
| 139 | /*! \ingroup TArray \fn Inverse */
|
---|
| 140 | inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
|
---|
| 141 | {return SimpleMatrixOperation<r_4>::Inverse(A);}
|
---|
| 142 | //! To inverse a TMatrix
|
---|
| 143 | /*! \ingroup TArray \fn Inverse */
|
---|
| 144 | inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
|
---|
| 145 | {return SimpleMatrixOperation<r_8>::Inverse(A);}
|
---|
| 146 | //! To inverse a TMatrix
|
---|
| 147 | /*! \ingroup TArray \fn Inverse */
|
---|
| 148 | inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
|
---|
| 149 | {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
|
---|
| 150 | //! To inverse a TMatrix
|
---|
| 151 | /*! \ingroup TArray \fn Inverse */
|
---|
| 152 | inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
|
---|
| 153 | {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
|
---|
| 154 |
|
---|
[935] | 155 | } // Fin du namespace
|
---|
[772] | 156 |
|
---|
[935] | 157 |
|
---|
| 158 | ////////////////////////////////////////////////////////////////
|
---|
| 159 | ////////////////////////////////////////////////////////////////
|
---|
| 160 | //------------------------------------------------------------//
|
---|
| 161 | // Linear fitting //
|
---|
| 162 | //------------------------------------------------------------//
|
---|
| 163 | ////////////////////////////////////////////////////////////////
|
---|
| 164 | ////////////////////////////////////////////////////////////////
|
---|
| 165 |
|
---|
| 166 | namespace SOPHYA {
|
---|
| 167 |
|
---|
| 168 | /*!
|
---|
| 169 | \class LinFitter
|
---|
| 170 | \ingroup TArray
|
---|
| 171 | Class for linear fitting
|
---|
| 172 | \sa TMatrix TArray
|
---|
| 173 | */
|
---|
| 174 |
|
---|
[926] | 175 | //! Class for linear fitting
|
---|
[939] | 176 | template <class T>
|
---|
[804] | 177 | class LinFitter {
|
---|
[939] | 178 |
|
---|
[804] | 179 | public :
|
---|
| 180 |
|
---|
[939] | 181 | LinFitter();
|
---|
| 182 | virtual ~LinFitter();
|
---|
[804] | 183 |
|
---|
[939] | 184 | //! Linear fitting
|
---|
| 185 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
|
---|
| 186 | uint_4 nf, T (*f)(uint_4,T), TVector<T>& c);
|
---|
| 187 |
|
---|
| 188 | //! Linear fitting
|
---|
| 189 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
|
---|
[804] | 190 |
|
---|
[939] | 191 | //! Linear fitting with errors
|
---|
| 192 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
|
---|
| 193 | uint_4 nf,T (*f)(uint_4,T), TVector<T>& c, TVector<T>& errC);
|
---|
[804] | 194 |
|
---|
[939] | 195 | //! Linear fitting with errors
|
---|
| 196 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
|
---|
| 197 | const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
|
---|
[804] | 198 | };
|
---|
| 199 |
|
---|
[772] | 200 | } // Fin du namespace
|
---|
| 201 |
|
---|
| 202 | #endif
|
---|