Saint Louis University |
Computer Science 146
|
Dept. of Math & Computer Science |
Topic: Matrix Expansion
Due:
11:59pm Tuesday, 29 February 2012
Please make sure you adhere to the policies on academic integrity.
In this assignment, we add additional functionality based upon similar features found in MATLAB. In particular, we examine the way that MATLAB handles assignments to an element of a matrix, particularly when the indices given appear to be beyond the current bounds of a matrix. In our C++, consider working with a matrix A having current contents
5 15 3 8 20 2 14 3With our standard zero-indexing of rows and columns, we have seen that a syntax such as A(1,2) would be used to retrieve the element having value 14 and that an assignment syntax
5 15 3 8 20 2 35 3
If a user were to attempt to access a non-existing element, perhaps
with a command such as
As an example, using the zero-indexing convention of C++, we might
expect a command
5 15 3 8 20 2 35 3 0 0 0 0 0 7 0 0adding two additional rows so that entry A(3,1) can be properly placed. Continuing with this example, an assignment of
5 15 3 8 14 20 2 35 3 0 0 0 0 0 0 0 7 0 0 0Finally, we note that a single assignment may require the expansion of new rows and new columns. Continuing with our example, the result of the assignment
5 15 3 8 14 0 0 0 20 2 35 3 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 20
double operator()(int r, int c) constand
double operator()(int r, int c)The only difference in the signatures is the use of the keyword const in the first of these. C++ uses that differentiation to allow us to vary the behaviors of retrieving an existing entry (the const signature is applied) versus assinging a new value to an entry (the non-const signature is applied). Therefore, you will be modifying the second of those functions.
In terms of the underlying algorithm, we want you to carefully consider how much data movement is required. Keep in mind that the underlying data is stored in column-major order in a one-dimensional vector. Therefore, if a new matrix entry causes us to add columns (but not rows), it should be reasonably easy to make the necessary adjustment by adding more entries to the end of the underlying vector. However, you will find that adding new rows to a table stored in column-major order is non-trivial. In this case, you should still be able to use the same (expanded) vector, but you will have to be much more careful about how to move data around without losing any information.
If working on turing, change directories into a desired subdirectory of your home folder if desired, and to execute the following command verbatim
cp -R /Public/goldwasser/146/asgn05 .This will cause a new folder named asgn05 to appear in your working directory including all files that you need for this assignment (however, with our earlier verison of matrix.h). Alternatively, these files can be downloaded individual from this website. The matrix definition is essentially the same one we have been using for past assignments. However, we have written a new driver for this assignment to make it easier for you to test your code. That driver is named testExpand and can be built with the make command.
Since you will need to work with the underlying vector object, it will be helpful to browse through documentation for the vector class and in particular for the resize method of that class.
Your revised matrix.h file should be submitted electronically (details on the submission process).