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

Last change on this file since 4065 was 3332, checked in by ansari, 18 years ago

1- Methode TArray::SumX2() renommee en ::SumSq()
2- Methode TArray::Norm2() appelle maintenant SumSq() - sauf pour les
tableaux complexes, ou on calcule Sum[el x conj(el)]=Sum[module2]
3- Nettoyage fichier sopemtx.cc (utilisation sa_size_t pour supprimer
les warnings g++

Reza , 02/10/2007

File size: 6.2 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 \brief Class for simple operation on TMatrix
23 This class provides presently a basic implementation of the Gauss
24 pivoting for linear system solving and matrix inversion.
25
26 \warning For large or ill conditioned matrices, use the methods
27 from LinAlg module.
28 \sa SOPHYA::LapackServer SOPHYA::TMatrix
29*/
30//! Class for simple operation on TMatrix
31template <class T>
32class SimpleMatrixOperation {
33public:
34 //! To define the type of data scaling for Gauss pivoting method (type T)
35 enum GausPivScal {
36 PIV_NO_SCALE = 0, //!< do not scale datas for gauss pivoting
37 PIV_GLOB_SCALE = 1, //!< do a global scaling of datas for gauss pivoting (default)
38 PIV_ROW_SCALE = 2 //!< do a scaling by row of datas for gauss pivoting
39 };
40 static inline int SetGausPivScal(int gps = PIV_GLOB_SCALE)
41 { GausPivScaling = gps; return GausPivScaling; }
42
43 static TMatrix<T> Inverse(TMatrix<T> const & A);
44 static T GausPiv(TMatrix<T>& A, TMatrix<T>& B, bool computedet=false);
45
46protected:
47 static int GausPivScaling;
48};
49
50} // Fin du namespace
51
52////////////////////////////////////////////////////////////////
53////////////////////////////////////////////////////////////////
54//------------------------------------------------------------//
55// Resolution de systemes lineaires //
56//------------------------------------------------------------//
57////////////////////////////////////////////////////////////////
58////////////////////////////////////////////////////////////////
59
60namespace SOPHYA {
61
62//------------------------------------------------------------
63// Resolution du systeme A*C = B
64//------------------------------------------------------------
65/*! \ingroup TArray \fn LinSolveInPlace(TMatrix<T>&,TVector<T>&)
66 \brief Solve A*C = B for C in place and return 1 if OK, 0 if not.
67*/
68template <class T>
69inline T LinSolveInPlace(TMatrix<T>& a, TVector<T>& b)
70{
71if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
72 throw(SzMismatchError("LinSolveInPlace(TMatrix<T>,TVector<T>) size mismatch"));
73return SimpleMatrixOperation<T>::GausPiv(a,b);
74}
75
76//------------------------------------------------------------
77// Resolution du systeme A*C = B, avec C retourne dans B
78//------------------------------------------------------------
79/*! \ingroup TArray
80 \fn LinSolve(const TMatrix<T>&, const TVector<T>&, TVector<T>&)
81 \brief Solve A*C = B and return C. Return 1 if OK, 0 if not.
82*/
83template <class T>
84inline T LinSolve(const TMatrix<T>& a, const TVector<T>& b, TVector<T>& c) {
85 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
86 throw(SzMismatchError("LinSolve(TMatrix<T>,TVector<T>) size mismatch"));
87 c = b; TMatrix<T> a1(a);
88 return SimpleMatrixOperation<T>::GausPiv(a1,c);
89}
90
91} // Fin du namespace
92
93////////////////////////////////////////////////////////////////
94////////////////////////////////////////////////////////////////
95//------------------------------------------------------------//
96// Inverse d'une matrice //
97//------------------------------------------------------------//
98////////////////////////////////////////////////////////////////
99////////////////////////////////////////////////////////////////
100
101namespace SOPHYA {
102
103/*! \ingroup TArray
104 \fn Inverse(TMatrix<T> const &)
105 \brief To inverse a TMatrix.
106*/
107template <class T>
108inline TMatrix<T> Inverse(TMatrix<T> const & A)
109 {return SimpleMatrixOperation<T>::Inverse(A);}
110
111/*! \ingroup TArray
112 \fn Determinant(TMatrix<T> const &)
113 \brief Return the TMatrix determinant
114*/
115template <class T>
116inline T Determinant(TMatrix<T> const & A) {
117 TMatrix<T> a(A,false);
118 TMatrix<T> b(a.NCols(),a.NRows()); b = IdentityMatrix(1.);
119 return SimpleMatrixOperation<T>::GausPiv(a,b,true);
120}
121
122/*! \ingroup TArray
123 \fn GausPiv(TMatrix<T> const &,TMatrix<T> &, bool)
124 \brief Gauss pivoting on matrix \b A, doing the same operations
125 on matrix \b B.
126 \param computedet = true : return the determinant of \b A
127 (beware of over/underfloat), default is false.
128 \return determinant if requested, or 1 if OK.
129 \sa SOPHYA::SimpleMatrixOperation::GausPiv(TMatrix<T>&,TMatrix<T>&,bool)
130*/
131template <class T>
132inline T GausPiv(TMatrix<T> const & A,TMatrix<T> & B, bool computedet=false) {
133 TMatrix<T> a(A,false);
134 return SimpleMatrixOperation<T>::GausPiv(a,B,computedet);
135}
136
137
138} // Fin du namespace
139
140
141////////////////////////////////////////////////////////////////
142////////////////////////////////////////////////////////////////
143//------------------------------------------------------------//
144// Linear fitting //
145//------------------------------------------------------------//
146////////////////////////////////////////////////////////////////
147////////////////////////////////////////////////////////////////
148
149namespace SOPHYA {
150
151/*!
152 \class LinFitter
153 \ingroup TArray
154 Class for linear fitting
155 \sa TMatrix TArray
156*/
157
158//! Class for linear fitting
159template <class T>
160class LinFitter {
161
162public :
163
164 LinFitter();
165virtual ~LinFitter();
166
167//! Linear fitting
168r_8 LinFit(const TVector<T>& x, const TVector<T>& y,
169 sa_size_t nf, T (*f)(sa_size_t,T), TVector<T>& c);
170
171//! Linear fitting
172r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y, TVector<T>& c);
173
174//! Linear fitting with errors
175r_8 LinFit(const TVector<T>& x, const TVector<T>& y, const TVector<T>& errY2,
176 sa_size_t nf,T (*f)(sa_size_t,T), TVector<T>& c, TVector<T>& errC);
177
178//! Linear fitting with errors
179r_8 LinFit(const TMatrix<T>& fx, const TVector<T>& y,
180 const TVector<T>& errY2, TVector<T>& c, TVector<T>& errC);
181};
182
183} // Fin du namespace
184
185#endif
Note: See TracBrowser for help on using the repository browser.