Class SpecialFunctions

  extended by nr.SpecialFunctions

public class SpecialFunctions
extends java.lang.Object

Some useful functions

Daniel Wachsstock

Method Summary
static double chisq(double x, double n)
          chi square distribution.
static double logGamma(double x)
          Returns the natural logarithm of the gamma function.
static double randomExponential(double n)
          sum of n random exponentials.
static double randomGaussian(double dev)
          random gaussian with a given standard deviation
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static double randomGaussian(double dev)
random gaussian with a given standard deviation


public static double randomExponential(double n)
sum of n random exponentials. The gamma deviate from Numerical Recipes section 7.3. Adds n random deviates with probability distribution p(x) = exp(-x)

n - the number of exponentials to add. A double, for flexibility with the rest of the program. If n does not represent an integer, for small n uses floor(n); for large n uses a function approximation that effectively interpolates between floor(n) and floor(n)+1.
java.lang.IllegalArgumentException - if n < 1


public static double chisq(double x,
                           double n)
chi square distribution. Probability of a chi-square-distributed statistic (probability that the sum of the squares of n normally distributed random deviates with mean 0 and variance 1 exceeds a value x. The higher x is, the lower chisq is.

x - the sum-of-squares
n - the "degrees of freedom": the number of sums-of-squares minus the number of fitted parameters.
java.lang.IllegalArgumentException - if x < 0 or n <= 0
java.lang.ArithmeticException - if the function cannot be estimated


public static double logGamma(double x)
                       throws java.lang.ArithmeticException
Returns the natural logarithm of the gamma function. Copied from the CERN COLT package. n! is exp (logGamma (n+1))


Some code taken and adapted from the Java 2D Graph Package 2.4, which in turn is a port from the Cephes 2.2 Math Library (C). Most Cephes code (missing from the 2D Graph Package) directly ported.

x - the argument to the function
java.lang.ArithmeticException - if the function overflows