Class Function<X,Y>
- All Implemented Interfaces:
Serializable
,javolution.lang.Realtime
- Direct Known Subclasses:
DiscreteFunction
,Polynomial
,RationalFunction
This abstract class represents a mapping between two sets such that there is a unique element in the second set assigned to each element in the first set.
Functions can be discrete or continuous and multivariate functions
(functions with multiple variables) are also supported as illustrated
below:[code]
// Defines local variables.
Variable.Local
Functions are often given by formula (e.g. f(x) = x²-x+1,
f(x,y)= x·y
) but the general function instance might tabulate
the values, solve an equation, etc.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the composition of this function with the one specified.differentiate
(Variable<X> v) Returns the first derivative of this function with respect to the specified variable.Returns the quotient of this function with the one specified.boolean
Indicates if this function is equals to the specified object.abstract Y
evaluate()
Evaluates this function using itsvariables
current values.final Y
Evaluates this function for the specified argument value (convenience method).final Y
Evaluates this function for the specified arguments values (convenience method).getVariable
(String symbol) Retrieves the variable from this function having the specified symbol (convenience method).Returns a lexically ordered list of the variables (or arguments) for this function (empty list for constant functions).int
hashCode()
Returns the hash code for this function (consistent withequals(Object)
.Returns an integral of this function with respect to the specified variable.Returns the difference of this function with the one specified.Returns the sum of this function with the one specified.pow
(int n) Returns this function raised at the specified exponent.Returns the product of this function with the one specified.final String
toString()
Returns the text representation of this function as ajava.lang.String
.abstract javolution.text.Text
toText()
Returns the textual representation of this real-time object (equivalent totoString
except that the returned value can be allocated from the local context space).
-
Constructor Details
-
Function
protected Function()Default constructor.
-
-
Method Details
-
getVariables
Returns a lexically ordered list of the variables (or arguments) for this function (empty list for constant functions).- Returns:
- this function current unset variables (sorted).
-
evaluate
Evaluates this function using itsvariables
current values.- Returns:
- the evaluation of this function.
- Throws:
FunctionException
- if any of this function's variable is not set.
-
equals
Indicates if this function is equals to the specified object. -
hashCode
public int hashCode()Returns the hash code for this function (consistent withequals(Object)
. -
getVariable
Retrieves the variable from this function having the specified symbol (convenience method).- Returns:
- the variable having the specified symbol or
null
if none.
-
evaluate
Evaluates this function for the specified argument value (convenience method). The evaluation is performed in aLocalContext
and can safely be called upon functions withglobal variables
.- Parameters:
arg
- the single variable value used for the evaluation.- Returns:
- the evaluation of this function.
- Throws:
FunctionException
- ifgetVariables().size() != 1
-
evaluate
Evaluates this function for the specified arguments values (convenience method). The evaluation is performed in aLocalContext
and can safely be called upon functions withglobal variables
.- Parameters:
args
- the variables values used for the evaluation.- Returns:
- the evaluation of this function.
- Throws:
IllegalArgumentException
- ifargs.length != getVariables().size())
-
compose
Returns the composition of this function with the one specified.- Parameters:
that
- the function for which the return value is passed as argument to this function.- Returns:
- the function
(this o that)
- Throws:
FunctionException
- if this function is not monovariate.
-
differentiate
Returns the first derivative of this function with respect to the specified variable.- Parameters:
v
- the variable for which the derivative is calculated.- Returns:
d[this]/dv
- Throws:
FunctionException
- if the derivative is undefined.- See Also:
-
integrate
Returns an integral of this function with respect to the specified variable.- Parameters:
v
- the variable for which the integral is calculated.- Returns:
S[this·dv]
- See Also:
-
plus
Returns the sum of this function with the one specified.- Parameters:
that
- the function to be added.- Returns:
this + that
.
-
minus
Returns the difference of this function with the one specified.- Parameters:
that
- the function to be subtracted.- Returns:
this - that
.
-
times
Returns the product of this function with the one specified.- Parameters:
that
- the function multiplier.- Returns:
this · that
.
-
divide
Returns the quotient of this function with the one specified. Evaluation of this function may raise an exception if the function result is not a {- Parameters:
that
- the function divisor.- Returns:
this / that
.
-
pow
Returns this function raised at the specified exponent.- Parameters:
n
- the exponent.- Returns:
thisn
- Throws:
IllegalArgumentException
- ifn <= 0
-
toText
public abstract javolution.text.Text toText()Returns the textual representation of this real-time object (equivalent totoString
except that the returned value can be allocated from the local context space).- Specified by:
toText
in interfacejavolution.lang.Realtime
- Returns:
- this object's textual representation.
-
toString
Returns the text representation of this function as ajava.lang.String
.
-