// tsncom05.cc // Nick Macks (macks@fnal.gov), Summer 2002 // LinearAlgebra: Matrix subtraction // (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 BuildMatrix2(Matrix&, const int&); void DeclareSpecialized(Matrix&, Matrix&, Matrix&, const int&); void DeclareSymmetric(Matrix&, Matrix&, Matrix&); void Show(const Matrix&, const Matrix&); void GetCalcs(int&); void GetRuns(int&); void Calculate(Matrix&, 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 (large values) 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) { matrix1.declareM55(); matrix2.declareM55(); matrix3.declareM55(); } else if (dimension == 6) { matrix1.declareM66(); matrix2.declareM66(); matrix3.declareM66(); } else if (dimension == 4) { matrix1.declareM44(); matrix2.declareM44(); matrix3.declareM44(); } else if (dimension == 3) { matrix1.declareM33(); matrix2.declareM33(); matrix3.declareM33(); } else if (dimension == 2) { matrix1.declareM22(); matrix2.declareM22(); matrix3.declareM22(); } else if (dimension == 1) cout << "Matrices weren't declared as specialized since dimension is 1\n"; } } // Ask the user if he wants the matrices declared symmetric void DeclareSymmetric(Matrix& matrix1, Matrix& matrix2, Matrix& matrix3) { 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') ) { matrix1.declareSymmetric(); matrix2.declareSymmetric(); matrix3.declareSymmetric(); } } // Show the matrices void Show(const Matrix& matrix1, const Matrix& matrix2) { cout << "Using matrix =\n" << matrix1 << "\n"; cout << "Using matrix =\n" << matrix2 << "\n"; } // Get the number of calculations void GetCalcs(int& N) { cout << "How many subtractions? "; cin >> N; } // Get the number of runs void GetRuns(int& run) { cout << "How many runs? "; cin >> run; cout << "\n"; } // Subtract the matrices void Calculate(Matrix& matrix1, Matrix& matrix2, Matrix& difference, const int& dimension, const int& N, const int& runs) { // Define a counter int counter = 0; // Loop "run" times for (int r=0; r