


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



EECS 268: Spring 2009 Laboratory 1: Matrix Determinant Due: 11:59:59 pm the day before your lab meets the week of February 9 Lecture Topics: Recursion, Classes Lab Topics: Command-line Parameters, Overloaded I/O Operators
1. Introduction In this lab, you will develop a recursive algorithm for computing the determinant of a general n x n matrix and write some additional functions to demonstrate that it works. Since we have not yet studied how to dynamically allocate multiply dimensioned arrays, you will initially: โ Define a const int MaxSize = 10; โ Define a class Matrix that contains a two-dimensional array of double precision floating point variables of size MaxSize x MaxSize. Actual arrays will be of size n x n where n โค MaxSize. You will create member functions with the following prototypes. (The "int n" parameter to the constructor will describe the actual size of the matrix.) โ Matrix(int n = MaxSize); โ double determinant(); โ Matrix inverse(); โ Matrix subMatrix(int i, int j); โ Matrix operator*(const Matrix &rhs); โ friend std::ostream& operator<<(std::ostream& os, Matrix& m); โ friend std::istream& operator>>(std::istream& is, Matrix& m); Through this lab you will demonstrate the ability to identify, formulate, and implement software solutions for various Matrix computational problems. 2. The Recursive Determinant Algorithm 2.1 Sub Matrix A submatrix of an n x n matrix is a matrix of size (n-1) x (n-1) created by removing one row and one column
i-th row and the j-th column. (The i and j indexes vary from 0 to (n-1) .) For example, consider the Matrix: 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44
2.2 The Determinant
of M formed by deleting row i and column j, then the determinant of an n x n matrix, M -- written as det( M ) --
x = 0 n - 1
x
Notice the alternating sign change in the expression above. 2.3 Inverse
where I is the identity matrix. Using the notation introduced above, the inverse of an n x n matrix can be
Pay careful attention to the subscripts in the expressions above! 2.4 Multiplication
x = 0 n - 1
Note: This lab only requires multiplying an n x n matrix, M , by its n x n inverse, Minv. Therefore, the multiplication function does not need to check for or recover from attempts to multiply matrices with invalid dimensions.
3. Development and Testing Initially use a stub for the inverse function. Have the function simply return the input matrix. Do not start to implement inverse until the recursive determinant function is completely debugged. Your program is to read a file consisting of a series of specifications in the following format: n m00 โฆ m0n โฆ mn0 โฆ mnn For each specification, print the original matrix, M , and compute and print its determinant. If the determinant is not equal to zero, compute and print the inverse matrix. (While your inverse function is stubbed, you will of course simply see a copy of the input matrix. That's OK for starters.) Finally, compute and print the product of the matrix and its inverse. Note: There may be additional whitespace (newlines, etc.) in the input. However, the order of the matrix specifications will not change. 4. Input & Output Your program will be expected to read input from the first file specified on the command line and to write output to the second file specified on the command line. Your program should display an error message and exit immediately if the expected command-line parameters are not provided. Following is an example of how your program will be run from the command line: $ ./main input.txt output.txt