37 VMatrix::VMatrix(
const unsigned int nRows,
const unsigned int nCols) :
38 numRows(nRows), numCols(nCols), theVec(nRows * nCols) {
41 VMatrix::VMatrix(
const VMatrix &aMatrix) :
42 numRows(aMatrix.numRows), numCols(aMatrix.numCols), theVec(
55 void VMatrix::resize(
const unsigned int nRows,
const unsigned int nCols) {
58 theVec.resize(nRows * nCols);
66 VMatrix aResult(numCols, numRows);
67 for (
unsigned int i = 0; i < numRows; ++i) {
68 for (
unsigned int j = 0; j < numCols; ++j) {
69 aResult(j, i) = theVec[numCols * i + j];
79 unsigned int VMatrix::getNumRows()
const {
87 unsigned int VMatrix::getNumCols()
const {
92 void VMatrix::print()
const {
93 std::cout <<
" VMatrix: " << numRows <<
"*" << numCols << std::endl;
94 for (
unsigned int i = 0; i < numRows; ++i) {
95 for (
unsigned int j = 0; j < numCols; ++j) {
97 std::cout << std::endl << std::setw(4) << i <<
","
98 << std::setw(4) << j <<
"-" << std::setw(4)
99 << std::min(j + 4, numCols) <<
":";
101 std::cout << std::setw(13) << theVec[numCols * i + j];
104 std::cout << std::endl << std::endl;
110 for (
unsigned int i = 0; i < this->numRows; ++i) {
112 for (
unsigned int j = 0; j < this->numCols; ++j) {
113 sum += theVec[numCols * i + j] * aVector(j);
124 for (
unsigned int i = 0; i < numRows; ++i) {
125 for (
unsigned int j = 0; j < aMatrix.
numCols; ++j) {
127 for (
unsigned int k = 0; k < numCols; ++k) {
128 sum += theVec[numCols * i + k] * aMatrix(k, j);
138 VMatrix aResult(numRows, numCols);
139 for (
unsigned int i = 0; i < numRows; ++i) {
140 for (
unsigned int j = 0; j < numCols; ++j) {
141 aResult(i, j) = theVec[numCols * i + j] + aMatrix(i, j);
149 if (
this != &aMatrix) {
152 theVec.resize(numRows * numCols);
153 for (
unsigned int i = 0; i < numRows; ++i) {
154 for (
unsigned int j = 0; j < numCols; ++j) {
155 theVec[numCols * i + j] = aMatrix(i, j);
164 VSymMatrix::VSymMatrix(
const unsigned int nRows) :
165 numRows(nRows), theVec((nRows * nRows + nRows) / 2) {
168 VSymMatrix::~VSymMatrix() {
177 theVec.resize((nRows * nRows + nRows) / 2);
190 std::cout <<
" VSymMatrix: " <<
numRows <<
"*" <<
numRows << std::endl;
191 for (
unsigned int i = 0; i <
numRows; ++i) {
192 for (
unsigned int j = 0; j <= i; ++j) {
194 std::cout << std::endl << std::setw(4) << i <<
","
195 << std::setw(4) << j <<
"-" << std::setw(4)
196 << std::min(j + 4, i) <<
":";
198 std::cout << std::setw(13) <<
theVec[(i * i + i) / 2 + j];
201 std::cout << std::endl << std::endl;
207 for (
unsigned int i = 0; i <
numRows; ++i) {
208 for (
unsigned int j = 0; j <= i; ++j) {
209 aResult(i, j) =
theVec[(i * i + i) / 2 + j] - aMatrix(i, j);
218 for (
unsigned int i = 0; i <
numRows; ++i) {
219 aResult(i) =
theVec[(i * i + i) / 2 + i] * aVector(i);
220 for (
unsigned int j = 0; j < i; ++j) {
221 aResult(j) +=
theVec[(i * i + i) / 2 + j] * aVector(i);
222 aResult(i) +=
theVec[(i * i + i) / 2 + j] * aVector(j);
232 for (
unsigned int l = 0; l < nCol; ++l) {
233 for (
unsigned int i = 0; i <
numRows; ++i) {
234 aResult(i, l) =
theVec[(i * i + i) / 2 + i] * aMatrix(i, l);
235 for (
unsigned int j = 0; j < i; ++j) {
236 aResult(j, l) +=
theVec[(i * i + i) / 2 + j] * aMatrix(i, l);
237 aResult(i, l) +=
theVec[(i * i + i) / 2 + j] * aMatrix(j, l);
246 VVector::VVector(
const unsigned int nRows) :
247 numRows(nRows), theVec(nRows) {
250 VVector::VVector(
const VVector &aVector) :
251 numRows(aVector.numRows), theVec(aVector.theVec) {
255 VVector::~VVector() {
275 std::memcpy(&aResult.
theVec[0], &
theVec[start],
sizeof(
double) * len);
286 sizeof(
double) * aVector.
numRows);
299 std::cout <<
" VVector: " <<
numRows << std::endl;
300 for (
unsigned int i = 0; i <
numRows; ++i) {
303 std::cout << std::endl << std::setw(4) << i <<
"-" << std::setw(4)
304 << std::min(i + 4,
numRows) <<
":";
306 std::cout << std::setw(13) <<
theVec[i];
308 std::cout << std::endl << std::endl;
314 for (
unsigned int i = 0; i <
numRows; ++i) {
315 aResult(i) =
theVec[i] - aVector(i);
322 if (
this != &aVector) {
325 for (
unsigned int i = 0; i <
numRows; ++i) {
350 const double eps = 1.0E-10;
352 std::vector<int> next(aSize);
353 std::vector<double> diag(aSize);
357 for (
int i = 1; i <= nSize; ++i) {
359 diag[i - 1] = fabs(
theVec[(i * i + i) / 2 - 1]);
361 next[aSize - 1] = -1;
363 unsigned int nrank = 0;
364 for (
int i = 1; i <= nSize; ++i) {
373 int jj = (j * j + j) / 2 - 1;
374 if (fabs(
theVec[jj]) > std::max(fabs(vkk), eps * diag[j - 1])) {
384 int kk = (k * k + k) / 2 - 1;
388 next[last - 1] = next[k - 1];
397 for (
int m = 1; m <= nSize; ++m) {
412 for (
int l = 1; l <= k - 1; ++l) {
419 for (
int l = k + 1; l <= m; ++l) {
425 for (
int l = 1; l <= m; ++l) {
434 for (
int m = 1; m <= nSize; ++m) {
435 if (next[m - 1] >= 0) {
436 int kk = (m * m - m) / 2 - 1;
437 for (
int n = 1; n <= nSize; ++n) {
438 if (next[n - 1] >= 0) {
447 for (
int ij = 0; ij < (nSize * nSize + nSize) / 2; ++ij) {
Simple Matrix based on std::vector<double>
unsigned int numCols
Number of columns.
unsigned int getNumRows() const
Get number of rows.
unsigned int getNumCols() const
Get number of columns.
Simple symmetric Matrix based on std::vector<double>
void resize(const unsigned int nRows)
Resize symmetric matrix.
unsigned int numRows
Number of rows.
VSymMatrix operator-(const VMatrix &aMatrix) const
Subtraction SymMatrix-(sym)Matrix.
unsigned int invert()
Matrix inversion.
void print() const
Print matrix.
unsigned int getNumRows() const
Get number of rows (= number of colums).
std::vector< double > theVec
Data (symmetric storage)
VVector operator*(const VVector &aVector) const
Multiplication SymMatrix*Vector.
Simple Vector based on std::vector<double>
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
void resize(const unsigned int nRows)
Resize vector.
unsigned int numRows
Number of rows.
VVector operator-(const VVector &aVector) const
Subtraction Vector-Vector.
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
void print() const
Print vector.
unsigned int getNumRows() const
Get number of rows.
std::vector< double > theVec
Data.
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Namespace for the general broken lines package.