#include <yang.h>
List of all members.
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 &) |
Detailed Description
Definition at line 48 of file yang.h.
Constructor & Destructor Documentation
Mtx::Mtx |
( |
int |
n, |
|
|
int |
m, |
|
|
double ** |
dbp | |
|
) |
| | |
Mtx::Mtx |
( |
int |
n, |
|
|
int |
m, |
|
|
double |
d = 0 | |
|
) |
| | |
Definition at line 147 of file yang.cc.
{
ets = new double* [nrows = n];
for (int i = 0; i< nrows; i++) {
ets[i] = new double [ncols = m];
for (int j = 0; j < ncols; j++) ets[i][j] = a;
}
}
Mtx::Mtx |
( |
const Mtx & |
mat |
) |
|
Definition at line 155 of file yang.cc.
{
ets = new double* [nrows = mat.nrows];
for (int i = 0; i< nrows; i++) {
ets[i] = new double [ncols = mat.ncols];
for (int j = 0; j < ncols; j++) ets[i][j] = mat[i][j];
}
}
Definition at line 163 of file yang.cc.
{
for (int i = 0; i< nrows; i++) delete[] ets[i];
delete[] ets;
}
Member Function Documentation
int Mtx::cols |
( |
|
) |
const [inline] |
void Mtx::getcol |
( |
int |
i, |
|
|
Vtr & |
vec | |
|
) |
| | const |
Definition at line 235 of file yang.cc.
{
if (vec.size() != nrows)
error("Mtx::getcol(): Bad vector size.");
for (int i = 0; i < nrows; i++)
vec[i] = ets[i][n];
}
double& Mtx::operator() |
( |
int |
i, |
|
|
int |
j | |
|
) |
| | [inline] |
const double& Mtx::operator() |
( |
int |
i, |
|
|
int |
j | |
|
) |
| | const [inline] |
Vtr Mtx::operator* |
( |
const Vtr & |
v |
) |
const |
Definition at line 205 of file yang.cc.
{
if (ncols != v.size())
error("Mtx::op*(Vtr): Error: Mat. and vec. sizes do not match.");
Vtr tm(nrows);
for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncols; j++) tm[i] += ets[i][j]*v[j];
return tm;
}
Mtx Mtx::operator* |
( |
const Mtx & |
mat |
) |
const |
Mtx Mtx::operator+ |
( |
const Mtx & |
mat |
) |
|
Definition at line 199 of file yang.cc.
{
Mtx sum = *this;
sum += mat;
return sum;
}
Mtx & Mtx::operator+= |
( |
const Mtx & |
mat |
) |
|
Mtx & Mtx::operator-= |
( |
const Mtx & |
mat |
) |
|
Mtx & Mtx::operator= |
( |
const Mtx & |
mat |
) |
|
double* Mtx::operator[] |
( |
int |
i |
) |
const [inline] |
int Mtx::QRdecomp |
( |
Mtx & |
Q, |
|
|
Mtx & |
R | |
|
) |
| | |
Definition at line 302 of file yang.cc.
{
if ((Q.nrows != nrows) || (Q.ncols != ncols) ||
(R.nrows != ncols) || (R.ncols != ncols)) {
std::cerr << "Mtx::QRdecomp(): Error: Bad matrix size.";
return -1;
}
double** tmp;
double norm, dot;
int tmprows = ncols;
int tmpcols = nrows;
tmp = new double* [tmprows];
for (int i=0; i<tmprows; i++) {
tmp[i] = new double [tmpcols];
for (int j=0; j<tmpcols; j++)
tmp[i][j] = ets[j][i];
}
Mat_DP QT(tmprows,tmpcols);
R.clear();
for (int i=0; i<tmprows; i++) {
norm = 0;
for (int k=0; k<tmpcols; k++)
norm += tmp[i][k]*tmp[i][k];
norm = std::sqrt(norm);
R.ets[i][i] = norm;
for (int k=0; k<tmpcols; k++)
QT.ets[i][k] = tmp[i][k] / norm;
for (int j=i+1; j<tmprows; j++) {
dot = 0;
for (int k=0; k<tmpcols; k++)
dot += QT.ets[i][k]*tmp[j][k];
R.ets[i][j] = dot;
for (int k=0; k<tmpcols; k++)
tmp[j][k] = tmp[j][k] - dot*QT.ets[i][k];
}
}
QT.transpose(Q);
for (int i=0; i<tmprows; i++)
delete[] tmp[i];
return 0;
}
int Mtx::QRdecomp_slow |
( |
Mtx & |
Q, |
|
|
Mtx & |
R | |
|
) |
| | |
Definition at line 352 of file yang.cc.
{
if ((Q.nrows != nrows) || (Q.ncols != ncols) ||
(R.nrows != ncols) || (R.ncols != ncols)) {
std::cerr << "Mtx::QRdecomp(): Error: Bad matrix size.";
return -1;
}
double** tmp;
double norm, dot;
tmp = new double* [nrows];
for (int i=0; i<nrows; i++) {
tmp[i] = new double [ncols];
for (int j=0; j<ncols; j++)
tmp[i][j] = ets[i][j];
}
R.clear();
for (int i=0; i<ncols; i++) {
norm = 0;
for (int k=0; k<nrows; k++)
norm += tmp[k][i]*tmp[k][i];
norm = std::sqrt(norm);
R.ets[i][i] = norm;
for (int k=0; k<nrows; k++)
Q.ets[k][i] = tmp[k][i] / norm;
for (int j=i+1; j<ncols; j++) {
dot = 0;
for (int k=0; k<nrows; k++)
dot += Q.ets[k][i]*tmp[k][j];
R.ets[i][j] = dot;
for (int k=0; k<nrows; k++)
tmp[k][j] = tmp[k][j] - dot*Q.ets[k][i];
}
}
for (int i=0; i<nrows; i++)
delete[] tmp[i];
return 0;
}
int Mtx::rows |
( |
|
) |
const [inline] |
void Mtx::setcol |
( |
int |
i, |
|
|
const Vtr & |
vec | |
|
) |
| | |
Definition at line 243 of file yang.cc.
{
if (vec.size() != nrows)
error("Mtx::getcol(): Bad vector size.");
for (int i = 0; i < nrows; i++)
ets[i][n] = vec[i];
}
int Mtx::transpose |
( |
Mtx & |
dest |
) |
const |
Definition at line 258 of file yang.cc.
Referenced by QRdecomp().
{
if ((nrows != dest.cols()) || (ncols != dest.rows())) {
std::cerr << "Mtx::transpose(): Error: Matrix dim."
<< std::endl;
return -1;
}
for (int i=0; i<nrows; i++)
for (int j=0; j<ncols; j++)
dest(j, i) = ets[i][j];
return 0;
}
Friends And Related Function Documentation
Vtr operator* |
( |
const Vtr & |
v, |
|
|
const Mtx & |
mat | |
|
) |
| | [friend] |
Definition at line 214 of file yang.cc.
{
if (v.lenth != mat.nrows)
error("op*(Vtr, Mtx): Error: Mat. and vec. size do no match.");
Vtr res(mat.ncols, 0.0);
for (int i=0; i<mat.ncols; i++)
for (int j=0; j<v.lenth; j++)
res[i] = v.ets[j] * mat.ets[j][i];
return res;
}
Mtx operator- |
( |
const Mtx & |
m1, |
|
|
const Mtx & |
m2 | |
|
) |
| | [friend] |
Mtx operator- |
( |
const Mtx & |
mat |
) |
[friend] |
std::ostream& operator<< |
( |
std::ostream & |
s, |
|
|
const Mtx & |
mat | |
|
) |
| | [friend] |
Definition at line 272 of file yang.cc.
{
for (int i = 0; i < mat.rows(); i++) {
s << "| ";
for(int j = 0; j < mat.cols(); j++) {
s.setf(std::ios_base::fixed, std::ios_base::floatfield);
s.precision(4);
s.width(8);
s << mat.ets[i][j];
}
s << " |" << std::endl;
}
return s;
}
Member Data Documentation
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().
Definition at line 51 of file yang.h.
Referenced by clear(), cols(), Mtx(), operator*(), operator*(), operator+=(), operator-(), operator-=(), operator=(), QRdecomp(), QRdecomp_slow(), and transpose().
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().
The documentation for this class was generated from the following files: