You need get the following files and you must NOT make any changes to these files:
class Vector { public: int N float *v; Vector(); Vector(int n); Vector(float w[], int n); Vector operator+(Vector &w); Vector operator=(Vector &w); };This class contains three constructor functions that are used to define vectors using the following declaration:
Vector v1(); Vector v1(n); Vector v1(w, n);The first form defines a vector of unknown n (pointer variable v is uninitialized). The second form defines an uninitialized vector of size n and in the thrid form, the variable v1 will have an array of n elements and the elements are initialized with the float array w. Basically, the constructor must allocate space for the vector and copy the elements from w to the allocated array.
The operator+ function adds 2 vectors together.
The operator= function is used to copy one vector to another vector. You need to define an assignment operator because you used pointers in Vector.
class Matrix { public: virtual Vector operator*(Vector &v); };The Matrix type is used to make polymorphic function calls. You don't need to do anything with this class.
class DenseMatrix : public Matrix { public: int N; float *A; Vector output; DenseMatrix(float *M, int n); Vector operator*(Vector &v); };This class also contains a constructor function like Vector. This contructor will be used to define matrices using the following declaration:
DenseMatrix M1(M, n);The variable M1 will have an array of n*n elements and the elements are initialized with the float array M (use the i*N+j method to access array elements). The constructor must allocate space for the matrix and copy the elements from M to the allocated array. The constructor must also allocate space for array in the Vector variable output vector (n floats). This variable is used in the operator* function to store the output vector and returned by the operator* function.
The operator* function multiplies a dense matrix and a vector together.
class SparseMatrix : public Matrix { public: int nnz; float *val; int *row; int *col; SparseMatrix(float *M, int N); Vector operator*(Vector &v); };This class represents a sparse matrix using the Coordinate-wise method. This contructor in this class is more involved, and it will be used to define matrices using the following declaration:
SparseMatrix M1(M, n);The input matrix M is an n x n matrix. Before you can allocate space for the 3 arrays (val, row and col), you need to determine the number of non-zero elements in M. Use the i*N+j method to access elements in M. After determining the number of non-zero elements, the constructor allocate space for val, row and col to store the non-zero elements of M.
The operator* function multiplies a sparse matrix and a vector together.
3 10 1 2 1 10 3 2 3 10 5 6 7
The first number is the dimension of the matrix (3 equations). The next n*n numbers (float) are the coefficients of the matrix. Then last n is the RHS of the equation.
NOTE: the above equation input is the same equation that we solved in class - so you can compare your solution with a working one.
NOTE: this is just a sample input, your program must work for equations of arbitrary size !
Your program is invoked using the following syntax from the UNIX command prompt:
UNIX>> main < input-dataFor example, to run the program on the sample data, you would issue this command:
UNIX>> main < pj5-data
The output of the program must go to the screen and you must print the solution vector of each Jacobi iteration.
The program must solve the same system using both the dense matrix and the sparse matrix representation. (You should see the same output twice if both methods are correctly implemented).
Due to the use of Makefile, I don't need to know exactly how you organize your programs (and I should not care).
If you follow the instructions below carefully, I will be able to compile your program without any problems:
/home/cs561000/turnin Makefile pj5
/home/cs561000/turnin OneOfYourFile pj5-#where "#" is a digit between 0 and 9.