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

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

doc + inversion de matrice template real+complex

File size: 7.9 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// Classe TMatrixRC //
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//! 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 */
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
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{
72if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
73 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
74return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
75}
76
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{
81if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
82 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
83return 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 */
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);
97}
98
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);
106}
107
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}
116
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
126} // Fin du namespace
127
128////////////////////////////////////////////////////////////////
129////////////////////////////////////////////////////////////////
130//------------------------------------------------------------//
131// Inverse d'une matrice //
132//------------------------------------------------------------//
133////////////////////////////////////////////////////////////////
134////////////////////////////////////////////////////////////////
135
136namespace SOPHYA {
137
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
155} // Fin du namespace
156
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
175//! Class for linear fitting
176class LinFitter {
177public :
178 LinFitter();
179 virtual ~LinFitter();
180
181 double LinFit(const Vector& x, const Vector& y, int nf,
182 double (*f)(int, double), Vector& c);
183// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1;
184
185 double LinFit(const Matrix& fx, const Vector& y, Vector& c);
186// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
187// la matrice fx contient les valeurs des f:
188// fx(i,j) = f(i, x(j)).
189
190 double LinFit(const Vector& x, const Vector& y, const Vector& errY2, int nf,
191 double (*f)(int, double), Vector& c, Vector& errC);
192// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
193// errY2 contient les carres des erreurs sur les Y.
194// au retour, errC contient les erreurs sur les coefs.
195
196 double LinFit(const Matrix& fx, const Vector& y, const Vector& errY2,
197 Vector& c, Vector& errC);
198// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
199// la matrice fx contient les valeurs des f:
200// fx(i,j) = f(i, x(j)).
201// errY2 contient les carres des erreurs sur les Y.
202// au retour, errC contient les erreurs sur les coefs.
203};
204
205
206} // Fin du namespace
207
208#endif
Note: See TracBrowser for help on using the repository browser.