org.jscience.mathematics.analysis.taylor
Class TaylorDouble

java.lang.Object
  extended by org.jscience.mathematics.analysis.taylor.TaylorDouble
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
TaylorBinary, TaylorConstant, TaylorDependant, TaylorIndependant, TaylorParameter, TaylorUnary

public abstract class TaylorDouble
extends java.lang.Object
implements java.io.Serializable

The abstract superclass of all TaylorDouble objects, representing a species of expressions that are automatically Taylor expandable.

See Also:
Serialized Form

Field Summary
protected  double[] coeffs
          The Taylor coefficients of this TaylorDouble.
protected  boolean constant
          True for TaylorDoubles that are constant in time, such as constants, parameters or a multiplication of two parameters.
protected  boolean independent
          True for the independent variable t or another TaylorDouble with only the two first Taylor coefficients nonzero, such as w·t + c.
protected  int order
          The current order of the expansion of this TaylorDouble.
 
Constructor Summary
TaylorDouble()
           
 
Method Summary
protected abstract  void calcOrder(int k)
          Any TaylorDouble must implement this method for calculation of the kth Taylor coefficient.
 double evaluate(double h)
          Evaluate at time t = t0 + h, where t0 is the expansion point; that is evaluate the Taylor expansion f (x,t) = f (t0) + f ' (t0h + f '' (t0) ·h2 + ...
 void expandToOrder(int k)
          Expand this TaylorDouble variable to order k.
protected  int flops(int k)
          Return the number of flops required to calculate the kth coefficient of this TaylorDouble.
 double getCoeff(int k)
          Get the kth Taylor coefficient.
 int getOrder()
          Get the order of the Taylor expansion.
abstract  void reset()
          Any TaylorDouble must implement a method to reset, that is to drop it's order to -1 and reset any TaylorDoubles it is dependent on.
protected  void setToLength(int k)
          Set the size of the coefficient array coeffs[] to k.
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

coeffs

protected double[] coeffs
The Taylor coefficients of this TaylorDouble.

Only the first order + 1 elements are valid, including coeffs[order]. The zeroth coefficient f0 = f (t0) is indexed coeffs[0].

The array is typically initialized with 10 elements, but the size is dynamically resized if in need for extra space.


order

protected int order
The current order of the expansion of this TaylorDouble.


constant

protected boolean constant
True for TaylorDoubles that are constant in time, such as constants, parameters or a multiplication of two parameters.

When a method realizes that an operand of some kind is either constant or independent, it should attempt to optimize code such as not to address the numerous zero coefficients of such TaylorDouble.


independent

protected boolean independent
True for the independent variable t or another TaylorDouble with only the two first Taylor coefficients nonzero, such as w·t + c.

Constructor Detail

TaylorDouble

public TaylorDouble()
Method Detail

evaluate

public double evaluate(double h)
Evaluate at time t = t0 + h, where t0 is the expansion point; that is evaluate the Taylor expansion
f (x,t) = f (t0) + f ' (t0h + f '' (t0) ·h2 + ...


expandToOrder

public void expandToOrder(int k)
Expand this TaylorDouble variable to order k. If dependent on any TaylorDependants, those must be available to order k, or they must be governed by some ODE.


calcOrder

protected abstract void calcOrder(int k)
Any TaylorDouble must implement this method for calculation of the kth Taylor coefficient.

The TaylorDouble should assume, that it's k-1 first coefficients are valid, so that only the kth is to be calculated.


flops

protected int flops(int k)
Return the number of flops required to calculate the kth coefficient of this TaylorDouble.

Notice that flops changes order, so calcOrder and flops should be separated by a call to reset


reset

public abstract void reset()
Any TaylorDouble must implement a method to reset, that is to drop it's order to -1 and reset any TaylorDoubles it is dependent on.

This strategy has been chosen, since it is difficult/unefficient to communicate the shifting of the expansion point from the independent variable upwards in the dependence tree to the top function value. Instead the top level TaylorDouble function value(s) is reset, which causes the information to propagate downwards to all the TaylorDoubles it is dependent on.

The reset signal is also intended to communicate such thing as the change of a parameter value, which also require all coefficients to be recalculated.


getCoeff

public double getCoeff(int k)
Get the kth Taylor coefficient.

Throws an ArithmeticException if the kth coefficient is not available (yet).


getOrder

public int getOrder()
Get the order of the Taylor expansion. The coefficients are indexed from zero, and -1 is returned if no coefficients are currently available.


toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

setToLength

protected void setToLength(int k)
Set the size of the coefficient array coeffs[] to k.

If the current order is larger than k-1, it is decreased.