// ENERGY211/CME211 // // main.cpp - Main application file that tests functions from // the SparseMatrix class // #include #include #include "sparsemat.h" using namespace std; int main() { try { // This creates a 3x3 zero matrix SparseMatrix A(3,3); A(1,1) = 1.0; cout double x = A(2,2); cout // By trying to access the (2,2) element, // entries in the map are created even though // the element is zero cout // So this will report nnz = 2 even though // it should be 1 cout // This will correct the problem A.Squeeze(); cout cout // Confirm that the matrix hasn't changed cout cout } catch(runtime_error e) { cout } try { // Test basic matrix operations SparseMatrix A; A.Identity( 4 ); A(0,1) = 2.0; A(1,2) = 3.0; A(2,3) = 4.0; cout cout SparseMatrix B = A * A; cout cout SparseMatrix T = B.Transpose(); cout cout SparseMatrix C = B + T; cout cout } catch(runtime_error e) { cout } return 0; }