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

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

mise en template des inline + new GausPiv+Determinant cmv 3/5/00

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