// tsncom09.cc // Nick Macks (macks@fnal.gov), Summer 2002 // LinearAlgebra: Matrix multiplication // (user can specify if the matrices are to be declared specialized // and/or symmetric) #include "LinearAlgebra/Matrix.h" using namespace std; // Function declarations void Identification(); void GetDimension(int&); void Describe(const int&); void BuildMatrix(Matrix&, const int&); void DeclareMatrixSpecialized(Matrix&, const int&); void DeclareMatrixSymmetric(Matrix&); void Show(const Matrix&); void GetCalcs(int&); void GetRuns(int&); void Calculate(Matrix&, Matrix&, const int&, const int&, const int&); // Package ID void Identification() { cout << "Using LinearAlgebra\n"; } // Ask for the desired dimension void GetDimension(int& dimension) { cout << "Enter the desired dimension(1-6): "; cin >> dimension; while ( (dimension < 1) || (dimension > 6) ) { cout << "Enter an integer between 1 and 6: "; cin >> dimension; } } // Describe how the matrices were defined void Describe(const int& dimension) { cout << "Matrices were defined 'Matrix (" << dimension << ", " << dimension << ")'\n"; } // Build the matrix void BuildMatrix(Matrix& matrix, const int& dimension) { for (int i=0; i> special; while ( (special != 'y') && (special != 'Y') && (special != 'n') && (special != 'N') ) { cout << "Please enter y or n: "; cin >> special; } if ( (special == 'y') || (special == 'Y') ) { if (dimension == 5) matrix.declareM55(); else if (dimension == 6) matrix.declareM66(); else if (dimension == 4) matrix.declareM44(); else if (dimension == 3) matrix.declareM33(); else if (dimension == 2) matrix.declareM22(); else if (dimension == 1) cout << "Matrices weren't declared as specialized since dimension is 1\n"; } } // Ask the user if he wants the matrix declared symmetric void DeclareMatrixSymmetric(Matrix& matrix) { char symmetry; cout << "Declare Matrix as Symmetric? (y/n): "; cin >> symmetry; while ( (symmetry != 'y') && (symmetry != 'Y') && (symmetry != 'n') && (symmetry != 'N') ) { cout << "Please enter y or n: "; cin >> symmetry; } if ( (symmetry == 'y') || (symmetry == 'Y') ) matrix.declareSymmetric(); } // Show the matrix void Show(const Matrix& matrix) { cout << "Using matrix =\n" << matrix << "\n"; } // Get the number of calculations void GetCalcs(int& N) { cout << "How many multiplications? "; cin >> N; } // Get the number of runs void GetRuns(int& run) { cout << "How many runs? "; cin >> run; cout << "\n"; } // Multiply the matrices void Calculate(Matrix& matrix1, Matrix& matrix2, const int& dimension, const int& N, const int& runs) { // Define a counter int counter = 0; // Define a matrix to hold the result Matrix product (dimension, dimension); // Loop "run" times for (int r=0; r