|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object assignments.a05.Matrix
public class Matrix
The Matrix class represents a 2D matrix.
Field Summary | |
---|---|
private ArrayList<ArrayList<Double>> |
matrix
The instance variable that stores the matrix data |
Constructor Summary | |
---|---|
Matrix(int rows,
int columns)
Creates a new matrix with the specified number of rows and columns and zeroes in every cell. |
Method Summary | |
---|---|
double |
get(int i,
int j)
Gets the value of the element at row i and column j. |
int |
getColumns()
Returns the number of columns in this matrix. |
int |
getRows()
Returns the number of rows in this matrix. |
Matrix |
multiply(Matrix right)
Multiplies this matrix by the matrix stored in 'right'. |
void |
set(int i,
int j,
double value)
Sets the value of the element at row i and column j. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private ArrayList<ArrayList<Double>> matrix
Constructor Detail |
---|
public Matrix(int rows, int columns)
rows
- The number of rows in this matrixcolumns
- The number of columns in this matrix
IllegalArgumentException
- if the number of rows or columns is not positiveMethod Detail |
---|
public int getRows()
public int getColumns()
public double get(int i, int j)
i
- The row numberj
- The column number
public void set(int i, int j, double value)
i
- The row numberj
- The column numbervalue
- The value to set the element at row i and column j topublic Matrix multiply(Matrix right)
[ r00 r01 ] [ a00 a01 a02 ] [ b00 b01 ] [ r10 r11 ] = [ a10 a11 a12 ] x [ b10 b11 ] [ b20 b21 ] = [ (a00xb00 + a01xb10 + a02xb20) (a00xb01 + a01xb11 + a02xb21) ] [ (a10xb00 + a11xb10 + a12xb20) (a10xb01 + a11xb11 + a12xb21) ]
right
- the matrix to multiply this matrix by
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |