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

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

doc + vire warning cmv 18/04/00

File size: 8.1 KB
RevLine 
[772]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
[935]9////////////////////////////////////////////////////////////////
10////////////////////////////////////////////////////////////////
11//------------------------------------------------------------//
[939]12// La classe de calcul simple sur les TMatrix //
[935]13//------------------------------------------------------------//
14////////////////////////////////////////////////////////////////
15////////////////////////////////////////////////////////////////
16
17namespace SOPHYA {
18
[926]19/*!
[935]20 \class SimpleMatrixOperation
[926]21 \ingroup TArray
22 Class for simple operation on TMatrix
23 \sa TMatrix TArray
[947]24*/
[926]25
26//! Class for simple operation on TMatrix
[772]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
[935]34} // Fin du namespace
35
[926]36////////////////////////////////////////////////////////////////
[935]37////////////////////////////////////////////////////////////////
38//------------------------------------------------------------//
39// Resolution de systemes lineaires //
40//------------------------------------------------------------//
41////////////////////////////////////////////////////////////////
42////////////////////////////////////////////////////////////////
43
44namespace SOPHYA {
45
46//------------------------------------------------------------
[772]47// Resolution du systeme A*C = B
[935]48//------------------------------------------------------------
49
[958]50/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_4>&,TVector<r_4>&)
[947]51 \brief Solve A*C = B for C in place and return determinant
52*/
[926]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
[958]60/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<r_8>&,TVector<r_8>&)
[947]61 \brief Solve A*X = B in place and return determinant
62*/
[772]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
[947]70/*! \ingroup TArray
[956]71 \fn LinSolveInPlace(TMatrix< complex<r_4> >&, TVector< complex<r_4> >&)
[947]72 \brief Solve A*X = B in place and return determinant */
[926]73inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
74{
[772]75if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
[926]76 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
77return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
[772]78}
79
[947]80/*! \ingroup TArray
[956]81 \fn LinSolveInPlace(TMatrix< complex<r_8> >&, TVector< complex<r_8> >&)
[947]82 \brief Solve A*X = B in place and return determinant
83*/
[926]84inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
85{
[850]86if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
[926]87 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
88return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
[850]89}
90
[935]91//------------------------------------------------------------
[926]92// Resolution du systeme A*C = B, avec C retourne dans B
[935]93//------------------------------------------------------------
94
[947]95/*! \ingroup TArray
[956]96 \fn LinSolve(const TMatrix<r_4>&, const TVector<r_4>&, TVector<r_4>&)
[947]97 \brief Solve A*C = B and return C and determinant
98*/
99
[926]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);
[850]105}
106
[947]107/*! \ingroup TArray
[956]108 \fn LinSolve(const TMatrix<r_8>&, const TVector<r_8>&, TVector<r_8>&)
[947]109 \brief Solve A*C = B and return C and determinant
110*/
[926]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);
[850]116}
117
[947]118/*! \ingroup TArray
[956]119 \fn LinSolve(const TMatrix< complex<r_4> >&, const TVector< complex<r_4> >&, TVector< complex<r_4> >&)
[947]120 \brief Solve A*C = B and return C and determinant
121*/
[926]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}
[850]128
[947]129/*! \ingroup TArray
[956]130 \fn LinSolve(const TMatrix< complex<r_8> >&, const TVector< complex<r_8> >&, TVector< complex<r_8> >&)
[947]131 \brief Solve A*C = B and return C and determinant
132*/
[926]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
[935]140} // Fin du namespace
141
[926]142////////////////////////////////////////////////////////////////
[935]143////////////////////////////////////////////////////////////////
144//------------------------------------------------------------//
145// Inverse d'une matrice //
146//------------------------------------------------------------//
147////////////////////////////////////////////////////////////////
148////////////////////////////////////////////////////////////////
149
150namespace SOPHYA {
151
[947]152/*! \ingroup TArray
[956]153 \fn Inverse(TMatrix<r_4> const &)
[947]154 \brief To inverse a TMatrix
155*/
[926]156inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
157 {return SimpleMatrixOperation<r_4>::Inverse(A);}
[947]158/*! \ingroup TArray
[956]159 \fn Inverse(TMatrix<r_8> const &)
[947]160 \brief To inverse a TMatrix
161*/
[926]162inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
163 {return SimpleMatrixOperation<r_8>::Inverse(A);}
[947]164/*! \ingroup TArray
[956]165 \fn Inverse(TMatrix< complex<r_4> > const &)
[947]166 \brief To inverse a TMatrix (complex numbers)
167*/
[926]168inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
169 {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
[947]170/*! \ingroup TArray
[956]171 \fn Inverse(TMatrix< complex<r_8> > const &)
[947]172 \brief To inverse a TMatrix (complex numbers)
173*/
[926]174inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
175 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
176
[935]177} // Fin du namespace
[772]178
[935]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
[947]195*/
[935]196
[926]197//! Class for linear fitting
[939]198template <class T>
[804]199class LinFitter {
[939]200
[804]201public :
202
[939]203 LinFitter();
204virtual ~LinFitter();
[804]205
[939]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);
[804]212
[939]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);
[804]216
[939]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);
[804]220};
221
[772]222} // Fin du namespace
223
224#endif
Note: See TracBrowser for help on using the repository browser.