Quickstart

Maven project

Add innoSoft repository in your project's POM

<repositories>
        <repository>
                <id>innoSoft Repository</id>
                <url>http://repository.innosoft.pl/maven2/</url>
        </repository>
</repositories>

Add MathJ dependency to your project

<dependency>
        <groupId>innosoft</groupId>
        <artifactId>mathj</artifactId>
        <version>0.7</version>
</dependency>

Now you can start using MathJ

import pl.innosoft.mathj.Expression;
import pl.innosoft.mathj.SimpleExpression;
import pl.innosoft.mathj.Solver;

public class MathJExample {

        public static void main(String[] args) throws Exception {
                Solver solver = new Solver();
                Expression exp = new SimpleExpression("1.2345 + 43 + -23.4 + 7");
                
                System.out.println("My first MathJ calculation: " + solver.solve(exp));
        }
        
}

Console output should looks like below

My first MathJ calculation: 27.8345

Or you can parametrize your expression

public class MathJExample {

        public static void main(String[] args) throws Exception {
                Solver solver = new Solver();
                ParametrizedExpression pex = new ParametrizedExpression();
                pex.setBody("2 + {x}");
                
                pex.setParameter("x", new Double(2));
                System.out.println("MathJ calculation: " + solver.solve(pex));
                
                pex.setParameter("x", new Double (-3));
                System.out.println("MathJ calculation: " + solver.solve(pex));
        }
        
}

And watch the console

MathJ calculation: 4.0
MathJ calculation: -1.0

And it's just the tip of the iceberg. More examples and features - coming soon.

Additional info

  • author: Arkadiusz Labus