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

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

LinFitter -> passe template cmv 14/4/00

File size: 7.4 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
24 */
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
[926]50//! Solve A*C = B for C in place and return determinant
51/*! \ingroup TArray \fn LinSolveInPlace */
52inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
53{
54if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
55 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
56return SimpleMatrixOperation<r_4>::GausPiv(a,b);
57}
58
59//! Solve A*X = B in place and return determinant
60/*! \ingroup TArray \fn LinSolveInPlace */
[772]61inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
62{
63if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
64 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
65return SimpleMatrixOperation<r_8>::GausPiv(a,b);
66}
67
[926]68//! Solve A*X = B in place and return determinant
69/*! \ingroup TArray \fn LinSolveInPlace */
70inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
71{
[772]72if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
[926]73 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
74return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
[772]75}
76
[926]77//! Solve A*X = B in place and return determinant
78/*! \ingroup TArray \fn LinSolveInPlace */
79inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
80{
[850]81if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
[926]82 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
83return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
[850]84}
85
[935]86//------------------------------------------------------------
[926]87// Resolution du systeme A*C = B, avec C retourne dans B
[935]88//------------------------------------------------------------
89
[926]90//! Solve A*C = B and return C and determinant
91/*! \ingroup TArray \fn LinSolve */
92inline 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);
[850]97}
98
[926]99//! Solve A*C = B and return C and determinant
100/*! \ingroup TArray \fn LinSolve */
101inline 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);
[850]106}
107
[926]108//! Solve A*C = B and return C and determinant
109/*! \ingroup TArray \fn LinSolve */
110inline 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}
[850]116
[926]117//! Solve A*C = B and return C and determinant
118/*! \ingroup TArray \fn LinSolve */
119inline 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
[935]126} // Fin du namespace
127
[926]128////////////////////////////////////////////////////////////////
[935]129////////////////////////////////////////////////////////////////
130//------------------------------------------------------------//
131// Inverse d'une matrice //
132//------------------------------------------------------------//
133////////////////////////////////////////////////////////////////
134////////////////////////////////////////////////////////////////
135
136namespace SOPHYA {
137
[926]138//! To inverse a TMatrix
139/*! \ingroup TArray \fn Inverse */
140inline 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 */
144inline 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 */
148inline 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 */
152inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
153 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
154
[935]155} // Fin du namespace
[772]156
[935]157
158////////////////////////////////////////////////////////////////
159////////////////////////////////////////////////////////////////
160//------------------------------------------------------------//
161// Linear fitting //
162//------------------------------------------------------------//
163////////////////////////////////////////////////////////////////
164////////////////////////////////////////////////////////////////
165
166namespace SOPHYA {
167
168/*!
169 \class LinFitter
170 \ingroup TArray
171 Class for linear fitting
172 \sa TMatrix TArray
173 */
174
[926]175//! Class for linear fitting
[939]176template <class T>
[804]177class LinFitter {
[939]178
[804]179public :
180
[939]181 LinFitter();
182virtual ~LinFitter();
[804]183
[939]184//! Linear fitting
185r_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
189r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
[804]190
[939]191//! Linear fitting with errors
192r_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);
[804]194
[939]195//! Linear fitting with errors
196r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
197 const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
[804]198};
199
[772]200} // Fin du namespace
201
202#endif
Note: See TracBrowser for help on using the repository browser.