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