Database Reference
In-Depth Information
speaking, it represents BLAS levels 2 and 3 (matrix operations) plus main
LAPACK functionality (especially decompositions). Thus, we included JAMA
into the Algebra package and extended the Matrix class for further requirements.
Example 12.10 We consider two matrices A and Bw hich are defined as follows:
, B ¼
14
3
12 3
001
A ¼
:
5
Now we demonstrate the generation and operations on A and B .
// Create A and B:
Matrix A ¼ new Matrix( new doubl [ ][] {{1.,4.},{3.,-5.}} );
Matrix B ¼ new Matrix( new doubl [ ][] {{1.,2.,-3},{0.,0.,1.}} );
// Transpose B. BT ¼ B^T:
Matrix BT ¼ B.transpose();
// Scalar multiplication. A2 ¼ 2*A:
Matrix A2 ¼ A.times(2);
// Matrix multiplication. C ¼ A*B:
Matrix C ¼ A.times(B);
// Matrix addition. D ¼ B+C:
Matrix D ¼ B.plus(C);
// Frobenius norm:
double nF ¼ A.normF();
// Concatination of operations. E ¼ (B + 2*A*B + C)^T:
Matrix E ¼ B.plus( A.times(B).times(2) ).plus(C).trans-
pose();
Since JAMA only supports dense matrices, it was extended for sparse matrices.
Therefore, the abstract class SparseMatrix was designed, and a number of
implementations of this class had been added. The corresponding class diagram is
depicted in Fig. 12.12 .
The different implementations of SparseMatrix use different storage techniques
and are optimized for different applications.
So the classes SparseMatrixCompRow and SparseMatrixCompRowStatic are
based on the format Compressed Row Storage ( CRS ). Here all nonzero elements
(NZE) are stored in one array, and a second array contains the corresponding
column indexes, while a third array contains the pointers to the rows. The CRS
format is especially suited for fast matrix-vector multiplications. At the same time,
it is relatively static because inserting and deleting of NZEs in general require all
arrays to be reordered.
Search WWH ::




Custom Search