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 |
|
---|
26 | //! Class for simple operation on TMatrix
|
---|
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 |
|
---|
34 | } // Fin du namespace
|
---|
35 |
|
---|
36 | ////////////////////////////////////////////////////////////////
|
---|
37 | ////////////////////////////////////////////////////////////////
|
---|
38 | //------------------------------------------------------------//
|
---|
39 | // Resolution de systemes lineaires //
|
---|
40 | //------------------------------------------------------------//
|
---|
41 | ////////////////////////////////////////////////////////////////
|
---|
42 | ////////////////////////////////////////////////////////////////
|
---|
43 |
|
---|
44 | namespace SOPHYA {
|
---|
45 |
|
---|
46 | //------------------------------------------------------------
|
---|
47 | // Resolution du systeme A*C = B
|
---|
48 | //------------------------------------------------------------
|
---|
49 |
|
---|
50 | /*! \ingroup TArray
|
---|
51 | \fn LinSolveInPlace
|
---|
52 | \brief Solve A*C = B for C in place and return determinant
|
---|
53 | */
|
---|
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 |
|
---|
61 | /*! \ingroup TArray
|
---|
62 | \fn LinSolveInPlace
|
---|
63 | \brief Solve A*X = B in place and return determinant
|
---|
64 | */
|
---|
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 |
|
---|
72 | /*! \ingroup TArray
|
---|
73 | \fn LinSolveInPlace
|
---|
74 | \brief Solve A*X = B in place and return determinant */
|
---|
75 | inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
|
---|
76 | {
|
---|
77 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
78 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
79 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*! \ingroup TArray
|
---|
83 | \fn LinSolveInPlace
|
---|
84 | \brief Solve A*X = B in place and return determinant
|
---|
85 | */
|
---|
86 | inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
|
---|
87 | {
|
---|
88 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
89 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
90 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
|
---|
91 | }
|
---|
92 |
|
---|
93 | //------------------------------------------------------------
|
---|
94 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
95 | //------------------------------------------------------------
|
---|
96 |
|
---|
97 | /*! \ingroup TArray
|
---|
98 | \fn LinSolve
|
---|
99 | \brief Solve A*C = B and return C and determinant
|
---|
100 | */
|
---|
101 |
|
---|
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);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*! \ingroup TArray
|
---|
110 | \fn LinSolve
|
---|
111 | \brief Solve A*C = B and return C and determinant
|
---|
112 | */
|
---|
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);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /*! \ingroup TArray
|
---|
121 | \fn LinSolve
|
---|
122 | \brief Solve A*C = B and return C and determinant
|
---|
123 | */
|
---|
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 | }
|
---|
130 |
|
---|
131 | /*! \ingroup TArray
|
---|
132 | \fn LinSolve
|
---|
133 | \brief Solve A*C = B and return C and determinant
|
---|
134 | */
|
---|
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 |
|
---|
142 | } // Fin du namespace
|
---|
143 |
|
---|
144 | ////////////////////////////////////////////////////////////////
|
---|
145 | ////////////////////////////////////////////////////////////////
|
---|
146 | //------------------------------------------------------------//
|
---|
147 | // Inverse d'une matrice //
|
---|
148 | //------------------------------------------------------------//
|
---|
149 | ////////////////////////////////////////////////////////////////
|
---|
150 | ////////////////////////////////////////////////////////////////
|
---|
151 |
|
---|
152 | namespace SOPHYA {
|
---|
153 |
|
---|
154 | /*! \ingroup TArray
|
---|
155 | \fn Inverse
|
---|
156 | \brief To inverse a TMatrix
|
---|
157 | */
|
---|
158 | inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
|
---|
159 | {return SimpleMatrixOperation<r_4>::Inverse(A);}
|
---|
160 | /*! \ingroup TArray
|
---|
161 | \fn Inverse
|
---|
162 | \brief To inverse a TMatrix
|
---|
163 | */
|
---|
164 | inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
|
---|
165 | {return SimpleMatrixOperation<r_8>::Inverse(A);}
|
---|
166 | /*! \ingroup TArray
|
---|
167 | \fn Inverse
|
---|
168 | \brief To inverse a TMatrix (complex numbers)
|
---|
169 | */
|
---|
170 | inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
|
---|
171 | {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
|
---|
172 | /*! \ingroup TArray
|
---|
173 | \fn Inverse
|
---|
174 | \brief To inverse a TMatrix (complex numbers)
|
---|
175 | */
|
---|
176 | inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
|
---|
177 | {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
|
---|
178 |
|
---|
179 | } // Fin du namespace
|
---|
180 |
|
---|
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
|
---|
197 | */
|
---|
198 |
|
---|
199 | //! Class for linear fitting
|
---|
200 | template <class T>
|
---|
201 | class LinFitter {
|
---|
202 |
|
---|
203 | public :
|
---|
204 |
|
---|
205 | LinFitter();
|
---|
206 | virtual ~LinFitter();
|
---|
207 |
|
---|
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);
|
---|
214 |
|
---|
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);
|
---|
218 |
|
---|
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);
|
---|
222 | };
|
---|
223 |
|
---|
224 | } // Fin du namespace
|
---|
225 |
|
---|
226 | #endif
|
---|