Class JELFunction
java.lang.Object
uk.ac.starlink.ttools.jel.JELFunction
- All Implemented Interfaces:
DoubleUnaryOperator
Provides a double precision function of one double precision
variable which can be evaluated using JEL.
The variable name and an expression giving the result in terms of that
variable name are supplied.
Instances of this class are not threadsafe, but could be made so
by putting a lock on the evaluate(double) method.
- Since:
- 14 Jun 2012
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionJELFunction(String xvarname, String fexpr) Constructs a function with no external constants.Constructs a function that can reference provided constants. -
Method Summary
Modifier and TypeMethodDescriptiondoubleapplyAsDouble(double x) Does exactly the same asevaluate(double).doubleevaluate(double x) Evaluates this function at a given value of the independent variable.Returns the text of the function expression.Constant<?>[]Returns an array of any constants that were referenced in this function's expression.Returns the name of the independent variable.static voidMain method tests this class.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DoubleUnaryOperator
andThen, compose
-
Constructor Details
-
JELFunction
Constructs a function with no external constants.- Parameters:
xvarname- name of the independent variable (for instance "x")fexpr- text of expression giving the function value, in terms ofxvarname(for instance "x+1")- Throws:
gnu.jel.CompilationException
-
JELFunction
public JELFunction(String xvarname, String fexpr, Map<String, ? extends Constant<?>> constMap) throws gnu.jel.CompilationException Constructs a function that can reference provided constants.- Parameters:
xvarname- name of the independent variable (for instance "x")fexpr- text of expression giving the function value, in terms ofxvarname(for instance "x+1")constMap- map by name of constant values that can be referenced in the expression, may be null- Throws:
gnu.jel.CompilationException
-
-
Method Details
-
getReferencedConstants
Returns an array of any constants that were referenced in this function's expression. This list does not include an entry for the X value expression.- Returns:
- constants from the map supplied at construction time that are referenced in this function's expression
-
evaluate
public double evaluate(double x) Evaluates this function at a given value of the independent variable. In case of an evaluation error of some kind, NaN is returned.- Parameters:
x- variable value- Returns:
- function value
-
applyAsDouble
public double applyAsDouble(double x) Does exactly the same asevaluate(double).- Specified by:
applyAsDoublein interfaceDoubleUnaryOperator
-
getXVarName
-
getExpression
Returns the text of the function expression.- Returns:
- function expression
-
main
Main method tests this class. Args are varname, expr, varvalue, for instance "x", "3x+1", "29"
-