\n\n\n\nFunction\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n\n
\n
org.jscience.mathematics.function
\n

## Class Function<X,Y>

\n
\n
\n
\n
\n
\n
• \n
\n
All Implemented Interfaces:
\n
Serializable, javolution.lang.Realtime
\n
\n
\n
Direct Known Subclasses:
\n
DiscreteFunction, Polynomial, RationalFunction
\n
\n
\n
\n
`public abstract class Function<X,Y>\nextends Object\nimplements Serializable, javolution.lang.Realtime`
\n

This abstract class represents a mapping between two sets such that\n there is a unique element in the second set assigned to each element\n in the first set.

\n \n

Functions can be discrete or continuous and multivariate functions \n (functions with multiple variables) are also supported as illustrated \n below:

``\n         // Defines local variables.\n         Variable.Local<Rational> varX = new Variable.Local<Rational>("x");\n         Variable.Local<Rational> varY = new Variable.Local<Rational>("y");\n         \n         // f(x, y) =  x\xc2\xb2 + x\xc2\xb7y + 1;\n         Polynomial<Rational> x = Polynomial.valueOf(Rational.ONE, varX);\n         Polynomial<Rational> y = Polynomial.valueOf(Rational.ONE, varY);\n         Polynomial<Rational> fx_y = x.pow(2).plus(x.times(y)).plus(Rational.ONE);\n         System.out.println("f(x,y) = " + fx_y);\n \n         // Evaluates f(1,0) \n         System.out.println("f(1,0) = " + fx_y.evaluate(Rational.ONE, Rational.ZERO));\n \n         // Calculates df(x,y)/dx\n         System.out.println("df(x,y)/dx = " + fx_y.differentiate(varX));\n          \n         > f(x,y) = [1/1]x^2 + [1/1]xy + [1/1]\n         > f(1,0) = 2/1\n         > df(x,y)/dx = [2/1]x + [1/1]y\n     ``

\n \n

Functions are often given by formula (e.g. `f(x) = x\xc2\xb2-x+1,\n f(x,y)= x\xc2\xb7y`) but the general function instance might tabulate\n the values, solve an equation, etc.

\n
\n Wikipedia: Functions (mathematics), \nSerialized Form
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Summary

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Methods
Modifier and TypeMethod and Description
`<Z> Function<Z,Y>``compose(Function<Z,X> that)`\n
Returns the composition of this function with the one specified.
\n
`Function<X,Y>``differentiate(Variable<X> v)`\n
Returns the first derivative of this function with respect to \n the specified variable.
\n
`Function<X,Y>``divide(Function<X,Y> that)`\n
Returns the quotient of this function with the one specified.
\n
`boolean``equals(Object obj)`\n
Indicates if this function is equals to the specified object.
\n
`abstract Y``evaluate()`\n
Evaluates this function using its `variables` current\n values.
\n
`Y``evaluate(X... args)`\n
Evaluates this function for the specified arguments values\n (convenience method).
\n
`Y``evaluate(X arg)`\n
Evaluates this function for the specified argument value\n (convenience method).
\n
`Variable<X>``getVariable(String symbol)`\n
Retrieves the variable from this function having the specified \n symbol (convenience method).
\n
`abstract List<Variable<X>>``getVariables()`\n
Returns a lexically ordered list of the variables (or arguments)\n for this function (empty list for constant functions).
\n
`int``hashCode()`\n
Returns the hash code for this function (consistent with \n `equals(Object)`.
\n
`Function<X,Y>``integrate(Variable<X> v)`\n
Returns an integral of this function with respect to \n the specified variable.
\n
`Function<X,Y>``minus(Function<X,Y> that)`\n
Returns the difference of this function with the one specified.
\n
`Function<X,Y>``plus(Function<X,Y> that)`\n
Returns the sum of this function with the one specified.
\n
`Function<X,Y>``pow(int n)`\n
Returns this function raised at the specified exponent.
\n
`Function<X,Y>``times(Function<X,Y> that)`\n
Returns the product of this function with the one specified.
\n
`String``toString()`\n
Returns the text representation of this function as a \n `java.lang.String`.
\n
`abstract javolution.text.Text``toText()`\n
Returns the textual representation of this real-time object\n (equivalent to `toString` except that the returned value\n can be allocated from the local context space).
\n
\n
\n
• \n\n\n

### Methods inherited from class java.lang.Object

\n`getClass, notify, notifyAll, wait, wait, wait`
• \n
\n
• \n
\n
• \n
\n
\n
\n
\n
• \n\n
\n
• \n\n\n

### Method Detail

\n\n\n\n
\n
• \n

#### getVariables

\n
`public abstract List<Variable<X>> getVariables()`
\n
Returns a lexically ordered list of the variables (or arguments)\n for this function (empty list for constant functions).
\n
Returns:
this function current unset variables (sorted).
\n
• \n
\n\n\n\n
\n
• \n

#### evaluate

\n
`public abstract Y evaluate()`
\n
Evaluates this function using its `variables` current\n values.
\n
Returns:
the evaluation of this function.
\n
Throws:
\n
`FunctionException` - if any of this function\'s variable is not set.
\n
• \n
\n\n\n\n
\n
• \n

#### equals

\n
`public boolean equals(Object obj)`
\n
Indicates if this function is equals to the specified object.
\n
\n
Overrides:
\n
`equals` in class `Object`
\n
Parameters:
`obj` - the object to be compared with.
\n
Returns:
`true` if this function and the specified argument\n represent the same function; `false` otherwise.
\n
• \n
\n\n\n\n
\n
• \n

#### hashCode

\n
`public int hashCode()`
\n
Returns the hash code for this function (consistent with \n `equals(Object)`.
\n
\n
Overrides:
\n
`hashCode` in class `Object`
\n
Returns:
this function hash code.
\n
• \n
\n\n\n\n
\n
• \n

#### getVariable

\n
`public final Variable<X> getVariable(String symbol)`
\n
Retrieves the variable from this function having the specified \n symbol (convenience method).
\n
Returns:
the variable having the specified symbol or `null`\n if none.
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### evaluate

\n
`public final Y evaluate(X arg)`
\n
Evaluates this function for the specified argument value\n (convenience method). The evaluation is performed \n in a `LocalContext` and \n can safely be called upon functions with `global\n variables`.
\n
Parameters:
`arg` - the single variable value used for the evaluation.
\n
Returns:
the evaluation of this function.
\n
Throws:
\n
`FunctionException` - if `getVariables().size() != 1`
\n
• \n
\n\n\n\n\n\n
\n
• \n

#### evaluate

\n
`public final Y evaluate(X... args)`
\n
Evaluates this function for the specified arguments values\n (convenience method). The evaluation is performed \n in a `LocalContext` and \n can safely be called upon functions with `global\n variables`.
\n
Parameters:
`args` - the variables values used for the evaluation.
\n
Returns:
the evaluation of this function.
\n
Throws:
\n
`IllegalArgumentException` - if `args.length != getVariables().size())`
\n
• \n
\n\n\n\n
\n
• \n

#### compose

\n
`public <Z> Function<Z,Y> compose(Function<Z,X> that)`
\n
Returns the composition of this function with the one specified.
\n
Parameters:
`that` - the function for which the return value is passed as\n argument to this function.
\n
Returns:
the function `(this o that)`
\n
Throws:
\n
`FunctionException` - if this function is not monovariate.
\n
• \n
\n\n\n\n
\n
• \n

#### differentiate

\n
`public Function<X,Y> differentiate(Variable<X> v)`
\n
Returns the first derivative of this function with respect to \n the specified variable.
\n
Parameters:
`v` - the variable for which the derivative is calculated.
\n
Returns:
`d[this]/dv`
\n
Throws:
\n
`FunctionException` - if the derivative is undefined.
\n Derivative -- from MathWorld
\n
• \n
\n\n\n\n
\n
• \n

#### integrate

\n
`public Function<X,Y> integrate(Variable<X> v)`
\n
Returns an integral of this function with respect to \n the specified variable.
\n
Parameters:
`v` - the variable for which the integral is calculated.
\n
Returns:
`S[this\xc2\xb7dv]`
\n Integral -- from MathWorld
\n
• \n
\n\n\n\n
\n
• \n

#### plus

\n
`public Function<X,Y> plus(Function<X,Y> that)`
\n
Returns the sum of this function with the one specified.
\n
Parameters:
`that` - the function to be added.
\n
Returns:
`this + that`.
\n
• \n
\n\n\n\n
\n
• \n

#### minus

\n
`public Function<X,Y> minus(Function<X,Y> that)`
\n
Returns the difference of this function with the one specified.
\n
Parameters:
`that` - the function to be subtracted.
\n
Returns:
`this - that`.
\n
• \n
\n\n\n\n
\n
• \n

#### times

\n
`public Function<X,Y> times(Function<X,Y> that)`
\n
Returns the product of this function with the one specified.
\n
Parameters:
`that` - the function multiplier.
\n
Returns:
`this \xc2\xb7 that`.
\n
• \n
\n\n\n\n
\n
• \n

#### divide

\n
`public Function<X,Y> divide(Function<X,Y> that)`
\n
Returns the quotient of this function with the one specified.\n Evaluation of this function may raise an exception if the \n function result is not a {
\n
Parameters:
`that` - the function divisor.
\n
Returns:
`this / that`.
\n
• \n
\n\n\n\n
\n
• \n

#### pow

\n
`public Function<X,Y> pow(int n)`
\n
Returns this function raised at the specified exponent.
\n
Parameters:
`n` - the exponent.
\n
Returns:
`thisn`
\n
Throws:
\n
`IllegalArgumentException` - if `n <= 0`
\n
• \n
\n\n\n\n
\n
• \n

#### toText

\n
`public abstract javolution.text.Text toText()`
\n
Returns the textual representation of this real-time object\n (equivalent to `toString` except that the returned value\n can be allocated from the local context space).
\n
\n
Specified by:
\n
`toText` in interface `javolution.lang.Realtime`
\n
Returns:
this object\'s textual representation.
\n
• \n
\n\n\n\n
\n
• \n

#### toString

\n
`public final String toString()`
\n
Returns the text representation of this function as a \n `java.lang.String`.
\n
\n
Overrides:
\n
`toString` in class `Object`
\n
Returns:
`toText().toString()`
\n
• \n
\n
• \n
\n
• \n
\n
\n
\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n