[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 |
|
---|
| 9 | namespace SOPHYA {
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | ////////////////////////////////////////////////////////////////
|
---|
| 14 | template <class T>
|
---|
| 15 | class SimpleMatrixOperation {
|
---|
| 16 | public:
|
---|
| 17 | // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes
|
---|
| 18 | // operations sur la matrice B
|
---|
| 19 | static TMatrix<T> Inverse(TMatrix<T> const & A);
|
---|
| 20 | static T GausPiv(TMatrix<T>& A, TMatrix<T>& B);
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | // Resolution du systeme A*C = B
|
---|
| 24 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
| 25 | {
|
---|
| 26 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 27 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 28 | return SimpleMatrixOperation<r_8>::GausPiv(a,b);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
| 32 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
|
---|
| 33 | {
|
---|
| 34 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 35 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 36 | c = b;
|
---|
| 37 | TMatrix<r_8> a1(a);
|
---|
| 38 | return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[850] | 41 | inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c)
|
---|
| 42 | {
|
---|
| 43 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 44 | throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
|
---|
| 45 | c = b;
|
---|
| 46 | TMatrix<r_4> a1(a);
|
---|
| 47 | return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | // Inverse d'une matrice
|
---|
| 51 | inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
|
---|
| 52 | {
|
---|
| 53 | return SimpleMatrixOperation<r_8>::Inverse(A);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
|
---|
| 57 | {
|
---|
| 58 | return SimpleMatrixOperation<r_4>::Inverse(A);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
[804] | 62 | //--------------------------------------
|
---|
| 63 | // Linear fitting
|
---|
| 64 | //--------------------------------------
|
---|
[772] | 65 |
|
---|
[804] | 66 | class LinFitter {
|
---|
| 67 | public :
|
---|
| 68 | LinFitter();
|
---|
| 69 | virtual ~LinFitter();
|
---|
| 70 |
|
---|
| 71 | double LinFit(const Vector& x, const Vector& y, int nf,
|
---|
| 72 | double (*f)(int, double), Vector& c);
|
---|
| 73 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1;
|
---|
| 74 |
|
---|
| 75 | double LinFit(const Matrix& fx, const Vector& y, Vector& c);
|
---|
| 76 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 77 | // la matrice fx contient les valeurs des f:
|
---|
| 78 | // fx(i,j) = f(i, x(j)).
|
---|
| 79 |
|
---|
| 80 | double LinFit(const Vector& x, const Vector& y, const Vector& errY2, int nf,
|
---|
| 81 | double (*f)(int, double), Vector& c, Vector& errC);
|
---|
| 82 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 83 | // errY2 contient les carres des erreurs sur les Y.
|
---|
| 84 | // au retour, errC contient les erreurs sur les coefs.
|
---|
| 85 |
|
---|
| 86 | double LinFit(const Matrix& fx, const Vector& y, const Vector& errY2,
|
---|
| 87 | Vector& c, Vector& errC);
|
---|
| 88 | // fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
|
---|
| 89 | // la matrice fx contient les valeurs des f:
|
---|
| 90 | // fx(i,j) = f(i, x(j)).
|
---|
| 91 | // errY2 contient les carres des erreurs sur les Y.
|
---|
| 92 | // au retour, errC contient les erreurs sur les coefs.
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 |
|
---|
[772] | 96 | } // Fin du namespace
|
---|
| 97 |
|
---|
| 98 | #endif
|
---|