power_series< Term > Class Template Reference

#include <powerseries.h>

Inheritance diagram for power_series< Term >:

iterative_method

List of all members.

Public Member Functions

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


Detailed Description

template<class Term>
class power_series< Term >

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

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

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

double exponential_term(unsigned int n) {
    return 1.0 / factorial(n);
}

num::power_series<num::power_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. "Power Series." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/PowerSeries.html
  2. Exponential Function: Series Representation. http://functions.wolfram.com/01.03.06.0002.01

Constructor & Destructor Documentation

template<class Term>
power_series< Term >::power_series ( Term &  t,
unsigned int  first = 0,
unsigned int  iterations = 100,
double  relative_error = 1.0e-13 
) [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>
power_series< Term >::~power_series (  )  [inline]

Destructor.


Member Function Documentation

template<class Term>
double power_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