Series

numerics4c++ provides the means to create and evaluate infinite series. The following routines are available for series evaluation:

Method Description
Power Series Specialized series implementation devoted to power series evaluation.
Series A pure infinite series where terms are functions of their index and point of evaluation. If none of the other series methods satisfy your needs, this series implementation should be flexible enough to accomodate any situation.

Power Series

numerics4c++ provides the means to create and evaluate infinite power series. See Power Series for an in depth definition of infinite power series. To create a power series, simply create a new power_series instance providing a functor for the term, which returns the terms of the series.

For example, the exponetial function can be evaluated with a power series:

double factorial(unsigned int n) {
      double p = 1.0;
      for(unsigned 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)
double x = exponential.evaluate(4.0); // std::exp(4.0)

Series

numerics4c++ provides the means to create and evaluate infinite series. See Series for an in depth definition of infinite series. To create a series, simply create a new series instance providing a functor for the term, which returns the terms of the series.

The series class is flexible with regards to the variety of convergent, infinite series it can represent. For example it can be used on geometric series, ones whose ratio of consecutive terms is constant like "the" geometric series:

double geometric_term(unsigned int n, double x) {
    return std::pow(0.5, n);
}

num::series<num::series_term> geometric(geometric_term);
double x = geometric.evaluate(0.0);  // returns 2.0 for all input values.

Also, the series class can represent series whose terms are not only functions of their indices, but also functions of an evaluation point. A lot of common series fit this general definition including power series and Taylor series. As such, these series can be evaluated numerically using the series class. For example, the exponetial function can be evaulated with a series:

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(0.5, 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)