Example: The Epsilon Algorithm

The Epsilon algorithm is used to accelerate a series of partial sums of an infinite sum. The error shows that the Epsilon algorithm is effective.
import com.imsl.math.*;
import java.text.DecimalFormat;

public class EpsilonAlgorithmEx1 {
    static public void main(String arg[]) {
        EpsilonAlgorithm eps = new EpsilonAlgorithm();
        
        int n = 100;
        double sum = 0.0;
        for (int i = 1;  i < n;  i++) {
            sum += 1.0 / (i*i);
            eps.extrapolate(sum);
        }
        sum += 1.0 / (n*n);
        double extrapolated = eps.extrapolate(1.0/(n*n));
        double expected = Math.PI * Math.PI / 6.0;
        double exError = expected - extrapolated;
        double sumError = expected - sum;
        DecimalFormat format = new DecimalFormat("0.00000"); 
        System.out.println("Expected     "+format.format(expected));
        System.out.print("Extrapolated "+format.format(extrapolated));
        System.out.println("   error ="+format.format(exError));
        System.out.print("Sum          "+format.format(sum));
        System.out.println("   error ="+format.format(sumError));
    }    
}

Output

Expected     1.64493
Extrapolated 1.64278   error =0.00216
Sum          1.63498   error =0.00995
Link to Java source.