[back] [home] [content] [continue]
It's possible to use all important mathematical constants and
function-calls within any expression.
Use the following notations in your expression-strings:
Notations of constants | Description | value type |
---|---|---|
pi | Archimedes' constant pi=3.141592653589793... | real |
e | exponentiation constant e=2.718281828459045... | real |
i | i=sqrt(-1) | complex |
Notations of functions | ||
sin | trigonometric sine function | |
cos | trigonometric cosine function | |
exp | exponential function | |
log | natural logarithm | |
sqrt | square root |
Note:
Examples:
ExpressionConfiguration config=new ExpressionConfiguration(RealType.TYPE); //example 1: config.setExpression("sin(2*pi)"); Real r=(Real)config.evaluateExpression(); //example 2: config.setExpression("log(E)"); r=(Real)config.evaluateExpression(); //example 3: default type is real -> "i" is just a definable variable config.defineVariable("i", new Real(2), RealType.TYPE); //see next chapter for more information how to define variables config.setExpression("2i"); r=(Real)config.evaluateExpression(); //result: 4.0 //example 4: change the default type to complex config.setType(ComplexType.TYPE); //the expression is still the same ("2i") Complex c=(Complex)config.evaluateExpression(); //result: 0.0+2.0i