Assignment 5

A Parameterized Matrix Class

Due Date: April 5, 2017

Required for submitting:

  • Grade Sheet Print this sheet and bring it to class the day the program is due.

  • Bring your UML diagram to class.

Purpose:

  • The purpose of this exercise is to give you more practice with the first few items listed below. And, as stated with the previous assignment, you will do good NOT to delay the implementation of the your solution to this assignment.

    1. templated classes

    2. templated functions

    3. overloading operator

    4. interactions between objects of differing classes

Resources:

  • Unix help This is an MST help site for the basics of Unix.

The Concept:

  • In the last 2 assignments I introduced the Gram-Schmidt process that operates on a set of vectors. So, in a way, you had to deal with a array of vectors (or a vector of arrays, however you like to look at it). Well, that situation isn't so uncommon. They are called matrices. And for this assignment, you are to code up a general (parameterized) matrix class for dense matrices (no assumption that some significant part of the matrix is a bunch of zeros). The most popular matrix is the square matrix (contrary to the socially accepted norm - nobody likes a square - but we don't care). So, you can assume that the number of rows and the number of columns will be the same, but you can code your class for differing row and col values if you like.

    • In order to make this assignment really exciting, you are going to use your matrix class and array class to solve a problem. You all remember Jacobi iteration for solving linear systems of equations from your CS 3200 course or equivalent? (OK, so don't laugh!) Yes, I thought so. I will provide you with a coefficient matrix linked HERE and you will use your matrix class in your driver to "solve" the system using Jacobi iteration. This means that you will have to code a method to implement Jacobi iteration and a vector norm to decide whether or not you are "close enough" to the solution. You get to decide which norm you want to use. (Remember that we proved that they are all equivalent.) You should include exception handling in the proper place to insure that any matrix to which you apply Jacobi is indeed diagonally dominant.

Program Specifications:

  • Now, you are free to use the design for your implementation as you like. There are many possibilities. Some are good methods; some are not. ... and some are really not. Don't use the STL vector class to contain your data. I wanted you to experience the STL to know the reason you should consider building your own data structures. It may be difficult, but once you understand the benefits, you will agree that it is worth the trouble. I discussed in class several different ways to build your class. You can choose one of these or you can use some other way that you believe is better. Of course, you will be graded on your implementations. There are pros and cons to the various methods. You may discover these on your own.

    • Your matrix class isn't very useful unless it can function like a matrix is expected to function, in the traditional mathematical ways. Thus, it is expected for this assignment that your class:

    • allows examination (can't be useful if you don't know what is in it)

    • provides objects use of overloaded stream operators.

    • provide operators for the standard matrix arithmetic operations of addition, subtraction, matrix multiplication, scalar multiplication

    • provide functionality for matrix - vector multiplication.

    • provide for a function or operator that will return the transpose of the matrix.

  • If you wish to include more functionality, please feel free to do so. And, of course, your class is to be a templateded class allowing the user of the class to parameterize the matrix with whatever type he/she wishes. Thus, you could have a matrix of floats or ints or bobs (the general, all-purpose variable).

    • So for this assignment, you are going to have several classes: matrix, array (or vector), norm, and any other you deem appropriate. Some details to consider:

    1. You don't have to provide indexing into the matrix with [ ]'s, but it's nice

    2. Make sure that your operations are provided for in the proper location. For example, multiplication of a matrix by a vector should be provided in the matrix class.

    3. If you overload insertion and extraction (and you WILL), use them. By the way, it's good to have two versions: one for files and one for others.

    4. Follow the reasonable guidelines for overloading operators (make multiplication the * and not the +).

    5. Make sure that your matrix multiplication checks for appropriate size considerations and delivers the properly dimensioned resultant.

  • So, your submission needs to include your classes and a driver that uses your constructions to solve a linear system using Jacobi Iteration. Also, in order that we know your matrix multiplication is working, first demonstrate that operation in your driver by multiplying the test data (matrix given above) by its transpose. (You could wow us by including functionality to return the transpose of matrix rather than just reading in another data set.)

    • One further note: if you want, implement Gauss-Seidel iteration in place of Jacobi. If you don't know what that is, look it up.

    • The format of the data is: first integer represents the size of the matrix (assumed square); the matrix is to follow; the right-hand-side vector (usually called 'b') follows the matrix. Make your program accept a command-line argument for the file to be read.

Output format:

For an nxn matrix, output n rows of n numbers. Commas or pipes in between are OK. Vector output should be the same as in previous homeworks; also, # and : work as previously described.

Deliverables:

  1. Code: I will test that the code you submit does indeed compile and run. You are to submit all your source code along with a makefile in the usual way. How to do this is explained in Submission procedure.

  2. makefile: Supply the makefile which compiles and builds your program as detailed above.

  3. Your gradesheet and UML (in class, of course).