#include <powerseries.h>
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) |
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:
power_series< Term >::power_series | ( | Term & | t, | |
unsigned int | first = 0 , |
|||
unsigned int | iterations = 100 , |
|||
double | relative_error = 1.0e-13 | |||
) | [inline] |
power_series< Term >::~power_series | ( | ) | [inline] |
Destructor.
double power_series< Term >::evaluate | ( | double | x | ) | [inline] |