#include #include "Vector.h" #include "DenseMatrix.h" #include "SparseMatrix.h" ostream & operator<<(ostream & cout, DenseMatrix m) { int i, j; for (i = 0; i < m.N; i++) { for (j = 0; j < m.N; j++) cout << m.A[i*m.N + j] << " "; cout << endl; } return(cout); } ostream & operator<<(ostream & cout, SparseMatrix m) { int i, j; double *h = new double[m.N*m.N]; for (i = 0; i < m.N; i++) for (j = 0; j < m.N; j++) h[i*m.N+j] = 0; for (i = 0; i < m.nnz; i++) h[m.row[i]*m.N + m.col[i]] = m.val[i]; for (i = 0; i < m.N; i++) { for (j = 0; j < m.N; j++) cout << h[i*m.N + j] << " "; cout << endl; } delete h; return(cout); } ostream & operator<<(ostream & cout, Vector v) { int i, j; for (i = 0; i < v.N; i++) { cout << v.x[i] << " "; } cout << endl; return(cout); } int main(int argc, char **argv) { int i, j, N; cin >> N; double *m = new double[N*N]; double *v = new double[N]; for (i = 0; i < N; i++) for (j = 0; j < N; j++) cin >> m[i*N+j]; for (i = 0; i < N; i++) cin >> v[i]; DenseMatrix D(m, N); SparseMatrix S(m, N); Vector v1(v, N); Vector v2; v2 = D * v1; cout << " D: " << endl << endl << D << endl; cout << " v1: " << endl << endl << v1 << endl; cout << " D*v1: " << endl << endl << v2 << endl; v2 = S * v1; cout << " S: " << endl << endl << S << endl; cout << " v1: " << endl << endl << v1 << endl; cout << " S*v1: " << endl << endl << v2 << endl; }