series< Term > Class Template Reference

#include <series.h>

Inheritance diagram for series< Term >:

iterative_method

List of all members.

Public Member Functions

 series (Term &t, unsigned int first=0, unsigned int iterations=100, double relative_error=1.0e-15)
 ~series ()
double evaluate (double x)


Detailed Description

template<class Term>
class series< Term >

This class provides the means to evaluate infinite series (1). To create a series, authors create an instance of series and provide a term functor.

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

double factorial(int n) {
    double p = 1.0;
    for(int i = n; i > 0; --i) {
        p *= i;
    }
    return p;
}

double exponential_term(unsigned int n, double x) {
    return std::pow(x, n) / factorial(n);
}

num::series<num::series_term> exponential(exponential_term);
double x = exponential.evaluate(2.0); // std::exp(2.0)
       x = exponential.evaluate(4.0); // std::exp(4.0)

References:

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

Constructor & Destructor Documentation

template<class Term>
series< Term >::series ( Term &  t,
unsigned int  first = 0,
unsigned int  iterations = 100,
double  relative_error = 1.0e-15 
) [inline]

Create a series with the given term functor.

Parameters:
t the term functor.
first the index of the first series term.
iterations the maximum number of iterations.
relative_error the maximum allowable relative error.

template<class Term>
series< Term >::~series (  )  [inline]

Destructor.


Member Function Documentation

template<class Term>
double series< Term >::evaluate ( double  x  )  [inline]

Evaluate this series at the given value.

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


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