Hi there! Jatrix is a new library for performing different operations with matrices. There are some operations with matrices: summation, subtraction, multiplying, trasposition, inversion, solving a system of linear equations, decompostitions, etc. The library is focused on performance and simplicity. In the benchmarking package you find benchmarks of some solutions.
There are some features of Jatrix library:
- A straightforward API.
- Strassen multiplying (more faster than default matrix product, you can see the result of comparison at samples directory of the matrix multiplications).
- Comfortable output methods. Printing out to .md, .txt and .html files in a pretty form.
- A vast numbers of methods for enjoyable development.
To download the library you need to use the following dependencies:
- Apache Maven:
<dependency>
<groupId>com.github.danilos1</groupId>
<artifactId>jatrix</artifactId>
<version>0.1</version>
</dependency>
- Gradle Groovy DSL:
implementation 'com.github.danilos1:jatrix:0.1'
The Jatrix API
is consisted of the following sections:
core
section is basic package, stores main classes of the library such asMatrix
,Matrices
,MatrixIterator
etc.
For instance, let's initialize some matrix and perform matrix product:
Matrix a = new Matrix(new double[][]{
{ 1, 7, 3},
{-5, 0, 9}
});
Matrix b = new Matrix(new double[][]{
{8, 10},
{3,-12},
{1, -7},
});
Matrix result = Matrices.mul(a, b);
System.out.println(result.prettyOut());
exceptions
section includes exceptions of the library.- In
solvers
section you'll find tools for solving linear equations.
To demonstrate one of solvers, let's solve the following system of linear equation:
{ -5x1 + 3x2 - x3 = 1
{ 8x2 + 2x3 = -5
{ 12x1 + 7x2 - 6*x3 = 6
Matrix coefficients = new Matrix(new double[][]{
{ -5, 3, -1 },
{ 0, 8, 2 },
{ 12, 7, -6 },
});
double[] b = {1, -5, 6};
CramerSolver solver = new CramerSolver(coefficients, b);
System.out.println(solver);
decompositions
section is used for decomposing some matrix (See Matrix decomposition)
For example, let's decompose the matrix above:
Matrix a = new Matrix(new double[][]{
{ -5, 3, -1 },
{ 0, 8, 2 },
{ 12, 7, -6 },
});
LUDecomposition lu = new LUDecomposition(a);
System.out.println(lu.getL());
System.out.println(lu.getU());
System.out.println(lu.det());
conversion
block is used for changing a matrix somewise (swap matrix rows or columns, etc)- To find out some statistics such as maximum or minimum by row or column you can use
statistics
section. printer
block is used for printing out a matrix into a .txt, .md or .html files. E.g. let's print out a random matrix to html file:AndMatrix a = new Matrix(new double[][]{ { -5, 3, -1 }, { 0, 8, 2 }, { 12, 7, -6 }, }); MatrixPrinter printer = new MatrixPrinter(a); try { a.saveAsHtml(new File(C://...matrix.html)); } catch (FileNotFoundException e) { e.printStackTrace(); }
matrix.html
looks as the following page:
For detail information you should go to the Documentation page.
All Jatrix API
is stored in JavaDoc.
Jatrix code is under MIT License