// library matvec.cc (<-- printvec.cc) #include // exit #include #include // needed for ifstream and ofstream #include // sqrt //------------------------------------------------------------------- // Print elements of a vector (length n) // void PrintVec(const int n, const double x[]) { int i; cout << endl; for (i=0; i> n; // read dimension vec = new double [n]; // allocate memory for vector for (i=0; i> vec[i]; } return; } //------------------------------------------------------------------- // Print elements of a matrix // (nrow rows and ncol columns) // void PrintMat(const int nrow, const int ncol, const double a[]) { int i,j; cout << endl; for (i=0; i> nrow; // read dimensions infile >> ncol; mat = new double [nrow*ncol]; // allocate memory for matrix for (i=0; i> mat[i*ncol+j]; } } return; } //------------------------------------------------------------------- // matrix times vector : erg := A * u // with a flexible number of columns in matrix void MatMul(const int nrow, const int ncol, const double a[], const double u[], double erg[]) { int i,j; for (i=0; i