#include <yang.h>
Public Member Functions | |
Mtx (int n, int m, double **) | |
Mtx (int n, int m, double d=0) | |
Mtx (const Mtx &) | |
~Mtx () | |
Mtx & | operator= (const Mtx &) |
Mtx & | operator+= (const Mtx &) |
Mtx & | operator-= (const Mtx &) |
Vtr | operator* (const Vtr &) const |
double * | operator[] (int i) const |
Mtx & | operator+ () |
Mtx | operator+ (const Mtx &) |
int | rows () const |
int | cols () const |
void | getcol (int i, Vtr &vec) const |
void | setcol (int i, const Vtr &vec) |
void | clear () |
int | transpose (Mtx &dest) const |
Mtx | operator* (const Mtx &) const |
const double & | operator() (int i, int j) const |
double & | operator() (int i, int j) |
int | QRdecomp (Mtx &Q, Mtx &R) |
int | QRdecomp_slow (Mtx &Q, Mtx &R) |
Private Attributes | |
int | nrows |
int | ncols |
double ** | ets |
Friends | |
Mtx | operator- (const Mtx &) |
Mtx | operator- (const Mtx &, const Mtx &) |
Vtr | operator* (const Vtr &, const Mtx &) |
std::ostream & | operator<< (std::ostream &, const Mtx &) |
Definition at line 48 of file yang.h.
Mtx::Mtx | ( | int | n, | |
int | m, | |||
double ** | dbp | |||
) |
Mtx::Mtx | ( | int | n, | |
int | m, | |||
double | d = 0 | |||
) |
Mtx::Mtx | ( | const Mtx & | mat | ) |
Mtx::~Mtx | ( | ) |
void Mtx::clear | ( | ) |
Definition at line 251 of file yang.cc.
Referenced by QRdecomp(), and QRdecomp_slow().
int Mtx::cols | ( | ) | const [inline] |
Definition at line 74 of file yang.h.
Referenced by operator<<(), and transpose().
00074 {return ncols;}
void Mtx::getcol | ( | int | i, | |
Vtr & | vec | |||
) | const |
double& Mtx::operator() | ( | int | i, | |
int | j | |||
) | [inline] |
const double& Mtx::operator() | ( | int | i, | |
int | j | |||
) | const [inline] |
Definition at line 287 of file yang.cc.
00288 { 00289 Mtx tmp(nrows, mat.ncols); 00290 00291 if (ncols != mat.nrows) 00292 error("Mtx::op*=: Bad matrix sizes."); 00293 00294 for (int i = 0; i < nrows; i++) 00295 for (int j = 0; j < mat.ncols; j++) 00296 for (int k = 0; k < ncols; k++) 00297 tmp(i,j) += ets[i][k] * mat.ets[k][j]; 00298 00299 return tmp; 00300 }
Mtx & Mtx::operator+ | ( | ) |
double* Mtx::operator[] | ( | int | i | ) | const [inline] |
Definition at line 302 of file yang.cc.
00303 { 00304 if ((Q.nrows != nrows) || (Q.ncols != ncols) || 00305 (R.nrows != ncols) || (R.ncols != ncols)) { 00306 std::cerr << "Mtx::QRdecomp(): Error: Bad matrix size."; 00307 return -1; 00308 } 00309 00310 double** tmp; 00311 double norm, dot; 00312 00313 // tmp = A transpose 00314 int tmprows = ncols; 00315 int tmpcols = nrows; 00316 tmp = new double* [tmprows]; 00317 for (int i=0; i<tmprows; i++) { 00318 tmp[i] = new double [tmpcols]; 00319 for (int j=0; j<tmpcols; j++) 00320 tmp[i][j] = ets[j][i]; 00321 } 00322 Mat_DP QT(tmprows,tmpcols); 00323 00324 R.clear(); 00325 00326 for (int i=0; i<tmprows; i++) { 00327 norm = 0; 00328 for (int k=0; k<tmpcols; k++) 00329 norm += tmp[i][k]*tmp[i][k]; 00330 norm = std::sqrt(norm); 00331 R.ets[i][i] = norm; 00332 for (int k=0; k<tmpcols; k++) 00333 QT.ets[i][k] = tmp[i][k] / norm; 00334 00335 for (int j=i+1; j<tmprows; j++) { 00336 dot = 0; 00337 for (int k=0; k<tmpcols; k++) 00338 dot += QT.ets[i][k]*tmp[j][k]; 00339 R.ets[i][j] = dot; 00340 for (int k=0; k<tmpcols; k++) 00341 tmp[j][k] = tmp[j][k] - dot*QT.ets[i][k]; 00342 } 00343 } 00344 00345 QT.transpose(Q); 00346 00347 for (int i=0; i<tmprows; i++) 00348 delete[] tmp[i]; 00349 return 0; 00350 }
Definition at line 352 of file yang.cc.
00353 { 00354 if ((Q.nrows != nrows) || (Q.ncols != ncols) || 00355 (R.nrows != ncols) || (R.ncols != ncols)) { 00356 std::cerr << "Mtx::QRdecomp(): Error: Bad matrix size."; 00357 return -1; 00358 } 00359 00360 double** tmp; 00361 double norm, dot; 00362 00363 tmp = new double* [nrows]; 00364 for (int i=0; i<nrows; i++) { 00365 tmp[i] = new double [ncols]; 00366 for (int j=0; j<ncols; j++) 00367 tmp[i][j] = ets[i][j]; 00368 } 00369 00370 R.clear(); 00371 00372 for (int i=0; i<ncols; i++) { 00373 norm = 0; 00374 for (int k=0; k<nrows; k++) 00375 norm += tmp[k][i]*tmp[k][i]; 00376 norm = std::sqrt(norm); 00377 R.ets[i][i] = norm; 00378 for (int k=0; k<nrows; k++) 00379 Q.ets[k][i] = tmp[k][i] / norm; 00380 00381 for (int j=i+1; j<ncols; j++) { 00382 dot = 0; 00383 for (int k=0; k<nrows; k++) 00384 dot += Q.ets[k][i]*tmp[k][j]; 00385 R.ets[i][j] = dot; 00386 for (int k=0; k<nrows; k++) 00387 tmp[k][j] = tmp[k][j] - dot*Q.ets[k][i]; 00388 } 00389 } 00390 00391 for (int i=0; i<nrows; i++) 00392 delete[] tmp[i]; 00393 return 0; 00394 }
int Mtx::rows | ( | ) | const [inline] |
Definition at line 73 of file yang.h.
Referenced by operator<<(), and transpose().
00073 {return nrows;}
void Mtx::setcol | ( | int | i, | |
const Vtr & | vec | |||
) |
int Mtx::transpose | ( | Mtx & | dest | ) | const |
Definition at line 258 of file yang.cc.
Referenced by QRdecomp().
00259 { 00260 if ((nrows != dest.cols()) || (ncols != dest.rows())) { 00261 std::cerr << "Mtx::transpose(): Error: Matrix dim." 00262 << std::endl; 00263 return -1; 00264 } 00265 00266 for (int i=0; i<nrows; i++) 00267 for (int j=0; j<ncols; j++) 00268 dest(j, i) = ets[i][j]; 00269 return 0; 00270 }
std::ostream& operator<< | ( | std::ostream & | s, | |
const Mtx & | mat | |||
) | [friend] |
Definition at line 272 of file yang.cc.
00273 { 00274 for (int i = 0; i < mat.rows(); i++) { 00275 s << "| "; 00276 for(int j = 0; j < mat.cols(); j++) { 00277 s.setf(std::ios_base::fixed, std::ios_base::floatfield); 00278 s.precision(4); 00279 s.width(8); 00280 s << mat.ets[i][j]; 00281 } 00282 s << " |" << std::endl; 00283 } 00284 return s; 00285 }
double** Mtx::ets [private] |
Definition at line 52 of file yang.h.
Referenced by clear(), getcol(), Mtx(), operator()(), operator*(), operator*(), operator+=(), operator-=(), operator<<(), operator=(), operator[](), QRdecomp(), QRdecomp_slow(), setcol(), transpose(), and ~Mtx().
int Mtx::ncols [private] |
Definition at line 51 of file yang.h.
Referenced by clear(), cols(), Mtx(), operator*(), operator*(), operator+=(), operator-(), operator-=(), operator=(), QRdecomp(), QRdecomp_slow(), and transpose().
int Mtx::nrows [private] |
Definition at line 50 of file yang.h.
Referenced by clear(), getcol(), Mtx(), operator*(), operator*(), operator+=(), operator-(), operator-=(), operator=(), QRdecomp(), QRdecomp_slow(), rows(), setcol(), transpose(), and ~Mtx().