org.opensourcephysics.numerics
Class Integral

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

public final class Integral
extends java.lang.Object

Class Integral defines various integration algorithms. This class cannot be subclassed or instantiated because all methods are static.

Author:
Wolfgang Christian

Method Summary
static double[][] fillArray(Function f, double start, double stop, double tol, double[][] data)
          Fills the given data array with the intgral of the given function.
static double[][] fillArray(Function f, double start, double stop, double tol, int n)
          Fills a data array with the integral of the given function.
static double ode(Function f, double start, double stop, double tol)
          Computes the integral of the function using an ODE solver.
static double romberg(Function f, double a, double b, int n, double tol)
          Integrates the function using Romberg's algorithm based on Richardson's deferred approach.
static double simpson(double[] f, double h)
          Uses Simpson's rule to find the area of an array representing a function that's been evaluated at N intervals of size h, where N is an odd integer.
static double simpson(Function f, double start, double stop, int n)
          Numerical integration using Simpson's rule.
static double simpson(Function f, double start, double stop, int n, double tol)
          Numerical integration using Simpson's rule.
static double trapezoidal(Function f, double start, double stop, int n, double tol)
          Integrates the function using the trapezoidal method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

trapezoidal

public static double trapezoidal(Function f,
                                 double start,
                                 double stop,
                                 int n,
                                 double tol)
Integrates the function using the trapezoidal method.

Parameters:
f - the function
start - the first ordinate.
stop - the last ordinate.
n - the number of partitions
tol - relative tolerance
Returns:
the integral

simpson

public static double simpson(Function f,
                             double start,
                             double stop,
                             int n)
                      throws java.lang.IllegalArgumentException
Numerical integration using Simpson's rule.

Parameters:
f - a function.
start - the first ordinate.
stop - the last ordinate.
n - the number of partitions
Returns:
the integral
Throws:
java.lang.IllegalArgumentException

simpson

public static double simpson(Function f,
                             double start,
                             double stop,
                             int n,
                             double tol)
Numerical integration using Simpson's rule.

Parameters:
f - the function
start - the first ordinate.
stop - the last ordinate.
n - minimum number of partitions
tol - relative tolerance
Returns:
the integral

romberg

public static double romberg(Function f,
                             double a,
                             double b,
                             int n,
                             double tol)
Integrates the function using Romberg's algorithm based on Richardson's deferred approach.

Parameters:
f - the function
a -
b -
n -
tol - tolerance
Returns:
the integral

simpson

public static double simpson(double[] f,
                             double h)
Uses Simpson's rule to find the area of an array representing a function that's been evaluated at N intervals of size h, where N is an odd integer. Example of usage: int N=27; x=new double[N]; f=new double[N]; double a=0, b=5, h=(b-a)/(N-1); for (int i=0; i< N;i++){ x[i]=a+i*h; f[i]=x[i]*Math.exp(x[i]); } double sum=Simp.Simp(f,h); Results: sum=594.6615858178942


ode

public static double ode(Function f,
                         double start,
                         double stop,
                         double tol)
Computes the integral of the function using an ODE solver.

Parameters:
f - the function
start -
stop -
tol - relative tolerance
Returns:
the integral

fillArray

public static double[][] fillArray(Function f,
                                   double start,
                                   double stop,
                                   double tol,
                                   int n)
Fills a data array with the integral of the given function.

Parameters:
f - Function to be integrated
start - double start of integral
stop - double end of integral
tol - double computation tolerance
n - int number of data points
Returns:
double[][]

fillArray

public static double[][] fillArray(Function f,
                                   double start,
                                   double stop,
                                   double tol,
                                   double[][] data)
Fills the given data array with the intgral of the given function.

Parameters:
f - Function to be integrated
start - double start of integral
stop - double end of integral
tol - double computation tolerance
data - double[][]
Returns:
double[][]