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

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

documentation cmv 13/4/00

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// doivent imperativement reste avant le namespace SOPHYA !
10/*!
11 \class SOPHYA::SimpleMatrixOperation
12 \ingroup TArray
13 Class for simple operation on TMatrix
14 \sa TMatrix TArray
15 */
16/*!
17 \class SOPHYA::LinFitter
18 \ingroup TArray
19 Class for linear fitting
20 \sa TMatrix TArray
21 */
22
23namespace SOPHYA {
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////////////////////////////////////////////////////////////////
35// Resolution du systeme A*C = B
36//! Solve A*C = B for C in place and return determinant
37/*! \ingroup TArray \fn LinSolveInPlace */
38inline r_4 LinSolveInPlace(TMatrix<r_4>& a, TVector<r_4>& b)
39{
40if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
41 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_4>,TVector<r_4>) size mismatch"));
42return SimpleMatrixOperation<r_4>::GausPiv(a,b);
43}
44
45//! Solve A*X = B in place and return determinant
46/*! \ingroup TArray \fn LinSolveInPlace */
47inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
48{
49if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
50 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
51return SimpleMatrixOperation<r_8>::GausPiv(a,b);
52}
53
54//! Solve A*X = B in place and return determinant
55/*! \ingroup TArray \fn LinSolveInPlace */
56inline complex<r_4> LinSolveInPlace(TMatrix< complex<r_4> >& a, TVector< complex<r_4> >& b)
57{
58if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
59 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
60return SimpleMatrixOperation< complex<r_4> >::GausPiv(a,b);
61}
62
63//! Solve A*X = B in place and return determinant
64/*! \ingroup TArray \fn LinSolveInPlace */
65inline complex<r_8> LinSolveInPlace(TMatrix< complex<r_8> >& a, TVector< complex<r_8> >& b)
66{
67if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
68 throw(SzMismatchError("LinSolveInPlace(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
69return SimpleMatrixOperation< complex<r_8> >::GausPiv(a,b);
70}
71
72////////////////////////////////////////////////////////////////
73// Resolution du systeme A*C = B, avec C retourne dans B
74//! Solve A*C = B and return C and determinant
75/*! \ingroup TArray \fn LinSolve */
76inline r_4 LinSolve(const TMatrix<r_4>& a, const TVector<r_4>& b, TVector<r_4>& c) {
77 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
78 throw(SzMismatchError("LinSolve(TMatrix<r_4>,TVector<r_4>) size mismatch"));
79 c = b; TMatrix<r_4> a1(a);
80 return SimpleMatrixOperation<r_4>::GausPiv(a1,c);
81}
82
83//! Solve A*C = B and return C and determinant
84/*! \ingroup TArray \fn LinSolve */
85inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c) {
86 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
87 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
88 c = b; TMatrix<r_8> a1(a);
89 return SimpleMatrixOperation<r_8>::GausPiv(a1,c);
90}
91
92//! Solve A*C = B and return C and determinant
93/*! \ingroup TArray \fn LinSolve */
94inline complex<r_4> LinSolve(const TMatrix< complex<r_4> >& a, const TVector< complex<r_4> >& b, TVector< complex<r_4> >& c) {
95 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
96 throw(SzMismatchError("LinSolve(TMatrix< complex<r_4> >,TVector< complex<r_4> >) size mismatch"));
97 c = b; TMatrix< complex<r_4> > a1(a);
98 return SimpleMatrixOperation< complex<r_4> >::GausPiv(a1,c);
99}
100
101//! Solve A*C = B and return C and determinant
102/*! \ingroup TArray \fn LinSolve */
103inline complex<r_8> LinSolve(const TMatrix< complex<r_8> >& a, const TVector< complex<r_8> >& b, TVector< complex<r_8> >& c) {
104 if(a.NCols()!=b.NRows() || a.NCols()!=a.NRows())
105 throw(SzMismatchError("LinSolve(TMatrix< complex<r_8> >,TVector< complex<r_8> >) size mismatch"));
106 c = b; TMatrix< complex<r_8> > a1(a);
107 return SimpleMatrixOperation< complex<r_8> >::GausPiv(a1,c);
108}
109
110////////////////////////////////////////////////////////////////
111// Inverse d'une matrice
112//! To inverse a TMatrix
113/*! \ingroup TArray \fn Inverse */
114inline TMatrix<r_4> Inverse(TMatrix<r_4> const & A)
115 {return SimpleMatrixOperation<r_4>::Inverse(A);}
116//! To inverse a TMatrix
117/*! \ingroup TArray \fn Inverse */
118inline TMatrix<r_8> Inverse(TMatrix<r_8> const & A)
119 {return SimpleMatrixOperation<r_8>::Inverse(A);}
120//! To inverse a TMatrix
121/*! \ingroup TArray \fn Inverse */
122inline TMatrix< complex<r_4> > Inverse(TMatrix< complex<r_4> > const & A)
123 {return SimpleMatrixOperation< complex<r_4> >::Inverse(A);}
124//! To inverse a TMatrix
125/*! \ingroup TArray \fn Inverse */
126inline TMatrix< complex<r_8> > Inverse(TMatrix< complex<r_8> > const & A)
127 {return SimpleMatrixOperation< complex<r_8> >::Inverse(A);}
128
129//--------------------------------------
130// Linear fitting
131//--------------------------------------
132
133//! Class for linear fitting
134class LinFitter {
135public :
136 LinFitter();
137 virtual ~LinFitter();
138
139 double LinFit(const Vector& x, const Vector& y, int nf,
140 double (*f)(int, double), Vector& c);
141// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1;
142
143 double LinFit(const Matrix& fx, const Vector& y, Vector& c);
144// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
145// la matrice fx contient les valeurs des f:
146// fx(i,j) = f(i, x(j)).
147
148 double LinFit(const Vector& x, const Vector& y, const Vector& errY2, int nf,
149 double (*f)(int, double), Vector& c, Vector& errC);
150// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
151// errY2 contient les carres des erreurs sur les Y.
152// au retour, errC contient les erreurs sur les coefs.
153
154 double LinFit(const Matrix& fx, const Vector& y, const Vector& errY2,
155 Vector& c, Vector& errC);
156// fit lineaire des y en tant que somme de c(i)f(i,x), i=0..nf-1,
157// la matrice fx contient les valeurs des f:
158// fx(i,j) = f(i, x(j)).
159// errY2 contient les carres des erreurs sur les Y.
160// au retour, errC contient les erreurs sur les coefs.
161};
162
163
164} // Fin du namespace
165
166#endif
Note: See TracBrowser for help on using the repository browser.