JADE v6.1

com.dautelle.math.functions
Class Function

java.lang.Object
  extended bycom.dautelle.realtime.RealtimeObject
      extended bycom.dautelle.math.functions.Function
All Implemented Interfaces:
Operable, Realtime, java.io.Serializable
Direct Known Subclasses:
DiscreteFunction, Polynomial, RationalFunction

public abstract class Function
extends RealtimeObject
implements Operable

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)).

Version:
6.0, March 17, 2004
Author:
Jean-Marie Dautelle
See Also:
Function -- from MathWorld, Serialized Form

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

Function

protected Function()
Default constructor.

Method Detail

getVariables

public abstract java.util.Set getVariables()
Returns a set containing this function variables.

Returns:
the variables for this function.

evaluate

public abstract Operable evaluate()
Evaluates this function by replacing its variables by their current (context-local) values.

Returns:
the evaluation of this function.
Throws:
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.

appendTo

public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb)
Appends the text representation of this function to the StringBuffer argument.

Parameters:
sb - the StringBuffer to append.
Returns:
sb

toString

public final java.lang.String toString()
Returns the String representation of this function.

Returns:
appendTo(new StringBuffer()).toString()

compose

public Function compose(Function that)
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 univariate.

differentiate

public Function differentiate(Function.Variable v)
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:
Derivative -- from MathWorld

integrate

public Function integrate(Function.Variable v)
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:
Integral -- from MathWorld

pow

public Function pow(int n)
Returns this function raised at the specified exponent.

Parameters:
n - the exponent.
Returns:
thisn
Throws:
java.lang.IllegalArgumentException - if n <= 0

plus

public Operable plus(Operable that)
Description copied from interface: Operable
Returns the sum of this object with the one specified.

Specified by:
plus in interface Operable
Parameters:
that - the object to be added.
Returns:
this + that.

opposite

public Operable opposite()
Description copied from interface: Operable
Returns the additive inverse of this object. It is the object such as this.plus(this.opposite()) == ZERO, with ZERO being the additive identity.

Specified by:
opposite in interface Operable
Returns:
-this.

times

public Operable times(Operable that)
Description copied from interface: Operable
Returns the product of this object with the one specified.

Specified by:
times in interface Operable
Parameters:
that - the object multiplier.
Returns:
this * that.

reciprocal

public Operable reciprocal()
Description copied from interface: Operable
Returns the multiplicative inverse of this object. It it the object such as this.times(this.reciprocal()) == ONE , with ONE being the multiplicative identity.

Specified by:
reciprocal in interface Operable
Returns:
ONE / this.

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.