source: Sophya/trunk/SophyaLib/TArray/sopemtx.h@ 970

Last change on this file since 970 was 958, checked in by ansari, 25 years ago

doc + vire warning cmv 18/04/00

File size: 8.1 KB
Line 
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
17namespace 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
27template <class T>
28class SimpleMatrixOperation {
29public:
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
44namespace SOPHYA {
45
46//------------------------------------------------------------
47// Resolution du systeme A*C = B
48//------------------------------------------------------------
49
50/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_4>&,TVector<r_4>&)
51 \brief Solve A*C = B for C in place and return determinant
52*/
53inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
54{
55if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
56 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
57return SimpleMatrixOperation<r_4>::GausPiv(a,b);
58}
59
60/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_8>&,TVector<r_8>&)
61 \brief Solve A*X = B in place and return determinant
62*/
63inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
64{
65if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
66 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
67return SimpleMatrixOperation<r_8>::GausPiv(a,b);
68}
69
70/*! \ingroup TArray
71 \fn LinSolveInPlace(TMatrix< complex<r_4> >&, TVector< complex<r_4> >&)
72 \brief Solve A*X = B in place and return determinant */
73inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
74{
75if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
76 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
77return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
78}
79
80/*! \ingroup TArray
81 \fn LinSolveInPlace(TMatrix< complex<r_8> >&, TVector< complex<r_8> >&)
82 \brief Solve A*X = B in place and return determinant
83*/
84inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
85{
86if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
87 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
88return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
89}
90
91//------------------------------------------------------------
92// Resolution du systeme A*C = B, avec C retourne dans B
93//------------------------------------------------------------
94
95/*! \ingroup TArray
96 \fn LinSolve(const TMatrix<r_4>&, const TVector<r_4>&, TVector<r_4>&)
97 \brief Solve A*C = B and return C and determinant
98*/
99
100inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {
101 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
102 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
103 c = b; TMatrix<r_4> a1(a);
104 return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
105}
106
107/*! \ingroup TArray
108 \fn LinSolve(const TMatrix<r_8>&, const TVector<r_8>&, TVector<r_8>&)
109 \brief Solve A*C = B and return C and determinant
110*/
111inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) {
112 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
113 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
114 c = b; TMatrix<r_8> a1(a);
115 return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
116}
117
118/*! \ingroup TArray
119 \fn LinSolve(const TMatrix< complex<r_4> >&, const TVector< complex<r_4> >&, TVector< complex<r_4> >&)
120 \brief Solve A*C = B and return C and determinant
121*/
122inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) {
123 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
124 throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
125 c = b; TMatrix< complex<r_4> > a1(a);
126 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c);
127}
128
129/*! \ingroup TArray
130 \fn LinSolve(const TMatrix< complex<r_8> >&, const TVector< complex<r_8> >&, TVector< complex<r_8> >&)
131 \brief Solve A*C = B and return C and determinant
132*/
133inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) {
134 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
135 throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
136 c = b; TMatrix< complex<r_8> > a1(a);
137 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c);
138}
139
140} // Fin du namespace
141
142////////////////////////////////////////////////////////////////
143////////////////////////////////////////////////////////////////
144//------------------------------------------------------------//
145// Inverse d'une matrice //
146//------------------------------------------------------------//
147////////////////////////////////////////////////////////////////
148////////////////////////////////////////////////////////////////
149
150namespace SOPHYA {
151
152/*! \ingroup TArray
153 \fn Inverse(TMatrix<r_4> const &)
154 \brief To inverse a TMatrix
155*/
156inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
157 {return SimpleMatrixOperation<r_4>::Inverse(A);}
158/*! \ingroup TArray
159 \fn Inverse(TMatrix<r_8> const &)
160 \brief To inverse a TMatrix
161*/
162inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
163 {return SimpleMatrixOperation<r_8>::Inverse(A);}
164/*! \ingroup TArray
165 \fn Inverse(TMatrix< complex<r_4> > const &)
166 \brief To inverse a TMatrix (complex numbers)
167*/
168inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
169 {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
170/*! \ingroup TArray
171 \fn Inverse(TMatrix< complex<r_8> > const &)
172 \brief To inverse a TMatrix (complex numbers)
173*/
174inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
175 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
176
177} // Fin du namespace
178
179
180////////////////////////////////////////////////////////////////
181////////////////////////////////////////////////////////////////
182//------------------------------------------------------------//
183// Linear fitting //
184//------------------------------------------------------------//
185////////////////////////////////////////////////////////////////
186////////////////////////////////////////////////////////////////
187
188namespace SOPHYA {
189
190/*!
191 \class LinFitter
192 \ingroup TArray
193 Class for linear fitting
194 \sa TMatrix TArray
195*/
196
197//! Class for linear fitting
198template <class T>
199class LinFitter {
200
201public :
202
203 LinFitter();
204virtual ~LinFitter();
205
206//! Linear fitting
207r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
208 uint_4 nf, T (*f)(uint_4,T), TVector<T>& c);
209
210//! Linear fitting
211r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
212
213//! Linear fitting with errors
214r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
215 uint_4 nf,T (*f)(uint_4,T), TVector<T>& c, TVector<T>& errC);
216
217//! Linear fitting with errors
218r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
219 const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
220};
221
222} // Fin du namespace
223
224#endif
Note: See TracBrowser for help on using the repository browser.