Power Series

numerics4j 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 subclass net.sf.doodleproject.numerics4j.series.PowerSeries and provide an implementation for the getTerm method, which returns the series terms.

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

PowerSeries exponential = new PowerSeries() {
    public double getTerm(int n) {
        return 1.0 / factorial(n);
    }
    
    private double factorial(int n) {
        double p = 1.0;
        for(int i = n; i > 0; --i) {
            p *= i;
        }
        return p;
    }
};

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