public class Expression
extends java.lang.Object
Supported operators:
Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh, exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh, sqrt, tan, tanh and more. (See the Functions class or the wiki)
Constants: e, pi
To compile an equation, run
Expression.compile("expression here", "var1", "var2"...)
.
If you wish to run the equation multiple times, you can then optimize it,
by calling optimize()
. You can then run the equation as many times
as you want by calling evaluate(double...)
. You do not need to
pass values for all variables specified while compiling.
To query variables after evaluation, you can use
getVariable(String, boolean)
. To get a value out of these, use
Variable.getValue()
.
Variables are also supported and can be set either by passing values
to evaluate(double...)
.
Modifier and Type | Method and Description |
---|---|
static Expression |
compile(java.lang.String expression,
java.lang.String... variableNames) |
double |
evaluate(double... values) |
ExpressionEnvironment |
getEnvironment() |
Functions |
getFunctions() |
static Expression |
getInstance() |
RValue |
getVariable(java.lang.String name,
boolean create) |
void |
optimize() |
void |
setEnvironment(ExpressionEnvironment environment) |
java.lang.String |
toString() |
public static Expression compile(java.lang.String expression, java.lang.String... variableNames) throws ExpressionException
ExpressionException
public double evaluate(double... values) throws EvaluationException
EvaluationException
public void optimize() throws EvaluationException
EvaluationException
public java.lang.String toString()
toString
in class java.lang.Object
public RValue getVariable(java.lang.String name, boolean create)
public static Expression getInstance()
public Functions getFunctions()
public ExpressionEnvironment getEnvironment()
public void setEnvironment(ExpressionEnvironment environment)