[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
|
---|
[947] | 24 | */
|
---|
[926] | 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 |
|
---|
[947] | 50 | /*! \ingroup TArray
|
---|
| 51 | \fn LinSolveInPlace
|
---|
| 52 | \brief Solve A*C = B for C in place and return determinant
|
---|
| 53 | */
|
---|
[926] | 54 | inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
|
---|
| 55 | {
|
---|
| 56 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 57 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
|
---|
| 58 | return SimpleMatrixOperation<r_4>::GausPiv(a,b);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[947] | 61 | /*! \ingroup TArray
|
---|
| 62 | \fn LinSolveInPlace
|
---|
| 63 | \brief Solve A*X = B in place and return determinant
|
---|
| 64 | */
|
---|
[772] | 65 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
| 66 | {
|
---|
| 67 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 68 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 69 | return SimpleMatrixOperation<r_8>::GausPiv(a,b);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[947] | 72 | /*! \ingroup TArray
|
---|
| 73 | \fn LinSolveInPlace
|
---|
| 74 | \brief Solve A*X = B in place and return determinant */
|
---|
[926] | 75 | inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
|
---|
| 76 | {
|
---|
[772] | 77 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
[926] | 78 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
| 79 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
|
---|
[772] | 80 | }
|
---|
| 81 |
|
---|
[947] | 82 | /*! \ingroup TArray
|
---|
| 83 | \fn LinSolveInPlace
|
---|
| 84 | \brief Solve A*X = B in place and return determinant
|
---|
| 85 | */
|
---|
[926] | 86 | inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
|
---|
| 87 | {
|
---|
[850] | 88 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
[926] | 89 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
| 90 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
|
---|
[850] | 91 | }
|
---|
| 92 |
|
---|
[935] | 93 | //------------------------------------------------------------
|
---|
[926] | 94 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
[935] | 95 | //------------------------------------------------------------
|
---|
| 96 |
|
---|
[947] | 97 | /*! \ingroup TArray
|
---|
| 98 | \fn LinSolve
|
---|
| 99 | \brief Solve A*C = B and return C and determinant
|
---|
| 100 | */
|
---|
| 101 |
|
---|
[926] | 102 | inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {
|
---|
| 103 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 104 | throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
|
---|
| 105 | c = b; TMatrix<r_4> a1(a);
|
---|
| 106 | return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
|
---|
[850] | 107 | }
|
---|
| 108 |
|
---|
[947] | 109 | /*! \ingroup TArray
|
---|
| 110 | \fn LinSolve
|
---|
| 111 | \brief Solve A*C = B and return C and determinant
|
---|
| 112 | */
|
---|
[926] | 113 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) {
|
---|
| 114 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 115 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 116 | c = b; TMatrix<r_8> a1(a);
|
---|
| 117 | return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
|
---|
[850] | 118 | }
|
---|
| 119 |
|
---|
[947] | 120 | /*! \ingroup TArray
|
---|
| 121 | \fn LinSolve
|
---|
| 122 | \brief Solve A*C = B and return C and determinant
|
---|
| 123 | */
|
---|
[926] | 124 | inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) {
|
---|
| 125 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 126 | throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
| 127 | c = b; TMatrix< complex<r_4> > a1(a);
|
---|
| 128 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c);
|
---|
| 129 | }
|
---|
[850] | 130 |
|
---|
[947] | 131 | /*! \ingroup TArray
|
---|
| 132 | \fn LinSolve
|
---|
| 133 | \brief Solve A*C = B and return C and determinant
|
---|
| 134 | */
|
---|
[926] | 135 | inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) {
|
---|
| 136 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
| 137 | throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
| 138 | c = b; TMatrix< complex<r_8> > a1(a);
|
---|
| 139 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[935] | 142 | } // Fin du namespace
|
---|
| 143 |
|
---|
[926] | 144 | ////////////////////////////////////////////////////////////////
|
---|
[935] | 145 | ////////////////////////////////////////////////////////////////
|
---|
| 146 | //------------------------------------------------------------//
|
---|
| 147 | // Inverse d'une matrice //
|
---|
| 148 | //------------------------------------------------------------//
|
---|
| 149 | ////////////////////////////////////////////////////////////////
|
---|
| 150 | ////////////////////////////////////////////////////////////////
|
---|
| 151 |
|
---|
| 152 | namespace SOPHYA {
|
---|
| 153 |
|
---|
[947] | 154 | /*! \ingroup TArray
|
---|
| 155 | \fn Inverse
|
---|
| 156 | \brief To inverse a TMatrix
|
---|
| 157 | */
|
---|
[926] | 158 | inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
|
---|
| 159 | {return SimpleMatrixOperation<r_4>::Inverse(A);}
|
---|
[947] | 160 | /*! \ingroup TArray
|
---|
| 161 | \fn Inverse
|
---|
| 162 | \brief To inverse a TMatrix
|
---|
| 163 | */
|
---|
[926] | 164 | inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
|
---|
| 165 | {return SimpleMatrixOperation<r_8>::Inverse(A);}
|
---|
[947] | 166 | /*! \ingroup TArray
|
---|
| 167 | \fn Inverse
|
---|
| 168 | \brief To inverse a TMatrix (complex numbers)
|
---|
| 169 | */
|
---|
[926] | 170 | inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
|
---|
| 171 | {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
|
---|
[947] | 172 | /*! \ingroup TArray
|
---|
| 173 | \fn Inverse
|
---|
| 174 | \brief To inverse a TMatrix (complex numbers)
|
---|
| 175 | */
|
---|
[926] | 176 | inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
|
---|
| 177 | {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
|
---|
| 178 |
|
---|
[935] | 179 | } // Fin du namespace
|
---|
[772] | 180 |
|
---|
[935] | 181 |
|
---|
| 182 | ////////////////////////////////////////////////////////////////
|
---|
| 183 | ////////////////////////////////////////////////////////////////
|
---|
| 184 | //------------------------------------------------------------//
|
---|
| 185 | // Linear fitting //
|
---|
| 186 | //------------------------------------------------------------//
|
---|
| 187 | ////////////////////////////////////////////////////////////////
|
---|
| 188 | ////////////////////////////////////////////////////////////////
|
---|
| 189 |
|
---|
| 190 | namespace SOPHYA {
|
---|
| 191 |
|
---|
| 192 | /*!
|
---|
| 193 | \class LinFitter
|
---|
| 194 | \ingroup TArray
|
---|
| 195 | Class for linear fitting
|
---|
| 196 | \sa TMatrix TArray
|
---|
[947] | 197 | */
|
---|
[935] | 198 |
|
---|
[926] | 199 | //! Class for linear fitting
|
---|
[939] | 200 | template <class T>
|
---|
[804] | 201 | class LinFitter {
|
---|
[939] | 202 |
|
---|
[804] | 203 | public :
|
---|
| 204 |
|
---|
[939] | 205 | LinFitter();
|
---|
| 206 | virtual ~LinFitter();
|
---|
[804] | 207 |
|
---|
[939] | 208 | //! Linear fitting
|
---|
| 209 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
|
---|
| 210 | uint_4 nf, T (*f)(uint_4,T), TVector<T>& c);
|
---|
| 211 |
|
---|
| 212 | //! Linear fitting
|
---|
| 213 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
|
---|
[804] | 214 |
|
---|
[939] | 215 | //! Linear fitting with errors
|
---|
| 216 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
|
---|
| 217 | uint_4 nf,T (*f)(uint_4,T), TVector<T>& c, TVector<T>& errC);
|
---|
[804] | 218 |
|
---|
[939] | 219 | //! Linear fitting with errors
|
---|
| 220 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
|
---|
| 221 | const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
|
---|
[804] | 222 | };
|
---|
| 223 |
|
---|
[772] | 224 | } // Fin du namespace
|
---|
| 225 |
|
---|
| 226 | #endif
|
---|