org.jscience.mathematics.analysis.expressions
Interface NumericalDifferentiable

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
Acos, Addition, Asin, Atan, Constant, Cos, Division, Exp, Log, Minus, Multiplication, NamedDataExpression, Parameter, Pow, Sin, Sqrt, Subtraction, Tan, Variable

public interface NumericalDifferentiable
extends java.io.Serializable

The interface specifies the methods that must be supplied for a class to be able to perform automatic differentiation in the reverse mode.
Example of use:
The example uses the classes from the symbolic computation package org.jscience.mathematics.analysis.expressions.symbolic that supports automatic differentiation. Note that since all classes do not implement the NumericalDifferentiable interface some class castings are necessary. In the example x, y, and z are independent variables/parameters, and e and f are dependent variables. All other expressions are auxiliaries.

 Variable x = new Variable( "x" );
 Variable y = new Variable( "y" );
 Parameter z = new Parameter( "z" );
 Expression a = new Sin( x );
 Expression b = new Multiplication( new Constant( 1.0 ), x );
 Expression c = new Division( y, a );
 Expression d = new Multiplication( a, z );
 Expression e = new Subtraction( b, c );
 Expression f = new Addition( c, d );
 for(int k = 0; k < 10; k++) f = new Sin( f );
 x.setIndex( 1 );
 y.setIndex( 2 );
 z.setIndex( 3 );
 ((NumericalDifferentiable)e).setNumberOfIndependents( 3 );
 ((NumericalDifferentiable)f).setNumberOfIndependents( 3 );
 x.setValue( 0.13 );
 y.setValue( 0.46 );
 z.setValue( 0.73 );
 ((NumericalDifferentiable)e).resetNumEval();
 ((NumericalDifferentiable)f).resetNumEval();
 ((NumericalDifferentiable)e).resetNumDiff( 1 );
 ((NumericalDifferentiable)f).resetNumDiff( 1 );
 double dedx = ((NumericalDifferentiable)e).numDiff( 1 );
 double dfdx = ((NumericalDifferentiable)f).numDiff( 1 );
 ((NumericalDifferentiable)e).resetNumDiff( 2 );
 ((NumericalDifferentiable)f).resetNumDiff( 2 );
 double dedy = ((NumericalDifferentiable)e).numDiff( 2 );
 double dfdy = ((NumericalDifferentiable)f).numDiff( 2 );
 ((NumericalDifferentiable)e).resetNumDiff( 3 );
 ((NumericalDifferentiable)f).resetNumDiff( 3 );
 double dedz = ((NumericalDifferentiable)e).numDiff( 3 );
 double dfdz = ((NumericalDifferentiable)f).numDiff( 3 );
 


Method Summary
 double numDiff(int i)
          Returns the derivative of an Expression with respect to a NamedDataExpression whose index is the parameter.
 double numEval()
          Compute the numerical value of the function expression.
 void resetNumDiff(int i)
          Reset the computational tree for derivative calculation for the indexed independent variable.
 void resetNumEval()
          Reset the function evaluation such that the next invocation of numEval() carries out the full computation.
 void setIndex(int i)
          Sets the index of an independent variable.
 void setNumberOfIndependents(int n)
          Sets the number of independent variables in the computational tree.
 

Method Detail

numDiff

double numDiff(int i)
Returns the derivative of an Expression with respect to a NamedDataExpression whose index is the parameter.

Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

resetNumDiff

void resetNumDiff(int i)
Reset the computational tree for derivative calculation for the indexed independent variable.

Parameters:
i - DOCUMENT ME!

setNumberOfIndependents

void setNumberOfIndependents(int n)
Sets the number of independent variables in the computational tree.

Parameters:
n - DOCUMENT ME!

setIndex

void setIndex(int i)
Sets the index of an independent variable. The index should be used to identify an independent variable

Parameters:
i - DOCUMENT ME!

numEval

double numEval()
Compute the numerical value of the function expression.

Returns:
DOCUMENT ME!

resetNumEval

void resetNumEval()
Reset the function evaluation such that the next invocation of numEval() carries out the full computation.