qavrg 0.0.28
|
#include <qavrgmatrix.h>
Public Member Functions | |
QavrgMatrix (int nr, int nc, QObject *parent=0) | |
void | fill (double val) |
void | resize (int nr, int nc) |
int | size (int indx) |
double & | operator() (int r, int c) |
QavrgMatrix & | operator= (const QavrgMatrix &m) |
void | dump () |
Static Public Member Functions | |
static void | test () |
static void | gaussj (QavrgMatrix &a, QVector< double > &b) |
Private Attributes | |
QVector< double > | m_Matrix |
int | m_NRows |
int | m_NCols |
double | m_Dummy |
Static Private Attributes | |
static int | m_Errors = 0 |
Definition at line 7 of file qavrgmatrix.h.
QavrgMatrix::QavrgMatrix | ( | int | nr, |
int | nc, | ||
QObject * | parent = 0 |
||
) |
Definition at line 8 of file qavrgmatrix.cpp.
void QavrgMatrix::dump | ( | ) |
Definition at line 53 of file qavrgmatrix.cpp.
References m_NCols, and m_NRows.
Referenced by test().
void QavrgMatrix::fill | ( | double | val | ) |
void QavrgMatrix::gaussj | ( | QavrgMatrix & | a, |
QVector< double > & | b | ||
) | [static] |
Definition at line 85 of file qavrgmatrix.cpp.
References m_Errors, size(), and SWAP.
Referenced by QavrgFitter::performCalculation().
{ int n1= a.size(1); int n2= a.size(2); int n = b.size(); if (n == n1 && n == n2) { int irow, icol; QVector<int> indxc(n), indxr(n), ipiv(n); ipiv.fill(-1); for (int i=0; i<n; i++) { double big=0; for (int j=0; j<n; j++) { if (ipiv[j] != 0) { for (int k=0; k<n; k++) { if (ipiv[k] == -1) { if (fabs(a(j,k)) >= big) { big = fabs(a(j,k)); irow=j; icol=k; } } else if (ipiv[k] > 0) { if (m_Errors < 10) { m_Errors++; printf("gaussj: Singular Matrix-1\n"); } return; } } } } ++(ipiv[icol]); if (irow != icol) { for (int l=0; l<n; l++) { SWAP(a(irow,l),a(icol,l)); } SWAP(b[irow],b[icol]); } indxr[i]=irow; indxc[i]=icol; if (a(icol,icol) == 0.0) { if (m_Errors < 10) { m_Errors++; printf("gaussj: Singular Matrix-2\n"); } return; } double pivinv = 1.0/a(icol,icol); a(icol,icol) = 1.0; for (int l=0; l<n; l++) { a(icol,l) *= pivinv; } b[icol] *= pivinv; for (int ll=0; ll<n; ll++) { if (ll != icol) { double dum = a(ll,icol); a(ll,icol) = 0.0; for (int l=0; l<n; l++) { a(ll,l) -= a(icol,l)*dum; } b[ll] -= b[icol]*dum; } } } for (int l=n-1; l>=0; l--) { if (indxr[l] != indxc[l]) { for (int k=0; k<n; k++) { SWAP(a(k,indxr[l]), a(k,indxc[l])); } } } } }
double & QavrgMatrix::operator() | ( | int | r, |
int | c | ||
) |
QavrgMatrix & QavrgMatrix::operator= | ( | const QavrgMatrix & | m | ) |
Definition at line 41 of file qavrgmatrix.cpp.
References m_Matrix.
void QavrgMatrix::resize | ( | int | nr, |
int | nc | ||
) |
int QavrgMatrix::size | ( | int | indx | ) |
void QavrgMatrix::test | ( | ) | [static] |
Definition at line 70 of file qavrgmatrix.cpp.
References dump().
{ QavrgMatrix m(5,5); for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { m(i,j) = 10*i+j; } } m.dump(); }
double QavrgMatrix::m_Dummy [private] |
Definition at line 30 of file qavrgmatrix.h.
Referenced by operator()().
int QavrgMatrix::m_Errors = 0 [static, private] |
Definition at line 31 of file qavrgmatrix.h.
Referenced by gaussj().
QVector<double> QavrgMatrix::m_Matrix [private] |
Definition at line 27 of file qavrgmatrix.h.
Referenced by fill(), operator()(), operator=(), and resize().
int QavrgMatrix::m_NCols [private] |
Definition at line 29 of file qavrgmatrix.h.
Referenced by dump(), operator()(), resize(), and size().
int QavrgMatrix::m_NRows [private] |
Definition at line 28 of file qavrgmatrix.h.
Referenced by dump(), operator()(), resize(), and size().