Assignment 5

A Parameterized Matrix Class and Gaussian Elimination

Due date: Friday, April 11, 2014 at class time

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. Note: you've already handed in your very last hand-drawn UML diagram

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 operators

    4. C++ to "wrap" a data type

    5. interactions between objects of differing classes

Resources:

The Concept:

In the last two assignments, you had to write and use array classes. In a mathematical sense, there isn't much difference between an array and a vector. But in the programming world, there is. For a vector class you need to add functionality to reflect how vectors are used in mathematics. In the last assignments, you were using arrays of arrays, or vectors of vectors, or arrays of vectors, or .... 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). But to do this, you will have to modify drastically your array class to include the functionality of vectors. 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 sizes if you like.

In order to make this assignment really exciting, you are going to use your matrix and vector classes to solve a problem. (Remember: the STL vector class isn't a good option. Write your own vector class.) You remember how to solve linear systems using Gaussian elimination? Yes, I thought so; we've all been doing that since 6th grade. Now is the time to code this process using OOP. You are to code the pivoting method known as partial pivoting. It is presented in almost every text on elementary numerical methods and you certianly should have seen it in your cs 228 (or equivalent) course. I have several such texts, if you need to borrow one. You can also check out the link above for Mathworld. I will provide a data set for you containing a coefficient matrix (A) and a vector (b) for solving the problem Ax = b for x. You can find them HERE . The format of this file is what you should code your project to: first entry is the dimension of the problem; next are the rows of A; finally, the transpose of b. Your driver should take as a command line argument the name of the file containing such data.

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 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 object use of overloaded stream operators

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

    • provides functionality for matrix - vector multiplication.

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/it 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, vector, gaussian_solver, 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 partial pivoting. 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.)

As always, make your output easy to read. Pay particular attention to this requirement as your grader will have to read that output and it is so important to keep him happy.

Deliverables:

    1. Code: I will test that the code you submit does indeed compile and run. You are to copy all your source code along with a makefile according to the 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).