Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : TSTSMAT.CPP
// tstsmat.cpp: A test program for the SimpleMatrix class.
// Copyright(c) 1993 Azarona Software. All rights reserved.
/////////////////////////////////////////////////////////////
#include
#include
#include "simpmat.h"
template
void PrtMat(SimpleMatrix
// Prints out all elements of a matrix.
// Tests subscripting operation as well.
{
for (int i = 0; i
}
cout << '\n';
}
}
template
void SetVec(VecPtr
// Sets all elements of a vector to x. Assumes
// TYPE as '=' defined. Uses fastest form of vector
// element access.
{
unsigned i;
for (i = 0; i
v++;
}
}
template
void MatMult(SimpleMatrix
// Does a matrix multiply.
{
unsigned i, j, k;
if (a.NCols() == b.NRows() && // A & B must conform
c.NCols() == b.NCols() && // C must be right size too
c.NRows() == a.NRows()) {
for (i = 0; i < a.NRows(); i++) {
for (j = 0; j < b.NCols(); j++) {
TYPE sum = 0;
for (k = 0; k < b.NRows(); k++) sum += a[i][k] * b[k][j];
c[i][j] = sum;
}
}
}
else {
cout << "Matrices don't conform\n";
}
}
// BC++ seems to need this prototype
void MatMult(SimpleMatrix
template
SimpleMatrix
// Multiplies two matrices together and returns a resulting matrix.
// If matrices don't conform, a message is printed and the resulting
// matrix is set to all zeros.
{
SimpleMatrix
MatMult(r, a, b);
return r; // Copy constructor called. Bad news.
}
template
SimpleMatrix
// Returns the transpose of a matrix by interchanging
// rows and columns.
{
SimpleMatrix
for (unsigned i = 0; i
return t; // Copy constructor called.
}
template
void TRYIT(const SimpleMatrix
// Try updating a constant matrix.
{
unsigned i;
VecPtr
for (i = 0; i
v++;
}
}
main()
{
SimpleMatrix
cout << "Setting all elements to 4's\n";
SetVec(m.PtrToAll(), m.NElems(), 4);
cout << "m:\n"; PrtMat(m); cout << '\n';
cout << "Setting row 1 to all 2's\n";
SetVec(m.RowPtr(1), m.NCols(), 2);
cout << "m:\n"; PrtMat(m); cout << '\n';
cout << "Setting column 1 to all 3's\n";
SetVec(m.ColPtr(3), m.NRows(), 3);
cout << "m:\n"; PrtMat(m); cout << '\n';
cout << "Setting diagonal to 1's\n";
SetVec(m.DiagPtr(), m.NRows(), 1);
cout << "m:\n"; PrtMat(m); cout << '\n';
// Do a matrix multiply with a 3x2 matrix
SimpleMatrix
unsigned k = 0;
for(unsigned i = 0; i
cout << "m2:\n"; PrtMat(m2); cout << '\n';
cout << "Multiplying m by m2\n";
c = m * m2;
cout << "c = m x m2:\n"; PrtMat(c); cout << '\n';
// Transpose c
cout << "Transpose(c):\n"; PrtMat(Transpose(c)); cout << '\n';
TRYIT(m); // Try updating a constant matrix
return 0;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/