math.numerics
Class Root

java.lang.Object
  extended by math.numerics.Root

public class Root
extends java.lang.Object

Class Root defines various root finding algorithms. This class cannot be subclassed or instantiated because all methods are static.

Author:
Wolfgang Christian

Method Summary
static double bisection(Function f, double x1, double x2, double tol)
          Implements the bisection method for finding the root of a function.
static double newton(Function f, double x, double tol)
          Implements Newton's method for finding the root of a function.
static double newton(Function f, Function df, double x, double tol)
          Implements Newton's method for finding the root of a function.
static double[] solveQuadratic(double a, double b, double c)
          Solves for the roots of the quadratic equation ax2+bx+c=0.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

solveQuadratic

public static double[] solveQuadratic(double a,
                                      double b,
                                      double c)
Solves for the roots of the quadratic equation ax2+bx+c=0.

Parameters:
a - double quadratic term coefficient
b - double linear term coefficient
c - double constant term
Returns:
double[] an array containing the two roots.

newton

public static double newton(Function f,
                            double x,
                            double tol)
Implements Newton's method for finding the root of a function. The derivative is calculated numerically using Romberg's method.

Parameters:
f - Function the function
x - double guess the root
tol - double computation tolerance
Returns:
double the root or NaN if root not found.

newton

public static double newton(Function f,
                            Function df,
                            double x,
                            double tol)
Implements Newton's method for finding the root of a function.

Parameters:
f - Function the function
df - Function the derivative of the function
x - double guess the root
tol - double computation tolerance
Returns:
double the root or NaN if root not found.

bisection

public static double bisection(Function f,
                               double x1,
                               double x2,
                               double tol)
Implements the bisection method for finding the root of a function.

Parameters:
f - Function the function
x - double guess root
tol - double computation tolerance
Returns:
double the root or NaN if root not found