[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 | //------------------------------------------------------------//
|
---|
| 12 | // Classe TMatrixRC //
|
---|
| 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
|
---|
[804] | 176 | class LinFitter {
|
---|
| 177 | public :
|
---|
| 178 | LinFitter();
|
---|
| 179 | virtual ~LinFitter();
|
---|
| 180 |
|
---|
| 181 | double LinFit(const Vector& x, const Vector& y, int nf,
|
---|
| 182 | double (*f)(int, double), Vector& c);
|
---|
| 183 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1;
|
---|
| 184 |
|
---|
| 185 | double LinFit(const Matrix& fx, const Vector& y, Vector& c);
|
---|
| 186 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 187 | // la matrice fx contient les valeurs des f:
|
---|
| 188 | // fx(i,j) = f(i, x(j)).
|
---|
| 189 |
|
---|
| 190 | double LinFit(const Vector& x, const Vector& y, const Vector& errY2, int nf,
|
---|
| 191 | double (*f)(int, double), Vector& c, Vector& errC);
|
---|
| 192 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 193 | // errY2 contient les carres des erreurs sur les Y.
|
---|
| 194 | // au retour, errC contient les erreurs sur les coefs.
|
---|
| 195 |
|
---|
| 196 | double LinFit(const Matrix& fx, const Vector& y, const Vector& errY2,
|
---|
| 197 | Vector& c, Vector& errC);
|
---|
| 198 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 199 | // la matrice fx contient les valeurs des f:
|
---|
| 200 | // fx(i,j) = f(i, x(j)).
|
---|
| 201 | // errY2 contient les carres des erreurs sur les Y.
|
---|
| 202 | // au retour, errC contient les erreurs sur les coefs.
|
---|
| 203 | };
|
---|
| 204 |
|
---|
| 205 |
|
---|
[772] | 206 | } // Fin du namespace
|
---|
| 207 |
|
---|
| 208 | #endif
|
---|