You can also get the files using the command:
cp /home/cheung/teaching/web/170/Projects/hw7/Handouts/* ~/cs170/hw7
In the remainder of the homework description, I will assume that you have saved these file in your ~/cs170/hw7 directory.
In this assignment, we will write a Matrix class that you can use to represent 3 x 3 matrices.
The following is how each element is number in a 3x3 matrix:
A_{11} A_{12} A_{13} A_{21} A_{22} A_{23} A_{31} A_{32} A_{33}
The first 3 values is the values in the first row of the matrix.
The second set of 3 values is the values in the second row of the matrix.
And the third set of 3 values is the values in the third row of the matrix.
The representation must use a two-dimensional array of doubles - and the size of the array is 3x3. (Look inside the file Matrix.java - I have already defined the array variable; you need to initialize it !).
The determinant of a 3x3 matrix can be computed as follows:
A_{11}*(A_{22}*A_{33} - A_{23}*A_{32}) - A_{21}*(A_{12}*A_{33} - A_{13}*A_{32}) + A_{31}*(A_{12}*A_{23} - A_{13}*A_{22})
The method determinant() must count how many times it has been invoked.
This is how you multiply two 3x3 matrices A and B:
+- -+ |A_{11} A_{12} A_{13}| A = |A_{21} A_{22} A_{23}| |A_{31} A_{32} A_{33}| +- -+
+- -+ |B_{11} B_{12} B_{13}| B = |B_{21} B_{22} B_{23}| |B_{31} B_{32} B_{33}| +- -+
Then:
+- -+ |C_{11} C_{12} C_{13}| C = A*B = |C_{21} C_{22} C_{23}| |C_{31} C_{32} C_{33}| +- -+ where: C_{ij} = A_{i1}*B_{1j} + A_{i2}*B_{2j} + A_{i3}*B_{3j} (for i = 1, 2, 3 and j = 1, 2, 3)
Some programming help in writing multiply()
Here's how the multiply() method will look like:
public Matrix multiply(Matrix m) { Matrix Result = Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0); ... compute Result = this matrix multiple with Matrix m... return(Result); }
Determinant of A = 1.0 getCountDet() = 1.0 Determinant of B = -3.0 getCountDet() = 2.0 Determinant of C = 1.0 getCountDet() = 3.0 ++ getCountMult() = 1.0 Determinant of R = -3.0 getCountDet() = 4.0 ++ getCountMult() = 2.0 Determinant of R = 1.0 getCountDet() = 5.0 ++ getCountMult() = 3.0 Determinant of R = -3.0 getCountDet() = 6.0
/home/cs170001/turnin ~/cs170/hw7/Matrix.java hw7