 CS-381 -- Lab 2: Matrix Class

Fall Quarter 1999

Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor

S-331, 277-7339 www.msoe.edu/~taylor/

### Purpose

The purpose of this lab assignment is to develop a matrix class which can be used to solve systems of linear equations.

### Assignment

A Matrix class should be developed with the following public interface:

 Method Description Constructors The usual host of constructors:  Default: empty matrix  (int N): Nth order identity matrix  (int N, int M): N x M matrix with an optional argument (of type double) that specifies the value of all elements  Copy Destructor For removing dynamic data components Operators Assignment =  (int N, int M): access (by reference) element in Nth row and Mth column  Equal ==  Not equal !=  Less than < (as computed by the Frobenius norm)  Greater than > (as computed by the Frobenius norm)  Multiplication *  Subtraction -  Addition +  Output stream << transpose Returns the transpose of the matrix determinant Returns the determinant of the matrix augment Augments the matrix with the matrix passed in as an argument. For example, if the original matrix is N x N and the matrix passed in is N x M, the resulting matrix is N x (N+M) where the first N columns comprise the original matrix and the last M columns comprise the matrix that was passed in. Note: no change should be made to the original matrix if the two matrices differ in height. extract Returns a matrix which consists of the last N (an unsigned int parameter which is passed in) columns of the matrix. lowerTriangular Returns lower-triangular part of the LU decomposition of the matrix upperTriangular Returns upper-triangular part of the LU decomposition of the matrix GaussJordan Returns a vector containing the solution (using the Gauss-Jordan method) to the system of equations represented by the matrix GaussJacobi Returns a vector containing the solution (using the Gauss-Jacobi method) to the system of equations represented by the matrix Inverse Returns the inverse of the matrix (using a method of your choice)

The methods should handle incorrect inputs gracefully. For example, if inverse() is called on a non-square or singular matrix, an error message should be displayed and an empty matrix should be returned.

In this lab, you are to do the following:

1. Design and implement Matrix class described above. You may find it useful to create additional private methods (e.g., pivot()) to aid in the implementation.
2. Design and implement a test program which thoroughly tests your Matrix class.

Note: It should be possible for you test program to be used to test any other student's Matrix class, and for any other student's test program to be used to test your Matrix class.

For this project, you are encouraged to work in groups of two; however, you may work individually.

### Lab report (due 4:30pm Tuesday, October 5, 1999)

One lab report is required of each group. The lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report. Your report should include:

• Purpose
• Problem Statement
• Procedure -- what approach you used to solve the problem
• Documented source code (you may wish to include this at the end of your report)
• Discussion (include the output from your test program, any problems you encountered and how they were resolved, etc...)
• Conclusions (what you learned, suggestions of how the lab could be improved, things you would have done differently, etc.)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic Submission Guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

If you have any questions, consult the instructor.