net.sf.doodleproject.numerics4j.series
Class PowerSeries

java.lang.Object
  extended by net.sf.doodleproject.numerics4j.IterativeMethod
      extended by net.sf.doodleproject.numerics4j.series.PowerSeries

public abstract class PowerSeries
extends IterativeMethod

This class provides the means to evaluate infinite power series (1). To create a power series, authors subclass this class and provided a concrete term method.

For example, this is the power series for the exponential function defined by (2):

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

References:

  1. Eric W. Weisstein. "Power Series." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/PowerSeries.html
  2. Exponential Function: Series Representation. http://functions.wolfram.com/01.03.06.0002.01

Since:
1.1
Version:
$Revision: 1.2 $ $Date: 2007/10/25 04:44:14 $

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.doodleproject.numerics4j.IterativeMethod
IterativeMethod.IterativeState
 
Constructor Summary
protected PowerSeries()
          Default constructor.
protected PowerSeries(int iterations, double error)
          Create a series with the given number of maximum iterations and maximum relative error.
protected PowerSeries(int index, int iterations, double error)
          Create a series with the given first term index, number of maximum iterations and maximum relative error.
 
Method Summary
 double evaluate(double x)
          Evaluate this series at the given value.
protected abstract  double getTerm(int n)
          Access the n-th term for this series.
 
Methods inherited from class net.sf.doodleproject.numerics4j.IterativeMethod
getMaximumIterations, getMaximumRelativeError, iterate, setMaximumIterations, setMaximumRelativeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PowerSeries

protected PowerSeries()
Default constructor.


PowerSeries

protected PowerSeries(int iterations,
                      double error)
Create a series with the given number of maximum iterations and maximum relative error.

Parameters:
iterations - maximum number of iterations.
error - maximum relative error.

PowerSeries

protected PowerSeries(int index,
                      int iterations,
                      double error)
Create a series with the given first term index, number of maximum iterations and maximum relative error.

Parameters:
index - index of first term in this series.
iterations - maximum number of iterations.
error - maximum relative error.
Method Detail

evaluate

public double evaluate(double x)
                throws NumericException
Evaluate this series at the given value.

Parameters:
x - the point of evalutation.
Returns:
the value of this series evaluated at x.
Throws:
NumericException - if the series could not be evaluated.

getTerm

protected abstract double getTerm(int n)
Access the n-th term for this series.

Parameters:
n - the term index.
Returns:
the n-th series term.


Copyright 2004-2004-2007 DoodleProject. All Rights Reserved.