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 | ////////////////////////////////////////////////////////////////
|
---|
10 | ////////////////////////////////////////////////////////////////
|
---|
11 | //------------------------------------------------------------//
|
---|
12 | // La classe de calcul simple sur les TMatrix //
|
---|
13 | //------------------------------------------------------------//
|
---|
14 | ////////////////////////////////////////////////////////////////
|
---|
15 | ////////////////////////////////////////////////////////////////
|
---|
16 |
|
---|
17 | namespace SOPHYA {
|
---|
18 |
|
---|
19 | /*!
|
---|
20 | \class SimpleMatrixOperation
|
---|
21 | \ingroup TArray
|
---|
22 | Class for simple operation on TMatrix
|
---|
23 | \sa TMatrix TArray
|
---|
24 | */
|
---|
25 | //! Class for simple operation on TMatrix
|
---|
26 | template <class T>
|
---|
27 | class SimpleMatrixOperation {
|
---|
28 | public:
|
---|
29 | static TMatrix<T> Inverse(TMatrix<T> const & A);
|
---|
30 | static T GausPiv(TMatrix<T>& A, TMatrix<T>& B);
|
---|
31 | };
|
---|
32 |
|
---|
33 | } // Fin du namespace
|
---|
34 |
|
---|
35 | ////////////////////////////////////////////////////////////////
|
---|
36 | ////////////////////////////////////////////////////////////////
|
---|
37 | //------------------------------------------------------------//
|
---|
38 | // Resolution de systemes lineaires //
|
---|
39 | //------------------------------------------------------------//
|
---|
40 | ////////////////////////////////////////////////////////////////
|
---|
41 | ////////////////////////////////////////////////////////////////
|
---|
42 |
|
---|
43 | namespace SOPHYA {
|
---|
44 |
|
---|
45 | //------------------------------------------------------------
|
---|
46 | // Resolution du systeme A*C = B
|
---|
47 | //------------------------------------------------------------
|
---|
48 | /*! \ingroup TArray \fn LinSolveInPlace(TMatrix<T>&,TVector<T>&)
|
---|
49 | \brief Solve A*C = B for C in place and return determinant
|
---|
50 | */
|
---|
51 | template <class T>
|
---|
52 | inline T LinSolveInPlace(TMatrix<T>& a, TVector<T>& b)
|
---|
53 | {
|
---|
54 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
55 | throw(SzMismatchError("LinSolveInPlace(TMatrix<T>,TVector<T>) size mismatch"));
|
---|
56 | return SimpleMatrixOperation<T>::GausPiv(a,b);
|
---|
57 | }
|
---|
58 |
|
---|
59 | //------------------------------------------------------------
|
---|
60 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
61 | //------------------------------------------------------------
|
---|
62 | /*! \ingroup TArray
|
---|
63 | \fn LinSolve(const TMatrix<T>&, const TVector<T>&, TVector<T>&)
|
---|
64 | \brief Solve A*C = B and return C and determinant
|
---|
65 | */
|
---|
66 | template <class T>
|
---|
67 | inline T LinSolve(const TMatrix<T>& a, const TVector<T>& b, TVector<T>& c) {
|
---|
68 | if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
|
---|
69 | throw(SzMismatchError("LinSolve(TMatrix<T>,TVector<T>) size mismatch"));
|
---|
70 | c = b; TMatrix<T> a1(a);
|
---|
71 | return SimpleMatrixOperation<T>::GausPiv(a1,c);
|
---|
72 | }
|
---|
73 |
|
---|
74 | } // Fin du namespace
|
---|
75 |
|
---|
76 | ////////////////////////////////////////////////////////////////
|
---|
77 | ////////////////////////////////////////////////////////////////
|
---|
78 | //------------------------------------------------------------//
|
---|
79 | // Inverse d'une matrice //
|
---|
80 | //------------------------------------------------------------//
|
---|
81 | ////////////////////////////////////////////////////////////////
|
---|
82 | ////////////////////////////////////////////////////////////////
|
---|
83 |
|
---|
84 | namespace SOPHYA {
|
---|
85 |
|
---|
86 | /*! \ingroup TArray
|
---|
87 | \fn Inverse(TMatrix<T> const &)
|
---|
88 | \brief To inverse a TMatrix
|
---|
89 | */
|
---|
90 | template <class T>
|
---|
91 | inline TMatrix<T> Inverse(TMatrix<T> const & A)
|
---|
92 | {return SimpleMatrixOperation<T>::Inverse(A);}
|
---|
93 |
|
---|
94 | /*! \ingroup TArray
|
---|
95 | \fn Determinant(TMatrix<T> const &)
|
---|
96 | \brief Give the TMatrix determinant
|
---|
97 | */
|
---|
98 | template <class T>
|
---|
99 | inline T Determinant(TMatrix<T> const & A) {
|
---|
100 | TMatrix<T> a(A,false);
|
---|
101 | TMatrix<T> b(a.NCols(),a.NRows()); b = IdentityMatrix(1.);
|
---|
102 | return SimpleMatrixOperation<T>::GausPiv(a,b);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /*! \ingroup TArray
|
---|
106 | \fn GausPiv(TMatrix<T> const &,TMatrix<T> &)
|
---|
107 | \brief Gauss pivoting on matrix \b A, doing the same operations
|
---|
108 | on matrix \b B and return determinant of \b A.
|
---|
109 | \sa SOPHYA::SimpleMatrixOperation::GausPiv(TMatrix<T>&,TMatrix<T>&)
|
---|
110 | */
|
---|
111 | template <class T>
|
---|
112 | inline T GausPiv(TMatrix<T> const & A,TMatrix<T> & B) {
|
---|
113 | TMatrix<T> a(A,false);
|
---|
114 | return SimpleMatrixOperation<T>::GausPiv(a,B);
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | } // Fin du namespace
|
---|
119 |
|
---|
120 |
|
---|
121 | ////////////////////////////////////////////////////////////////
|
---|
122 | ////////////////////////////////////////////////////////////////
|
---|
123 | //------------------------------------------------------------//
|
---|
124 | // Linear fitting //
|
---|
125 | //------------------------------------------------------------//
|
---|
126 | ////////////////////////////////////////////////////////////////
|
---|
127 | ////////////////////////////////////////////////////////////////
|
---|
128 |
|
---|
129 | namespace SOPHYA {
|
---|
130 |
|
---|
131 | /*!
|
---|
132 | \class LinFitter
|
---|
133 | \ingroup TArray
|
---|
134 | Class for linear fitting
|
---|
135 | \sa TMatrix TArray
|
---|
136 | */
|
---|
137 |
|
---|
138 | //! Class for linear fitting
|
---|
139 | template <class T>
|
---|
140 | class LinFitter {
|
---|
141 |
|
---|
142 | public :
|
---|
143 |
|
---|
144 | LinFitter();
|
---|
145 | virtual ~LinFitter();
|
---|
146 |
|
---|
147 | //! Linear fitting
|
---|
148 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
|
---|
149 | uint_4 nf, T (*f)(uint_4,T), TVector<T>& c);
|
---|
150 |
|
---|
151 | //! Linear fitting
|
---|
152 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
|
---|
153 |
|
---|
154 | //! Linear fitting with errors
|
---|
155 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
|
---|
156 | uint_4 nf,T (*f)(uint_4,T), TVector<T>& c, TVector<T>& errC);
|
---|
157 |
|
---|
158 | //! Linear fitting with errors
|
---|
159 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
|
---|
160 | const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
|
---|
161 | };
|
---|
162 |
|
---|
163 | } // Fin du namespace
|
---|
164 |
|
---|
165 | #endif
|
---|