Docsity

Lab 1 for Matrix Determinant | Programming II | EECS 268, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
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
from the original n x n matrix. We will use the notation
Si , j
to denote the sub matrix created by removing the
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
The matrix
S1,2
would be:
11 12 14
31 32 34
41 42 44
2.2 The Determinant
pf3
pf4

Partial preview of the text

Download Lab 1 for Matrix Determinant | Programming II | EECS 268 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

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

from the original n x n matrix. We will use the notation Si , j to denote the sub matrix created by removing the

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

The matrix S 1,2 would be:

2.2 The Determinant

The determinant of a 1 x 1 matrix, M , is the single floating point number M^ 0,0. The determinant of a 2 x 2

matrix, M , is the floating point number: M^ 0,0โˆ— M^ 1,1โˆ’ M^ 1,0โˆ— M^ 0,1. If we let Si , j ๎‚ž^ M^ ๎‚Ÿ^ denote the submatrix

of M formed by deleting row i and column j, then the determinant of an n x n matrix, M -- written as det( M ) --

can be defined recursively as: det ๎‚ž M ๎‚Ÿ = โˆ‘

x = 0 n - 1

x

โˆ— M 0, x โˆ—det๎‚ž S 0, x ๎‚ž M ๎‚Ÿ๎‚Ÿ.

Notice the alternating sign change in the expression above. 2.3 Inverse

The inverse of an n x n matrix, M , is another n x n matrix, Minv , such that M โˆ— Minv = Minv โˆ— M = I ,

where I is the identity matrix. Using the notation introduced above, the inverse of an n x n matrix can be

computed as follows: Minvi , j = ๎‚ž- 1 ๎‚Ÿ i^ +^ j^ * det ๎‚ž S j , i ๎‚ž M ๎‚Ÿ๎‚Ÿ / det ๎‚ž M ๎‚Ÿ.

Pay careful attention to the subscripts in the expressions above! 2.4 Multiplication

The product of two n x n matrices, A and B , is another n x n matrix, C , such that Ci , j = โˆ‘

x = 0 n - 1

Ai , x โˆ— Bx , j.

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

  • Correctly define the Matrix class and implement all necessary functions.
  • Provide overloaded operators for multiplication, input, and output. 30 Recursive Determinant Algorithm
  • Demonstrate a recursive determinant algorithm with clearly stated base and recursive cases. 30 Documentation
  • Javadoc comments for all files, classes, and functions.
  • Internal documentation (especially recursive functions). 10 Programming Style & Output Formatting
  • Use standard paragraphing conventions and object orientated design practices. 100 Total