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

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

encore de la doc cmv 17/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
51 \fn LinSolveInPlace(TMatrix<r_4>&, TVector<r_4>&)
52 \brief Solve A*C = B for C in place and return determinant
53*/
54inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
55{
56if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
57 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
58return SimpleMatrixOperation<r_4>::GausPiv(a,b);
59}
60
61/*! \ingroup TArray
62 \fn LinSolveInPlace (TMatrix<r_8>&, TVector<r_8>&)
63 \brief Solve A*X = B in place and return determinant
64*/
65inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
66{
67if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
68 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
69return SimpleMatrixOperation<r_8>::GausPiv(a,b);
70}
71
72/*! \ingroup TArray
73 \fn LinSolveInPlace(TMatrix< complex<r_4> >&, TVector< complex<r_4> >&)
74 \brief Solve A*X = B in place and return determinant */
75inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
76{
77if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
78 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
79return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
80}
81
82/*! \ingroup TArray
83 \fn LinSolveInPlace(TMatrix< complex<r_8> >&, TVector< complex<r_8> >&)
84 \brief Solve A*X = B in place and return determinant
85*/
86inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
87{
88if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
89 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
90return 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(const TMatrix<r_4>&, const TVector<r_4>&, TVector<r_4>&)
99 \brief Solve A*C = B and return C and determinant
100*/
101
102inline 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(const TMatrix<r_8>&, const TVector<r_8>&, TVector<r_8>&)
111 \brief Solve A*C = B and return C and determinant
112*/
113inline 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(const TMatrix< complex<r_4> >&, const TVector< complex<r_4> >&, TVector< complex<r_4> >&)
122 \brief Solve A*C = B and return C and determinant
123*/
124inline 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(const TMatrix< complex<r_8> >&, const TVector< complex<r_8> >&, TVector< complex<r_8> >&)
133 \brief Solve A*C = B and return C and determinant
134*/
135inline 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
152namespace SOPHYA {
153
154/*! \ingroup TArray
155 \fn Inverse(TMatrix<r_4> const &)
156 \brief To inverse a TMatrix
157*/
158inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
159 {return SimpleMatrixOperation<r_4>::Inverse(A);}
160/*! \ingroup TArray
161 \fn Inverse(TMatrix<r_8> const &)
162 \brief To inverse a TMatrix
163*/
164inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
165 {return SimpleMatrixOperation<r_8>::Inverse(A);}
166/*! \ingroup TArray
167 \fn Inverse(TMatrix< complex<r_4> > const &)
168 \brief To inverse a TMatrix (complex numbers)
169*/
170inline 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(TMatrix< complex<r_8> > const &)
174 \brief To inverse a TMatrix (complex numbers)
175*/
176inline 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
190namespace 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
200template <class T>
201class LinFitter {
202
203public :
204
205 LinFitter();
206virtual ~LinFitter();
207
208//! Linear fitting
209r_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
213r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
214
215//! Linear fitting with errors
216r_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
220r_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
Note: See TracBrowser for help on using the repository browser.