In this project you are asked to implement several methods in a file
Matrix.java, which will contain a class that
represents a matrix. The final
Matrix objects should be able to perform the following nine operations: add, subtract, (matrix and scalar) multiply, transpose,
identity matrix, trace, and random matrix, and a method that converts a matrix to an array. In this project, you will need to rely on your knowledge of loops and build on your understanding
of arrays, constructors, method overloading, exception handling, and static and non-static methods. In this project you will decide on the underlying implementation. I will, of
course, review your code. But unlike before, I will also subject your
Matrix class to a series of correctness tests. To pass
the correctness tests, your implementation need only follow the specifications described below.
First, we need to know how to create new Matrix objects. Here is a list of constructors that you need to implement:
Matrix(int m, int n). Creates a new matrix with
ncolumns whose initial entries are all zero.
Matrix(double elements). Creates a new matrix from the two-dimensional array
elements. (You may assume
elementsis not a ragged array.)
The methods that you need to implement are:
Matrix add(Matrix M). Returns a new Matrix object which represents the element-wise sum of the current matrix and another matrix
Mand throws a
Exceptionif the addition is not defined. Matrix addition is valid on for two matrices of the same size. For example, if the matrices below are represented by the Matrix objects
then the Java expression
A.add(B)should evaluate to their sum (shown below).
Matrix subtract(Matrix M). Returns a Matrix whose elements are the entry-wise subtraction of the current matrix and another matrix
Mwhen subtraction is well-defined and throws an
Matrix multiply(double scalar). Returns a Matrix object which results when each entry of the current matrix is multiplied by the factor
scalar. For example, if the matrix
Ais as above, then scalar multiplication of
Aby the scalar factor 8 is:
Matrix multiply(Matrix M). Returns a Matrix object that represents the result of multiplying the current matrix by the matrix
Mon the right if the multiplication is valid and throws an
Matrix multiplication is valid only if the number of columns of the first matrix is the same as the number of rows of the second matrix. For notational convenience, let's say that the matrix C is the matrix product A·B. The the element in row i and column j of C, Cij is the sum
Cij = ∑kAikBkj,
where k ranges between 1 and the number of columns in A. For a fuller account, come to lecture or read the appropriate
article on matrix multiplication at Wikipedia. Notice that matrix multiplication does not
commute. That is,
A.multiply(B) does not necessarily give the same matrix as
Matrix transpose(). Returns a Matrix whose i, j-th element is the same as the j, i-th element of the current matrix. Transposition swaps elements in corresponding positions across the diagonal of a matrix. With
A.transpose()should return the matrix shown below.
Matrix identity(int n). Returns an
nmatrix whose diagonal elements are 1 and whose off-diagonal elements are 0.
Matrix random(int m, int n). Returns an
nmatrix whose entries are random numbers between 0 and 1.
double trace(). Returns the sum of the diagonal elements of the current matrix. For example,
A.trace()should return the value 18 (1+9+8), while
B.trace()evaluates to 6 (1+2+3).
double toArray(). Returns the current matrix represented as a two-dimensional array.
Be sure to comment your code fully and prefix your
Matrix class file with comments that include your name, course title, date, and the project number and title. For example:
// Joshua Reyes
// CSIT 114
// 12 November 2007
// Project 5: ADT Matrix
memo.txt. (Do not use an editor like MS Word.) Remember that your analysis counts for the majority of your grade. Please write in clear, proper English. As above, be sure to include your name, class, and project title.
Here are some questions to keep in mind:
If you worked with others, explain what each person contributed to your project. Cite others appropriately. Even if you worked with others, the code you pass in ought to be your own.
Use a secure FTP client to create a subdirectory of
project4. Upload your
SimplePicture.java if necessary) and
memo.txt to that directory by Tuesday, 16 October 2007.
Please make sure that your file names are spelled correctly. It is
frustrating for me to have to search for your files by hand.
|Requirement||Advanced||Proficient||Needs Improvement||Maximum Points|
|Comments and Coding Style||Well commented. Code conforms to naming and style conventions.||Mostly commented. Code mostly conforms to naming and style conventions.||Few or no comments. Code does not conform to conventions.||25|
|Compiles||Compiles without error.||Compiles without error.||Does not compile.||6|
||Is named correctly, renders four image processing filters, at least two of which are listed above, and calls at least four helper method.||Is named correctly, renders four image processing filters, and calls at least four helper methods.||Is neither named correctly, renders less than four processing filters, and calls fewer than four helper methods.||14|
|Code Structure||Modular design: most repeated patterns in code are stored in individual helper methods or executed using loop constructs.||Semi-modular design: Blocks of code that perform a different tasks are logically and physically separated.||There is heavy evidence of copying and pasting throughout the code.||20|
|Analysis||Provides clear and complete exposition of the design and implementation process; addresses all or most of the questions above.||Provides a mostly clear and nearly complete exposition of the design and implementation process.||Provides an unclear and incomplete exposition of the design and implementation process.||35|
|Grammar and Style||Well written. No obvious grammar or punctuation errors. A pleasure to read.||A few grammatical errors such as punctuation or spelling, although most errors do not interfere with the overall message or the substance of the text.||Many grammatical errors including punctuation, spelling or usage problems.||15|
|Organization||Written work is neat and well organized.||Written work mostly organized.||Written work messy and disorganized.||10|