MathFunctions
jdistlib.math

Class MathFunctions



  • public class MathFunctionsextends Object
    • Constructor Summary

      Constructors 
      Constructor and Description
      MathFunctions() 
    • Method Summary

      Methods 
      Modifier and TypeMethod and Description
      static double_expm1(double x)
      Alternative expm1 -- no difference from Java's
      static double_log1p(double x)
      Alternative log1p.
      static doublealgdiv(double a, double b)
      ----------------------------------------------------------------------- COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B >= 8.
      static doublealnrel(double a)
      ----------------------------------------------------------------------- Evaluation of the function ln(1 + a) -----------------------------------------------------------------------
      static doubleapser(double a, double b, double x, double eps) 
      static doublebasym(double a, double b, double lambda, double eps, boolean log_p) 
      static doublebcorr(double a0, double b0)
      ----------------------------------------------------------------------- EVALUATION OF DEL(A0) + DEL(B0) - DEL(A0 + B0) WHERE LN(GAMMA(A)) = (A - 0.5)*LN(A) - A + 0.5*LN(2*PI) + DEL(A).
      static doublebd0(double x, double np) 
      static doublebeta(double a, double b)
      This function returns the value of the beta function evaluated with arguments a and b.
      static doublebetaln(double a0, double b0)
      ----------------------------------------------------------------------- Evaluation of the logarithm of the beta function ln(beta(a0,b0)) -----------------------------------------------------------------------
      static doublebfrac(double a, double b, double x, double y, double lambda, double eps, boolean log_p) 
      static doublebgrat(double a, double b, double x, double y, double w, double eps, boolean log_w) 
      static doublebpser(double a, double b, double x, double eps, boolean log_p) 
      static double[]bratio(double a, double b, double x, double y, boolean log_p)
      ----------------------------------------------------------------------- Evaluation of the Incomplete Beta function I_x(a,b) -------------------- It is assumed that a and b are nonnegative, and that x <= 1 and y = 1 - x.
      static doublebrcmp1(int mu, double a, double b, double x, double y, boolean give_log) 
      static doublebrcomp(double a, double b, double x, double y, boolean log_p) 
      static doublebup(double a, double b, double x, double y, int n, double eps, boolean give_log) 
      static doublechebyshev_eval(double x, double[] a, int n)
      evaluate the n-term Chebyshev series "a" at "x".
      static doublechoose(double n, double k) 
      static doubleerf__(double x)
      ----------------------------------------------------------------------- EVALUATION OF THE REAL ERROR FUNCTION -----------------------------------------------------------------------
      static doubleerfc1(int ind, double x)
      ----------------------------------------------------------------------- EVALUATION OF THE COMPLEMENTARY ERROR FUNCTION ERFC1(IND,X) = ERFC(X) IF IND = 0 ERFC1(IND,X) = EXP(X*X)*ERFC(X) OTHERWISE -----------------------------------------------------------------------
      static doubleesum(int mu, double x, boolean give_log)
      ----------------------------------------------------------------------- EVALUATION OF EXP(MU + X) -----------------------------------------------------------------------
      static doubleexparg(int l)
      --------------------------------------------------------------------
      static doublefpser(double a, double b, double x, double eps, boolean log_p) 
      static doublegam1(double a)
      ------------------------------------------------------------------ COMPUTATION OF 1/GAMMA(A+1) - 1 FOR -0.5 <= A <= 1.5 ------------------------------------------------------------------
      static doublegamln(double a)
      ----------------------------------------------------------------------- Evaluation of ln(gamma(a)) for positive a ----------------------------------------------------------------------- Written by Alfred H.
      static doublegamln1(double a)
      ----------------------------------------------------------------------- EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 <= A <= 1.25 -----------------------------------------------------------------------
      static doublegamma_cody(double x)
      ---------------------------------------------------------------------- This routine calculates the GAMMA function for a float argument X.
      static doublegammafn(double x) 
      static intgcd(int m, int n)
      Find greatest common divisor of m and n
      static doublegrat_r(double a, double x, double log_r, double eps) 
      static doublegsumln(double a, double b)
      ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION LN(GAMMA(A + B)) FOR 1 <= A <= 2 AND 1 <= B <= 2 -----------------------------------------------------------------------
      static booleanisFinite(double x) 
      static booleanisInfinite(double x) 
      static doublelbeta(double a, double b) 
      static doublelchoose(double n, double k) 
      static doubleldexp(double x, double ex) 
      static doublelgamma1p(double a) 
      static doublelgammacor(double x) 
      static doublelgammafn_sign(double x, int[] sgn) 
      static doublelgammafn(double x) 
      static doublelmvgammafn(double a, int p)
      Log of multivariate gamma function By: Roby Joehanes
      static doublelog1pmx(double x) 
      static doublelog1px(double x)
      log1px takes a double and returns a double.
      static doublepd_lower_cf(double y, double d) 
      static doublepd_lower_series(double lambda, double y) 
      static doublepd_upper_series(double x, double y, boolean log_p) 
      static doublepsi(double x)
      --------------------------------------------------------------------- Evaluation of the Digamma function psi(x) ----------- Psi(xx) is assigned the value 0 when the digamma function cannot be computed.
      static doublerexpm1(double x)
      ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION EXP(X) - 1 -----------------------------------------------------------------------
      static doublerlog1(double x)
      ----------------------------------------------------------------------- Evaluation of the function x - ln(1 + x) -----------------------------------------------------------------------
      static doubleround(double val, int places)
      Rounding to desired num places
      static floatround(float val, int places) 
      static doublesignif(double val, int places)
      Mimicking R's signif
      static doublestirlerr(double n) 
      static doubletrunc(double x) 
    • Constructor Detail

      • MathFunctions

        public MathFunctions()
    • Method Detail

      • lmvgammafn

        public static final double lmvgammafn(double a,                int p)
        Log of multivariate gamma function By: Roby Joehanes
        Parameters:
        a -
        p - the order (or dimension)
        Returns:
        log multivariate gamma
      • trunc

        public static final double trunc(double x)
      • round

        public static final double round(double val,           int places)
        Rounding to desired num places
        Parameters:
        val -
        places -
        Returns:
        rounded number
      • round

        public static final float round(float val,          int places)
      • signif

        public static final double signif(double val,            int places)
        Mimicking R's signif
        Parameters:
        val -
        places -
        Returns:
        rounded values
      • gcd

        public static final int gcd(int m,      int n)
        Find greatest common divisor of m and n
        Parameters:
        m -
        n -
        Returns:
        GCD(m, n)
      • isFinite

        public static final boolean isFinite(double x)
      • isInfinite

        public static final boolean isInfinite(double x)
      • ldexp

        public static final double ldexp(double x,           double ex)
      • chebyshev_eval

        public static final double chebyshev_eval(double x,                    double[] a,                    int n)
        evaluate the n-term Chebyshev series "a" at "x".
        Parameters:
        x -
        a -
        n -
        Returns:
        Chebyshev function result
      • lgammacor

        public static final double lgammacor(double x)
      • lgammafn_sign

        public static final double lgammafn_sign(double x,                   int[] sgn)
      • lgammafn

        public static final double lgammafn(double x)
      • stirlerr

        public static final double stirlerr(double n)
      • gammafn

        public static final double gammafn(double x)
      • bd0

        public static final double bd0(double x,         double np)
      • lbeta

        public static final double lbeta(double a,           double b)
      • log1pmx

        public static final double log1pmx(double x)
      • log1px

        public static final double log1px(double x)
        log1px takes a double and returns a double. It is a Taylor series expansion of log(1+x). x is presumed to be < 1. As I have called it, x < .1, and so I know the algorithm will terminate quickly. The closer x is to 1, the slower this will be. (From AS 885)
      • lgamma1p

        public static final double lgamma1p(double a)
      • bratio

        public static final double[] bratio(double a,              double b,              double x,              double y,              boolean log_p)
        -----------------------------------------------------------------------              Evaluation of the Incomplete Beta function I_x(a,b)                       --------------------     It is assumed that a and b are nonnegative, and that x <= 1     and y = 1 - x.  Bratio assigns w and w1 the values                        w  = I_x(a,b)                        w1 = 1 - I_x(a,b)     ierr is a variable that reports the status of the results.     If no input errors are detected then ierr is set to 0 and     w and w1 are computed. otherwise, if an error is detected,     then w and w1 are assigned the value 0 and ierr is set to     one of the following values ...          ierr = 1  if a or b is negative          ierr = 2  if a = b = 0          ierr = 3  if x < 0 or x > 1          ierr = 4  if y < 0 or y > 1          ierr = 5  if x + y != 1          ierr = 6  if x = a = 0          ierr = 7  if y = b = 0          ierr = 8  "error" in bgrat() --------------------     Written by Alfred H. Morris, Jr.          Naval Surface Warfare Center          Dahlgren, Virginia     Revised ... Nov 1991 -----------------------------------------------------------------------
      • fpser

        public static final double fpser(double a,           double b,           double x,           double eps,           boolean log_p)
      • apser

        public static final double apser(double a,           double b,           double x,           double eps)
      • bpser

        public static final double bpser(double a,           double b,           double x,           double eps,           boolean log_p)
      • bup

        public static final double bup(double a,         double b,         double x,         double y,         int n,         double eps,         boolean give_log)
      • bfrac

        public static final double bfrac(double a,           double b,           double x,           double y,           double lambda,           double eps,           boolean log_p)
      • brcomp

        public static final double brcomp(double a,            double b,            double x,            double y,            boolean log_p)
      • brcmp1

        public static final double brcmp1(int mu,            double a,            double b,            double x,            double y,            boolean give_log)
      • bgrat

        public static final double bgrat(double a,           double b,           double x,           double y,           double w,           double eps,           boolean log_w)
      • grat_r

        public static final double grat_r(double a,            double x,            double log_r,            double eps)
      • basym

        public static final double basym(double a,           double b,           double lambda,           double eps,           boolean log_p)
      • exparg

        public static final double exparg(int l)
        --------------------------------------------------------------------
             IF L = 0 THEN  EXPARG(L) = THE LARGEST POSITIVE W FOR WHICH     EXP(W) CAN BE COMPUTED.     IF L IS NONZERO THEN  EXPARG(L) = THE LARGEST NEGATIVE W FOR     WHICH THE COMPUTED VALUE OF EXP(W) IS NONZERO.     NOTE... ONLY AN APPROXIMATE VALUE FOR EXPARG(L) IS NEEDED.  
        --------------------------------------------------------------------
      • esum

        public static final double esum(int mu,          double x,          boolean give_log)
        ----------------------------------------------------------------------- EVALUATION OF EXP(MU + X) -----------------------------------------------------------------------
      • rexpm1

        public static final double rexpm1(double x)
        ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION EXP(X) - 1 -----------------------------------------------------------------------
      • alnrel

        public static final double alnrel(double a)
        ----------------------------------------------------------------------- Evaluation of the function ln(1 + a) -----------------------------------------------------------------------
      • rlog1

        public static final double rlog1(double x)
        ----------------------------------------------------------------------- Evaluation of the function x - ln(1 + x) -----------------------------------------------------------------------
      • erf__

        public static final double erf__(double x)
        ----------------------------------------------------------------------- EVALUATION OF THE REAL ERROR FUNCTION -----------------------------------------------------------------------
      • erfc1

        public static final double erfc1(int ind,           double x)
        ----------------------------------------------------------------------- EVALUATION OF THE COMPLEMENTARY ERROR FUNCTION ERFC1(IND,X) = ERFC(X) IF IND = 0 ERFC1(IND,X) = EXP(X*X)*ERFC(X) OTHERWISE -----------------------------------------------------------------------
      • gam1

        public static final double gam1(double a)
        ------------------------------------------------------------------ COMPUTATION OF 1/GAMMA(A+1) - 1 FOR -0.5 <= A <= 1.5 ------------------------------------------------------------------
      • gamln1

        public static final double gamln1(double a)
        ----------------------------------------------------------------------- EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 <= A <= 1.25 -----------------------------------------------------------------------
      • psi

        public static final double psi(double x)
         ---------------------------------------------------------------------                 Evaluation of the Digamma function psi(x)                           -----------     Psi(xx) is assigned the value 0 when the digamma function cannot     be computed.     The main computation involves evaluation of rational Chebyshev     approximations published in Math. Comp. 27, 123-127(1973) by     Cody, Strecok and Thacher. ---------------------------------------------------------------------     Psi was written at Argonne National Laboratory for the FUNPACK     package of special function subroutines. Psi was modified by     A.H. Morris (NSWC). --------------------------------------------------------------------- 
      • betaln

        public static final double betaln(double a0,            double b0)
        ----------------------------------------------------------------------- Evaluation of the logarithm of the beta function ln(beta(a0,b0)) -----------------------------------------------------------------------
      • gsumln

        public static final double gsumln(double a,            double b)
        ----------------------------------------------------------------------- EVALUATION OF THE FUNCTION LN(GAMMA(A + B)) FOR 1 <= A <= 2 AND 1 <= B <= 2 -----------------------------------------------------------------------
      • bcorr

        public static final double bcorr(double a0,           double b0)
        ----------------------------------------------------------------------- EVALUATION OF DEL(A0) + DEL(B0) - DEL(A0 + B0) WHERE LN(GAMMA(A)) = (A - 0.5)*LN(A) - A + 0.5*LN(2*PI) + DEL(A). IT IS ASSUMED THAT A0 >= 8 AND B0 >= 8. -----------------------------------------------------------------------
      • algdiv

        public static final double algdiv(double a,            double b)
        ----------------------------------------------------------------------- COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B >= 8. IN THIS ALGORITHM, DEL(X) IS THE FUNCTION DEFINED BY LN(GAMMA(X)) = (X - 0.5)*LN(X) - X + 0.5*LN(2*PI) + DEL(X). -----------------------------------------------------------------------
      • gamln

        public static final double gamln(double a)
         -----------------------------------------------------------------------            Evaluation of  ln(gamma(a))  for positive a -----------------------------------------------------------------------     Written by Alfred H. Morris          Naval Surface Warfare Center          Dahlgren, Virginia ----------------------------------------------------------------------- 
      • beta

        public static final double beta(double a,          double b)
            This function returns the value of the beta function    evaluated with arguments a and b.  NOTES    This routine is a translation into C of a Fortran subroutine    by W. Fullerton of Los Alamos Scientific Laboratory.    Some modifications have been made so that the routines    conform to the IEEE 754 standard.
      • lchoose

        public static final double lchoose(double n,             double k)
      • choose

        public static final double choose(double n,            double k)
      • gamma_cody

        public static final double gamma_cody(double x)
         ----------------------------------------------------------------------           This routine calculates the GAMMA function for a float argument X.           Computation is based on an algorithm outlined in reference [1].           The program uses rational functions that approximate the GAMMA           function to at least 20 significant decimal digits.  Coefficients           for the approximation over the interval (1,2) are unpublished.           Those for the approximation for X >= 12 are from reference [2].           The accuracy achieved depends on the arithmetic system, the           compiler, the intrinsic functions, and proper selection of the           machine-dependent constants.           Error returns           The program returns the value XINF for singularities or           when overflow would occur.    The computation is believed           to be free of underflow and overflow.           Intrinsic functions required are:           INT, DBLE, EXP, LOG, REAL, SIN           References:           [1]  "An Overview of Software Development for Special Functions",                W. J. Cody, Lecture Notes in Mathematics, 506,                Numerical Analysis Dundee, 1975, G. A. Watson (ed.),                Springer Verlag, Berlin, 1976.           [2]  Computer Approximations, Hart, Et. Al., Wiley and sons, New York, 1968.           Latest modification: October 12, 1989           Authors: W. J. Cody and L. Stoltz           Applied Mathematics Division           Argonne National Laboratory           Argonne, IL 60439           ----------------------------------------------------------------------
      • pd_upper_series

        public static final double pd_upper_series(double x,                     double y,                     boolean log_p)
      • pd_lower_cf

        public static final double pd_lower_cf(double y,                 double d)
      • pd_lower_series

        public static final double pd_lower_series(double lambda,                     double y)
      • _expm1

        public static final double _expm1(double x)
        Alternative expm1 -- no difference from Java's
        Parameters:
        x -
        Returns:
        expm1
      • _log1p

        public static final double _log1p(double x)
        Alternative log1p. No difference from Java's.
        Parameters:
        x -
        Returns:
        log1p

SCaVis 1.8 © jWork.org