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 | //! 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 */
|
---|
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 |
|
---|
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 | {
|
---|
72 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
73 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
|
---|
74 | return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
|
---|
75 | }
|
---|
76 |
|
---|
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 | {
|
---|
81 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
82 | throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
|
---|
83 | return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
|
---|
84 | }
|
---|
85 |
|
---|
86 | //------------------------------------------------------------
|
---|
87 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
88 | //------------------------------------------------------------
|
---|
89 |
|
---|
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);
|
---|
97 | }
|
---|
98 |
|
---|
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);
|
---|
106 | }
|
---|
107 |
|
---|
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 | }
|
---|
116 |
|
---|
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 |
|
---|
126 | } // Fin du namespace
|
---|
127 |
|
---|
128 | ////////////////////////////////////////////////////////////////
|
---|
129 | ////////////////////////////////////////////////////////////////
|
---|
130 | //------------------------------------------------------------//
|
---|
131 | // Inverse d'une matrice //
|
---|
132 | //------------------------------------------------------------//
|
---|
133 | ////////////////////////////////////////////////////////////////
|
---|
134 | ////////////////////////////////////////////////////////////////
|
---|
135 |
|
---|
136 | namespace SOPHYA {
|
---|
137 |
|
---|
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 |
|
---|
155 | } // Fin du namespace
|
---|
156 |
|
---|
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 |
|
---|
175 | //! Class for linear fitting
|
---|
176 | template <class T>
|
---|
177 | class LinFitter {
|
---|
178 |
|
---|
179 | public :
|
---|
180 |
|
---|
181 | LinFitter();
|
---|
182 | virtual ~LinFitter();
|
---|
183 |
|
---|
184 | //! Linear fitting
|
---|
185 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
|
---|
186 | uint_4 nf, T (*f)(uint_4,T), TVector<T>& c);
|
---|
187 |
|
---|
188 | //! Linear fitting
|
---|
189 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
|
---|
190 |
|
---|
191 | //! Linear fitting with errors
|
---|
192 | r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
|
---|
193 | uint_4 nf,T (*f)(uint_4,T), TVector<T>& c, TVector<T>& errC);
|
---|
194 |
|
---|
195 | //! Linear fitting with errors
|
---|
196 | r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
|
---|
197 | const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
|
---|
198 | };
|
---|
199 |
|
---|
200 | } // Fin du namespace
|
---|
201 |
|
---|
202 | #endif
|
---|