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:
A11 A12 A13
A21 A22 A23
A31 A32 A33
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:
A11*(A22*A33 - A23*A32)
- A21*(A12*A33 - A13*A32)
+ A31*(A12*A23 - A13*A22)
The method determinant() must count how many times it has been invoked.
This is how you multiply two 3x3 matrices A and B:
|A11 A12 A13|
A = |A21 A22 A23|
|A31 A32 A33|
|B11 B12 B13|
B = |B21 B22 B23|
|B31 B32 B33|
|C11 C12 C13|
C = A*B = |C21 C22 C23|
|C31 C32 C33|
Cij = Ai1*B1j + Ai2*B2j + Ai3*B3j (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...
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