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

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

Corrections divers + RansomSequence - Reza 10/4/2000

File size: 2.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
9namespace SOPHYA {
10
11
12
13////////////////////////////////////////////////////////////////
14template <class T>
15class SimpleMatrixOperation {
16public:
17 // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes
18 // operations sur la matrice B
19 static TMatrix<T> Inverse(TMatrix<T> const & A);
20 static T GausPiv(TMatrix<T>& A, TMatrix<T>& B);
21};
22
23// Resolution du systeme A*C = B
24inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
25{
26if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
27 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
28return SimpleMatrixOperation<r_8>::GausPiv(a,b);
29}
30
31// Resolution du systeme A*C = B, avec C retourne dans B
32inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
33{
34if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
35 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
36c = b;
37TMatrix<r_8> a1(a);
38return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
39}
40
41inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c)
42{
43if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
44 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
45c = b;
46TMatrix<r_4> a1(a);
47return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
48}
49
50// Inverse d'une matrice
51inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
52{
53 return SimpleMatrixOperation<r_8>::Inverse(A);
54}
55
56inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
57{
58 return SimpleMatrixOperation<r_4>::Inverse(A);
59}
60
61
62//--------------------------------------
63// Linear fitting
64//--------------------------------------
65
66class LinFitter {
67public :
68 LinFitter();
69 virtual ~LinFitter();
70
71 double LinFit(const Vector& x, const Vector& y, int nf,
72 double (*f)(int, double), Vector& c);
73// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1;
74
75 double LinFit(const Matrix& fx, const Vector& y, Vector& c);
76// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
77// la matrice fx contient les valeurs des f:
78// fx(i,j) = f(i, x(j)).
79
80 double LinFit(const Vector& x, const Vector& y, const Vector& errY2, int nf,
81 double (*f)(int, double), Vector& c, Vector& errC);
82// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
83// errY2 contient les carres des erreurs sur les Y.
84// au retour, errC contient les erreurs sur les coefs.
85
86 double LinFit(const Matrix& fx, const Vector& y, const Vector& errY2,
87 Vector& c, Vector& errC);
88// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
89// la matrice fx contient les valeurs des f:
90// fx(i,j) = f(i, x(j)).
91// errY2 contient les carres des erreurs sur les Y.
92// au retour, errC contient les erreurs sur les coefs.
93};
94
95
96} // Fin du namespace
97
98#endif
Note: See TracBrowser for help on using the repository browser.