continued_fraction< A, B > Class Template Reference

#include <continuedfraction.h>

Inheritance diagram for continued_fraction< A, B >:

iterative_method

List of all members.

Public Member Functions

 continued_fraction (A &coefA, B &coefB, unsigned int iterations=100, double relative_error=1.0e-15)
 ~continued_fraction ()
double evaluate (double x)


Detailed Description

template<class A, class B>
class continued_fraction< A, B >

This class provides the means to evaluate continued fractions (1). To create a continued fraction, authors create an instance of continued_fraction and provide a and b coefficient functors.

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

double exponential_a(unsigned int n, double x) {
    if (n == 0) {
        return 1.0;
    } else if (n % 2 == 0) { // even
        return 2.0;
    } else { // odd
        return n;
    }
}

double exponential_b(unsigned int n, double x) {
    if (n % 2 == 0) { // even
        return x;
    } else { // odd
        return -x;
    }
}

num::continued_fraction<num::continued_fraction_coefficient, num::continued_fraction_coefficient>
    exponential(exponential_a, exponential_b);

double x = exponential.evaluate(2.0); // std::exp(2.0)
       x = exponential.evaluate(4.0); // std::exp(4.0)

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

Constructor & Destructor Documentation

template<class A, class B>
continued_fraction< A, B >::continued_fraction ( A &  coefA,
B &  coefB,
unsigned int  iterations = 100,
double  relative_error = 1.0e-15 
) [inline]

Create a continued fraction with the given coefficient functors.

Parameters:
coefA the a coefficient functor.
coefB the b coefficient functor.
iterations the maximum number of iterations.
relative_error the maximum allowable relative error.

template<class A, class B>
continued_fraction< A, B >::~continued_fraction (  )  [inline]

Destructor.


Member Function Documentation

template<class A, class B>
double continued_fraction< A, B >::evaluate ( double  x  )  [inline]

Evaluate this continued fraction at the given value.

Parameters:
x the point of evalutation.
Returns:
the value of this continued fraction evaluated at x.


The documentation for this class was generated from the following file:
Generated on Wed Nov 21 22:22:15 2007 for numerics4c++ by  doxygen 1.5.3