File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ Brief Examples
23
23
--------------
24
24
** Matrix inversion**
25
25
``` java
26
+ // We want simple dense matrix that uses 2D array as internal representation
26
27
Matrix a = new Basic2DMatrix (new double [][] {
27
28
{ 1.0 , 2.0 , 3.0 },
28
29
{ 4.0 , 5.0 , 6.0 },
@@ -36,27 +37,28 @@ Matrix b = inverter.invert(LinearAlgebra.DENSE_FACTORY);
36
37
```
37
38
** System of linear equations**
38
39
``` java
39
- // A coefficient matrix
40
- Matrix a = new Basic2DMatrix (new double [][] {
40
+ // The coefficient matrix 'a' is a CRS (Compressed Sparse Row) matrix
41
+ Matrix a = new CRSMatrix (new double [][] {
41
42
{ 1.0 , 2.0 , 3.0 },
42
43
{ 4.0 , 5.0 , 6.0 },
43
44
{ 7.0 , 8.0 . 9.0 }
44
45
});
45
46
46
- // A right hand side vector
47
+ // A right hand side vector, which is simple dense vector
47
48
Vector b = new BasicVector (new double [] {
48
- { 1.0 , 2.0 , 3.0 }
49
+ 1.0 , 2.0 , 3.0
49
50
});
50
51
51
52
// We will use standard Forward-Back Substitution method,
52
53
// which is based on LU decomposition and can be used with square systems
53
54
LinearSystemSolver solver = a. withSolver(LinearAlgebra . FORWARD_BACK_SUBSTITUTION );
54
- // The 'x' vector will be dense
55
- Vector x = solver. solve(b, LinearAlgebra . DENSE_FACTORY );
55
+ // The 'x' vector will be sparse
56
+ Vector x = solver. solve(b, LinearAlgebra . SPARSE_FACTORY );
56
57
```
57
58
** Matrix decomposition**
58
59
``` java
59
- Matrix a = new Basic2DMatrix (new double [][] {
60
+ // We want simple dense matrix, which is based on 1D double's array
61
+ Matrix a = new Basic1DMatrix (new double [][] {
60
62
{ 1.0 , 2.0 , 3.0 },
61
63
{ 4.0 , 5.0 , 6.0 },
62
64
{ 7.0 , 8.0 . 9.0 }
You can’t perform that action at this time.
0 commit comments