Series

numerics4j provides the means to create and evaluate infinite series. See Series for an in depth definition of infinite series. To create a series, simply subclass net.sf.doodleproject.numerics4j.series.Series and provide an implementation for the getTerm method, which returns the series terms.

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:

Series geometric = new Series() {
    public double getTerm(int n, double x) {
        return Math.pow(.5, n);
    }
};

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:

Series exponential = new Series() {
    public double getTerm(int n, double x) {
        return Math.pow(x, n) / 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)