|
Project Information
Links
|
Latest available release: la4j-0.2.0.zip (api + src) (Nov 2011); News14 Nov 2011I've just published awesome article about la4j at CodeProject.com. Enjoy reading! 13 Nov 2011Hey! la4j-0.2.0 just released. Here is changelog:
9 Sep 2011I've just started new blog of project - la4j development. I am planing write there some technical staff about implementation details. 26 Jan 2011I am working on integration la4j into jmatbench project. Linear Algebra for Java (la4j)la4j (Linear Algebra for Java) - is a elegant and pure Java library for solving problems of linear algebra. It is support sparse and dense matrices and vectors. la4j - is a try to design nice object oriented implementation of linear math library. Features
List of projects uses la4jHere could be Your project :) Use issue 12 for submitting. DownloadsYou can download latest version of la4j from here:
ContributionYou can contribute to la4j by following:
Code samplesSee jUnit tests package for more examples. Factories
Factory denseFactory = new DenseFactory();
Factory sparseFactory = new SparseFactory();
double array[][] = new double[][] {
{1.0, 0.0, 0.0},
{0.0, 5.0, 0.0},
{0.0, 0.0, 9.0}
};
Matrix a = sparseFactory.createMatrix(array);
Matrix b = denseFactory.createMatrix(array);
Matrix c = a.copy(denseFactory); // convert sparse to dense
Matrix d = b.copy(sparseFactory); // convert dense to sparse
Basic operationsMatrix a = sparseFactory.createMatrix(array); Matrix b = denseFactory.createMatrix(array); Matrix c = a.multiply(b); // c - is sparse matrix Matrix d = a.multiply(b, denseFactory); // d - is dense matrix Matrix e = c.add(d).subtract(a).multiply(100); // c + d - a * 100 Transposing and traceMatrix a = sparseFactory.createMatrix(array); Matrix b = denseFactory.createMatrix(array); double trace = a.trace(); Matrix c = a.transpose(); // c - is sparse matrix Matrix d = a.transpose(denseFactory); // d - is dense matrix Rows and columnsMatrix a = sparseFactory.createMatrix(array); int rows = a.rows(); int columns = a.columns(); a.setColumns(columns + 1); // set number of columns a.setRows(rows + 1); // set number of rows b.resize(rows + 1, columns + 1); // resize matrix a.swapColumns(0, columns - 1); // swap columns a.swapRows(0, rows - 1); // swap rows Vector row = a.getRow(0); // row - is sparse vector Vector column = a.getColumn(0); // column is sparse vector Triangles matricesMatrix a = denseFactory.createMatrix(array); boolean check = a.isTrianle(); // true if a - is triangle matrix Matrix b = a.triangularize(); // b - is triangle dense matrix Matrix c = a.triangularize(sparseFactory); // c - is triangle sparse matrix Solving linear systemsMatrix a = denseFactory.createMatrix(array); Vector b = sparseFactory.createVector(array[0]); LinearSystem system = new LinearSystem(a, b); Vector x = system.solve(new GaussianSolver()); // x - is dense vector Vector y = system.solve(new SquareRootSolver(), sparseFactory); // y - is sparse vector Matrix inversionMatrix a = denseFactory.createMatrix(array); Matrix b = a.inverse(new GaussianInvertor()); // b - is dense matrix Matrix c = a.inverse(new GaussianInvertor(), sparseFactory); // c - is sparse matrix Matrix decompositionMatrix a = denseFactory.createMatrix(array); Matrix[] qr = a.decompose(new QRDecompositor()); // qr[0] = Q, qr[1] = R; Q,R - dense matrices Matrix[] lu = a.decompose(new LUDecompositor(), sparseFactory); // lu[0] = L, lu[1] = U; L,U - sparse matrices Input/Output
Matrix a = denseFactory.createMatrix(array);
ObjectOutput mmos = new MMOutputStream(new FileOutputStream("file.mm"));
mmos.writeObject(a);
mmos.close();
ObjectInput mmis = new MMInputStream(new FileInputStream("file.mm"));
Matrix b = (Matrix) mmis.readObject();
mis.close();
|