net.sf.doodleproject.numerics4j.root
Class BisectionRootFinder

java.lang.Object
  extended by net.sf.doodleproject.numerics4j.IterativeMethod
      extended by net.sf.doodleproject.numerics4j.root.BisectionRootFinder

public class BisectionRootFinder
extends IterativeMethod

The bisection method (1) for finding roots of functions.

For example, to find roots for sine, first a Function is defined:

 Function sine = new Function() {
    public double evaluate(double x) {
        return Math.sin(x);
    }}
 };
 

Then, a bisection root finder is created with the above function:

 BisectionRootFinder finder = new BisectionRootFinder(sine);
 

Lastly, locating roots is accomplished using the findRoot(double, double) method:

 // find the root between 3 and 4.
 double pi = finder.findRoot(3.0, 4.0);
 
 // find the root between -1 and 1.
 double zero = finder.findRoot(-1.0, 1.0);
 

References:

  1. Eric W. Weisstein. "Bisection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Bisection.html

Version:
$Revision: 1.3 $ $Date: 2007/10/27 04:57:42 $

Constructor Summary
BisectionRootFinder(Function f)
          Create a root finder for the given function.
BisectionRootFinder(Function f, int iterations, double error)
          Create a root finder for the given function.
 
Method Summary
 double findRoot(double min, double max)
          Find a root of the target function that lies in the interval [ min, max].
 Function getFunction()
          Access the target function.
 void setFunction(Function f)
          Modify the target function.
 
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

BisectionRootFinder

public BisectionRootFinder(Function f)
Create a root finder for the given function.

Parameters:
f - the target function.

BisectionRootFinder

public BisectionRootFinder(Function f,
                           int iterations,
                           double error)
Create a root finder for the given function.

Parameters:
f - the target function.
iterations - maximum number of iterations.
error - maximum relative error.
Method Detail

findRoot

public double findRoot(double min,
                       double max)
                throws NumericException
Find a root of the target function that lies in the interval [ min, max].

Parameters:
min - the lower bound of the search interval.
max - the upper bound of the search interval.
Returns:
a root that lies between min and max, inclusive.
Throws:
NumericException - if a root could not be found.

getFunction

public Function getFunction()
Access the target function.

Returns:
the target function.

setFunction

public void setFunction(Function f)
Modify the target function.

Parameters:
f - the new target function.


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