|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dautelle.realtime.RealtimeObject
com.dautelle.math.functions.Function
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:
// f(x, y) = x² + x·y + 1; Polynomial x = Polynomial.valueOf(Rational.ONE, Variable.X); Polynomial y = Polynomial.valueOf(Rational.ONE, Variable.Y); Constant one = Constant.valueOf(Rational.ONE); Polynomial fx_y = (Polynomial) x.pow(2).plus(x.times(y)).plus(one); System.out.println("f(x,y) = " + fx_y); // Evaluates f(1,0); LocalContext.enter(); try { Variable.X.setValue(Rational.ONE); Variable.Y.setValue(Rational.ZERO); Rational f1_0 = (Rational) fx_y.evaluate(); System.out.println("f(1,0) = " + f1_0); } finally { LocalContext.exit(); } // Calculates df(x,y)/dx Polynomial dfx_y = (Polynomial) fx_y.differentiate(Variable.X); System.out.println("df(x,y)/dx = " + dfx_y); > f(x,y) = [1/1]x² + [1/1]xy + [1/1] > f(1,0) = 2/1 > df(x,y)/dx = [2/1]x + [1/1]y
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.
Finally, Function
instances are immutable and Operable
with componentwise multiplication
(
(fg)(x) = f(x)g(x)).
Nested Class Summary | |
static class |
Function.Variable
This class represents a symbol on whose value a Function
depends. |
Nested classes inherited from class com.dautelle.realtime.RealtimeObject |
RealtimeObject.Factory |
Constructor Summary | |
protected |
Function()
Default constructor. |
Method Summary | |
java.lang.StringBuffer |
appendTo(java.lang.StringBuffer sb)
Appends the text representation of this function to the StringBuffer argument. |
Function |
compose(Function that)
Returns the composition of this function with the one specified. |
Function |
differentiate(Function.Variable v)
Returns the first derivative of this function with respect to the specified variable. |
abstract Operable |
evaluate()
Evaluates this function by replacing its variables by their current (context-local) values. |
abstract java.util.Set |
getVariables()
Returns a set containing this function variables . |
Function |
integrate(Function.Variable v)
Returns an integral of this function with respect to the specified variable. |
Operable |
opposite()
Returns the additive inverse of this object. |
Operable |
plus(Operable that)
Returns the sum of this object with the one specified. |
Function |
pow(int n)
Returns this function raised at the specified exponent. |
Operable |
reciprocal()
Returns the multiplicative inverse of this object. |
Operable |
times(Operable that)
Returns the product of this object with the one specified. |
java.lang.String |
toString()
Returns the String representation of this function. |
Methods inherited from class com.dautelle.realtime.RealtimeObject |
clone, export, isLocalObject, isPoolObject, recycle, toHeap |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Function()
Method Detail |
public abstract java.util.Set getVariables()
variables
.
public abstract Operable evaluate()
variables
by their current (context-local) values.
FunctionException
- if any of this function's variable is not set.
java.lang.ClassCastException
- if the actual value of a variable is
incompatible with this function type.public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
StringBuffer
argument.
sb
- the StringBuffer
to append.
sb
public final java.lang.String toString()
String
representation of this function.
appendTo(new StringBuffer()).toString()
public Function compose(Function that)
that
- the function for which the return value is passed as
argument to this function.
(this o that)
FunctionException
- if this function is not univariate.public Function differentiate(Function.Variable v)
v
- the variable for which the derivative is calculated.
d[this]/dv
FunctionException
- if the derivative is undefined.public Function integrate(Function.Variable v)
v
- the variable for which the integral is calculated.
S[this·dv]
public Function pow(int n)
n
- the exponent.
thisn
java.lang.IllegalArgumentException
- if n <= 0
public Operable plus(Operable that)
Operable
plus
in interface Operable
that
- the object to be added.
this + that
.public Operable opposite()
Operable
this.plus(this.opposite()) == ZERO
,
with ZERO
being the additive identity.
opposite
in interface Operable
-this
.public Operable times(Operable that)
Operable
times
in interface Operable
that
- the object multiplier.
this * that
.public Operable reciprocal()
Operable
this.times(this.reciprocal()) == ONE
,
with ONE
being the multiplicative identity.
reciprocal
in interface Operable
ONE / this
.
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |