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

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

gestion det dans GausPiv et new norm cmv 16/5/00

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