6 Utilities6.1 OverviewThe org.apache.commons.math.util package collects a group of array utilities, value transformers, and numerical routines used by implementation classes in commons-math. 6.2 Double array utilities
To maintain statistics based on a "rolling" window of values, a resizable
array implementation was developed and is provided for reuse in the
The
org.apache.commons.math.util.ResizableDoubleArray
class provides a
configurable, array-backed implementation of the 6.3 Continued Fractions
The
org.apache.commons.math.util.ContinuedFraction
class provides a generic
way to create and evaluate continued fractions. The easiest way to create a
continued fraction is to subclass As an example, the constant Pi could be computed using the continued fraction defined at http://functions.wolfram.com/Constants/Pi/10/0002/ . The following anonymous class provides the implementation: ContinuedFraction c = new ContinuedFraction() { public double getA(int n, double x) { switch(n) { case 0: return 3.0; default: return 6.0; } } public double getB(int n, double x) { double y = (2.0 * n) - 1.0; return y * y; } }
Then, to evalute Pi, simply call any of the For a more practical use of continued fractions, consider the exponential function with the continued fraction definition of http://functions.wolfram.com/ElementaryFunctions/Exp/10/ . The following anonymous class provides its implementation: ContinuedFraction c = new ContinuedFraction() { public double getA(int n, double x) { if (n % 2 == 0) { switch(n) { case 0: return 1.0; default: return 2.0; } } else { return n; } } public double getB(int n, double x) { if (n % 2 == 0) { return -x; } else { return x; } } }
Then, to evalute ex for any value x, simply call any of the
6.4 binomial coefficients, factorials and other common math functionsA collection of reusable math functions is provided in the MathUtils utility class. MathUtils currently includes methods to compute the following:
|