org.opensourcephysics.numerics
Class Derivative

java.lang.Object
  extended by org.opensourcephysics.numerics.Derivative

public class Derivative
extends java.lang.Object

Derivative defines various derivative algorithms. This class cannot be subclassed or instantiated because all methods are static.

Author:
Wolfgang Christian

Method Summary
static double backward(Function f, double x, double h)
          Calculates the first derivative of a function using the finite difference approximation toward decreasing x.
static double centered(Function f, double x, double h)
          Calculates the first derivative of a function using the centered finite difference approximation.
static double first(Function f, double x, double h)
          Calculates the first derivative of a function at the given point.
static double firstPartial(MultiVarFunction f, double[] x, int n, double h)
          Gets the partial derivate of a multivariable function using the centered finite difference approximation.
static double forward(Function f, double x, double h)
          Calculates the first derivative of a function using the finite difference approximation toward increasing x.
static Function getFirst(Function f, double h)
          Gets a derivative function using the centered difference approximation.
static Function getSecond(Function f, double h)
          Gets a second derivative function using a second order finite difference approximation.
static double romberg(Function f, double x0, double h, double tol)
          Calculates the derivative using the Romberg scheme for Richardson extrapolation.
static double second(Function f, double x, double h)
          Computes the second derivate using the centered finite difference approximation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFirst

public static Function getFirst(Function f,
                                double h)
Gets a derivative function using the centered difference approximation.

Parameters:
f - Function f(x)
h - double change in x
Returns:
Function

getSecond

public static Function getSecond(Function f,
                                 double h)
Gets a second derivative function using a second order finite difference approximation.

Parameters:
f - Function f(x)
h - double change in x
Returns:
Function second derivate

romberg

public static double romberg(Function f,
                             double x0,
                             double h,
                             double tol)
Calculates the derivative using the Romberg scheme for Richardson extrapolation. This method runs until all Romberg rows are filled or until the step size drops below defaultNumericalPrecision or if the desired tolerance is reached.

Parameters:
f - the function
x0 - where derivative is to be calculated
h - initial step size
tol - desired accuracy
Returns:
first derivative

first

public static double first(Function f,
                           double x,
                           double h)
Calculates the first derivative of a function at the given point. The current implementation uses the centered finite difference method but this may change.

Parameters:
f - the function
x - the x value
h -
Returns:
first derivative

centered

public static double centered(Function f,
                              double x,
                              double h)
Calculates the first derivative of a function using the centered finite difference approximation.

Parameters:
f - the function
x - the x value
h -
Returns:
first derivatve

backward

public static double backward(Function f,
                              double x,
                              double h)
Calculates the first derivative of a function using the finite difference approximation toward decreasing x.

Parameters:
f - the function
x - the x value
h -
Returns:
first derivative

forward

public static double forward(Function f,
                             double x,
                             double h)
Calculates the first derivative of a function using the finite difference approximation toward increasing x.

Parameters:
f - the function
x - the x value
h -
Returns:
first derivative

firstPartial

public static double firstPartial(MultiVarFunction f,
                                  double[] x,
                                  int n,
                                  double h)
Gets the partial derivate of a multivariable function using the centered finite difference approximation.

Parameters:
f - MultiVarFunction
x - double[] variables
n - int index
h - double change in the varible with index i
Returns:
double

second

public static double second(Function f,
                            double x,
                            double h)
Computes the second derivate using the centered finite difference approximation.

Parameters:
f - Function
x - double
h - double
Returns:
double