Expression4j Expression4J

Sample > Simple expression

About
Documentation
Sample
    Simple expression
    Agregated expression
    Predefined function
    User define function
    Custom element
    Custom operator
    External configuration
Download

Create an expression

An expression is constitued by :
  •  function name (like f or foo or function)
  • parameters (like x or y or foo)
  • equal sign (=)
  • the body of the expression (like 2+3*x or 3.5e-2+4)
Expression does not support space. If spaces are present in the expression, the parsin will generate an error.

My first expression with expression4j

The next example create a simple expression with no parameter

2: try {
3: Expression expression = ExpressionFactory.createExpression("f()=2.4e-2");
4: System.out.println("Expression name: " + expression.getName());
5: System.out.println("Value of expression:" + expression.evaluate(null)
.getRealValue())
6: }
7: catch (Exception e) {
8: System.out.println("Error: " + e);
9: }

Line 3 define the expression "f". This expression has no parameter and is equal to the constant 2.4e-2.
Line 4 display the name of the expression after the parsing. This line must display the result:
Expression name: f

Line 5 evaluate the expression and display the résult. The result must be:
Value of expression:0.024
SourceForge.net Logo Support This Project