|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.dyndns.kwitte.jfunction.Terms
public final class Terms
A class to evaluate Terms.
[expr] -- [term] [term_tail]unsigned_float is a positive float value as specified in the grammar of the Java language specification. e is the empty word. The meaning of the unary operators is the same as in the corresponding method of
[term_tail] -- [add_op] [term] [term_tail] | e
[term] -- [factor] [factor_tail]
[factor] -- [power] [power_tail]
[power_tail] -- ^ [power] [power_tail] | e
[factor_tail] -- [mult_op] [factor] [factor_tail] | e
[power] -- ( expr ) | [unary_operator] [power] | x | unsigned_float
[add_op] -- + | -
[mult_op] -- * | /
[unary_operator] -> abs | acos | add | asin | atan | ceil | cos | cosh | exp | floor | ln | round | signum | sin | sinh | sqrt | tan | tanh
java.lang.Math, except that sin, cos and tan take
degrees. ln is like the log method in
java.lang.Math.
Additionally, a ";" can be used to mark everything that is right of the term as comment. Whitespace is ignored, just newline characters are not allowed within a term.
| Method Summary | |
|---|---|
static Term |
compile(java.lang.String term)
Creates a Term. |
static double |
evaluate(java.lang.String term)
Evaluates a term. |
static double |
evaluate(java.lang.String term,
double value)
Evaluates a term. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Term compile(java.lang.String term)
throws FunctionFormatException
Term. Use this method if you have to evaluate the
same term frequently (for different x-values). Use
evaluate(String, double) or
evaluate(String) otherwise.
Example:
Create a value table for the function f(x) = sin(3*x)+2
Pre-compile once to increase performance. This is a lot faster than calling Terms.evaluate("sin(3*x)+2") 20000 times inside the loop.
Term myTerm = Terms.compile("sin(3*x)+2");
for (double d = -1000.0; d < 1000.0; d+=0.1) {
double result = myTerm.evaluate(d);
System.out.println(d + "\t" + result);
}
term - the term to be compiled. For the grammar see
class documentation
Term, ready for fast evaluation for
different x-values
FunctionFormatException - iff the argument
is not an element of the language specified in the class documentation
public static double evaluate(java.lang.String term,
double value)
throws FunctionFormatException
Example:
System.out.println(Terms.evaluate("2*x", 12)); // prints 24
term - the term to be evaluated. For the grammar see
class documentation
FunctionFormatException - iff the argument
is not an element of the language specified in the class documentation
public static double evaluate(java.lang.String term)
throws FunctionFormatException
Example:
System.out.println(Terms.evaluate("3+4")); // prints 7
term - the term to be evaluated. For the grammar see
class documentation
FunctionFormatException - iff the argument
is not an element of the language specified in the class documentation
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||