net.sf.doodleproject.numerics4j.continuedfraction
Class ContinuedFraction

java.lang.Object
  extended by net.sf.doodleproject.numerics4j.IterativeMethod
      extended by net.sf.doodleproject.numerics4j.continuedfraction.ContinuedFraction

public abstract class ContinuedFraction
extends IterativeMethod

This class provides the means to evaluate continued fractions (1). To create a continued fraction, authors subclass this class and provided concrete a and b coefficient methods.

For example, this is the continued fraction for the exponential function defined by (2):

 ContinuedFraction exponential = new ContinuedFraction() {
     public double getA(int n, double x) {
         if (n == 0) {
             return 1.0;
         } else if (n % 2 == 0) { // even
             return 2.0;
         } else { // odd
             return n;
         }
     }
    
     public double getB(int n, double x) {
         if (n % 2 == 0) { // even
             return x;
         } else { // odd
             return -x;
         }
 }
 

References:

  1. Eric W. Weisstein. "Continued Fraction." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ContinuedFraction.html
  2. Exponential Function: Continued Fraction Representation. http://functions.wolfram.com/01.03.10.0001.01

Version:
$Revision: 1.2 $ $Date: 2007/10/25 04:44:21 $

Nested Class Summary
(package private)  class ContinuedFraction.IterativeState
          The internal state used during continued fraction evaluation.
 
Constructor Summary
protected ContinuedFraction()
          Default constructor.
protected ContinuedFraction(int iterations, double error)
          Create a continued fraction with the given number of maximum iterations and maximum relative error.
 
Method Summary
 double evaluate(double x)
          Evaluate this continued fraction at the given value.
protected abstract  double getA(int n, double x)
          Access the n-th a coefficient.
protected abstract  double getB(int n, double x)
          Access the n-th b coefficient.
 
Methods inherited from class net.sf.doodleproject.numerics4j.IterativeMethod
getMaximumIterations, getMaximumRelativeError, iterate, setMaximumIterations, setMaximumRelativeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContinuedFraction

protected ContinuedFraction()
Default constructor.


ContinuedFraction

protected ContinuedFraction(int iterations,
                            double error)
Create a continued fraction with the given number of maximum iterations and maximum relative error.

Parameters:
iterations - maximum number of iterations.
error - maximum relative error.
Method Detail

evaluate

public double evaluate(double x)
                throws NumericException
Evaluate this continued fraction at the given value.

Parameters:
x - the point of evalutation.
Returns:
the value of this continued fraction evaluated at x.
Throws:
NumericException - if the continued fraction could not be evaluated.

getA

protected abstract double getA(int n,
                               double x)
Access the n-th a coefficient.

Parameters:
n - the coefficient index.
x - the continued fraction evaluation point.
Returns:
the n-th a coefficient.

getB

protected abstract double getB(int n,
                               double x)
Access the n-th b coefficient.

Parameters:
n - the coefficient index.
x - the continued fraction evaluation point.
Returns:
the n-th b coefficient.


Copyright 2004-2004-2007 DoodleProject. All Rights Reserved.