Support of this website is discontinued.
Each sub project is now supported on its own Google Code page:






Introduction

What JMathTools IS

JMathTools is a collection of independent packages designed to fit common engineering/scientific computing needs. For now, JMathTools contains:

  • JMathArray: simple linear algebra for double[][] arrays using static methods
  • JMathPlot: interactive plot in 2D / 3D
  • JMathIO: binary and ASCII input/output for double arrays

JMathTools is designed to be:

  • easy to integrate in your java applications
  • easy to extend and modify

It was initially developed to provide easy to use java API in Matlab to Java porting task.

What JMathTools IS NOT

JMathTools was NOT designed to be:

  • a high performance computing engine
  • a high performance 3D visualization tool

For such things, many free Java packages are available (see Links).

JMathArray: use double[][] arrays for linear algebra

Provides a list of static methods applicable on int and double arrays:

import static org.math.array.LinearAlgebra.*;
...
  // random 4 x 4 matrix + Id
  double[][] A = plus(random(4, 4), identity(4));
		
  // Eigen values Decomposition : A = V * D * V^-1
  EigenvalueDecomposition eig = eigen(A);
  double[][] V = eig.getV();
  double[][] D = eig.getD();

JMathArray syntax is stable. Only new features may be added, and current syntax will stay available.

Tutorial

JMathPlot: interactive 2D and 3D plots

Provides :

  • 2D/3D scatter plot
  • 2D/3D line plot
  • 2D staircase plot
  • 2D/3D histogram plot
  • 2D/3D boxplot
  • 3D grid plot
  • 2D/3D quantiles on plots
import org.math.plot.*;
...
  
  double[] x = ...
  double[] y = ...
 
  // create your PlotPanel (you can use it as a JPanel)
  Plot2DPanel plot = new Plot2DPanel();
 
  // add a line plot to the PlotPanel
  plot.addLinePlot("my plot", x, y);
 
  // put the PlotPanel in a JFrame, as a JPanel
  JFrame frame = new JFrame("a plot panel");
  frame.setContentPane(plot);
  frame.setVisible(true);

JMathPlot syntax is NOT stable. As far as possible current syntax will stay available.

Tutorial

JMathIO: easy to use read/write classes for double[][] arrays

JMathIO allows to create, read, write, append your datas in:

import static org.math.io.files.ASCIIFile.*;
import static org.math.io.parser.ArrayString.*;
 
...
 
  double[][] b = { { 1.0, 2.0, 3.0, 4.0 }, { 11.0, 12.0, 13.0, 14.0 } };
  // write file in ASCII
  writeDoubleArray(new File("b.txt"), b);
  // read this file
  double[][] b_read = readDoubleArray(new File("b.txt"));

JMathIO syntax is considered stable. Only new features may be added, and current syntax will stay available.

Tutorial

GroovyLab: Groovy DSL for math engineering

GroovyLab is a full jmathtools wrapper for Groovy agile dynamic language (close to Ruby, Python and Java). It is a collection of Groovy classes to provide common math features like math enginneering languages (matlab, scilab, ...):

Basically, it allows to create scripts with matlab-like syntax for Matrices and plots:

import static org.math.array.Matrix.*
import static org.math.plot.Plot.*
 
def A = rand(10,3) 		// random Matrix of 10 rows and 3 columns
def B = fill(10,3,1.0) 	// one Matrix of 10 rows and 3 columns
def C = A + B 			// support for matrix addition with "+" or "-"
def D = A - 2.0			// support for number addition with "+" or "-"
def E = A * B			// support for matrix multiplication or division
def F = rand(3,3)	
def G = F**(-1)			// support for matrix power (with integers only)
 
println A				// display Matrix content
 
plot("A",A,"SCATTER")	// plot Matrix values as ScatterPlot
 
def M = rand(5,5) + id(5) //Eigenvalues decomposition
println "M=\n" + M
println "V=\n" + V(M)
println "D=\n" + D(M)
println "M~\n" + (V(M) * D(M) * V(M)**(-1))
 
...
def A = rand(10,3)
println A
plot("A",A,"SCATTER")
 
def B = rand(10,3)
println B
plot("B",B,"LINE")
...

Rsession: R sessions wrapping for Java

Rsession is an easy to use java class providing access to remote or local R session. The back-end engine is Rserve 0.6, locally spawned automatically if necessary.

import static org.math.R.Rsession.*;
...
 
    public static void main(String args[]) {
        Rsession s = Rsession.newLocalInstance(System.out);
 
        double[] rand=((double[]) cast(s.eval("rnorm(10)"))); //create java variable from R command
 
        ...
 
        s.set("c", Math.random()); //create R variable from java one
 
        s.save(new File("save.Rdata"), "c"); //save variables in .Rdata
        s.rm("c"); //delete variable in R environment
        s.load(new File("save.Rdata")); //load R variable from .Rdata
 
        ...
 
        s.set("df", new double[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}, "x1", "x2", "x3"); //create data frame from given vectors
        double value= (Double) (cast(s.eval("df$x1[3]"))); //access one value in data frame
 
        ...
 
        s.toJPEG(new File("plot.jpg"), 400, 400, "plot(rnorm(10))"); //create jpeg file from R graphical command (like plot)
 
        String html = s.asHTML("summary(rnorm(100))"); //format in html using R2HTML
        System.out.println(html);
 
        String txt = s.asString("summary(rnorm(100))"); //format in text
        System.out.println(txt);
 
        ...
 
        System.out.println(s.installPackage("sensitivity", true)); //install and load R package
        System.out.println(s.installPackage("wavelets", true));
 
        s.end();
    }
start.txt · Last modified: 2009/07/26 00:13 by yannrichet
Creative Commons License Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0