Klasse TestMatrix
/** TestMatmul:
* simple class to test the matrixmultiplikation
*/
#include <iostream.h>
#include "SquareMatrix.H"
class TestMatrix {
public:
TestMatrix(int n) : a(n), b(n), c(n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a.set(i, j, i + j);
b.set(i, j, i - j);
}
b.set(i, i, 1.0);
}
}
void run() {
a.mult(b, c);
}
void check() {
int n = a.shape()[0];
double sp_th = n * (n + 1);
double sp = c.trace();
double c12_th = (n * n * n - 7 * n + 9) / 3.0;
double c12 = c.get(1, 2);
cout << "Spur theoretisch: " << sp_th << endl;
cout << "Spur : " << sp << endl;
cout << "c(1,2) theor. : " << c12_th << endl;
cout << "c(1,2) : " << c12 << endl;
}
private:
SquareMatrix a, b, c;
};
int main(int argc, char* argv[]) {
try {
TestMatrix tm(500); // initialisiert alles
tm.run();
tm.check();
} catch (char* info) {
cerr << "EXCEPTION: " << info << endl;
return -1;
}
}

Peter Junglas 8.10.1999