double
s in a rectangular 2D array, and it is used alongside Vector
in numerical computations. Implementing classes decides on the actual storage. Use numRows
and numColumns
to get the basic size of a matrix. get(int,int)
gets an element, and there are corresponding set(int,int,double)
and add(int,int,double)
methods as well. Note that matrix indices are zero-based (typical for Java and C). This means that the row-indices range from 0 to numRows-1
, likewise for the columns. It is legal to have numRows
or numColumns
equal zero.
Other basic operations are zero
which zeros all the entries of the matrix, which can be cheaper than either zeroing the matrix manually, or creating a new matrix, and the operation copy
which creates a deep copy of the matrix. This copy has separate storage, but starts with the same contents as the current matrix.
The matrix interface extends Iterable
, and the iterator returns a MatrixEntry
which contains current index and entry value. Note that the iterator may skip non-zero entries. Using an iterator, many simple and efficient algorithms can be created. The iterator also permits changing values in the matrix, however only non-zero entries can be changed.
A large selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.
The operations available include:
|
|
|
|