public class MathFunctions
extends java.lang.Object
Constructor and Description |
---|
MathFunctions() |
Modifier and Type | Method and Description |
---|---|
static double |
_expm1(double x)
Alternative expm1 -- no difference from Java's
|
static double |
_log1p(double x)
Alternative log1p.
|
static double |
algdiv(double a,
double b)
-----------------------------------------------------------------------
COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B >= 8.
|
static double |
alnrel(double a)
-----------------------------------------------------------------------
Evaluation of the function ln(1 + a)
-----------------------------------------------------------------------
|
static double |
apser(double a,
double b,
double x,
double eps) |
static double |
basym(double a,
double b,
double lambda,
double eps,
boolean log_p) |
static 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).
|
static double |
bd0(double x,
double np) |
static double |
beta(double a,
double b)
This function returns the value of the beta function
evaluated with arguments a and b.
|
static double |
betaln(double a0,
double b0)
-----------------------------------------------------------------------
Evaluation of the logarithm of the beta function ln(beta(a0,b0))
-----------------------------------------------------------------------
|
static double |
bfrac(double a,
double b,
double x,
double y,
double lambda,
double eps,
boolean log_p) |
static double |
bgrat(double a,
double b,
double x,
double y,
double w,
double eps,
int[] ierr,
boolean log_w) |
static double |
bpser(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 double |
brcmp1(int mu,
double a,
double b,
double x,
double y,
boolean give_log) |
static double |
brcomp(double a,
double b,
double x,
double y,
boolean log_p) |
static double |
bup(double a,
double b,
double x,
double y,
int n,
double eps,
boolean give_log) |
static double |
chebyshev_eval(double x,
double[] a,
int n)
evaluate the n-term Chebyshev series "a" at "x".
|
static double |
choose(double n,
double k) |
static double |
cospi(double x) |
static double |
erf__(double x)
-----------------------------------------------------------------------
EVALUATION OF THE REAL ERROR FUNCTION
-----------------------------------------------------------------------
|
static 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
-----------------------------------------------------------------------
|
static double |
esum(int mu,
double x,
boolean give_log)
-----------------------------------------------------------------------
EVALUATION OF EXP(MU + X)
-----------------------------------------------------------------------
|
static double |
exparg(int l)
--------------------------------------------------------------------
|
static double |
fpser(double a,
double b,
double x,
double eps,
boolean log_p) |
static double |
frexp(double x,
int[] i)
Implementation of frexp
|
static double |
gam1(double a)
------------------------------------------------------------------
COMPUTATION OF 1/GAMMA(A+1) - 1 FOR -0.5 <= A <= 1.5
------------------------------------------------------------------
|
static double |
gamln(double a)
-----------------------------------------------------------------------
Evaluation of ln(gamma(a)) for positive a
-----------------------------------------------------------------------
Written by Alfred H.
|
static double |
gamln1(double a)
-----------------------------------------------------------------------
EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 <= A <= 1.25
-----------------------------------------------------------------------
|
static double |
gamma_cody(double x)
----------------------------------------------------------------------
This routine calculates the GAMMA function for a float argument X.
|
static double |
gammafn(double x) |
static double[] |
gammafn(double[] x)
Batch call gamma function
|
static int |
gcd(int m,
int n)
Find greatest common divisor of m and n
|
static double |
gharmonic(int n)
Calculate harmonic number
|
static double |
gharmonic(int n,
double s) |
static double |
gharmonic(int n,
double s,
double logexponent)
Calculate generalized harmonic number
|
static double |
grat_r(double a,
double x,
double log_r,
double eps) |
static double |
gsumln(double a,
double b)
-----------------------------------------------------------------------
EVALUATION OF THE FUNCTION LN(GAMMA(A + B))
FOR 1 <= A <= 2 AND 1 <= B <= 2
-----------------------------------------------------------------------
|
static boolean |
isFinite(double x) |
static boolean |
isInfinite(double x) |
static boolean |
isNonInt(double x) |
static double |
lbeta(double a,
double b) |
static double |
lchoose(double n,
double k) |
static double |
ldexp(double x,
double ex) |
static double |
ldexp(double x,
int p)
Implementation of ldexp
|
static double |
lgamma1p(double a) |
static double |
lgammacor(double x) |
static double |
lgammafn_sign(double x,
int[] sgn) |
static double |
lgammafn(double x) |
static double[] |
lgammafn(double[] x)
Batch call log gamma function
|
static double |
lgharmonic(int n) |
static double |
lgharmonic(int n,
double s) |
static double |
lgharmonic(int n,
double s,
double logexponent)
Calculate the log of generalized harmonic number
|
static double |
lmvgammafn(double a,
int p)
Log of multivariate gamma function
By: Roby Joehanes
|
static double |
log1pmx(double x) |
static double |
log1px(double x)
log1px takes a double and returns a double.
|
static double |
logspace_add(double logx,
double logy)
Compute the log of a sum from logs of terms, i.e.,
log (exp (logx) + exp (logy))
without causing overflows and without throwing away large handfuls
of accuracy.
|
static double |
logspace_sub(double logx,
double logy)
Compute the log of a difference from logs of terms, i.e.,
log (exp (logx) - exp (logy))
without causing overflows and without throwing away large handfuls
of accuracy.
|
static double |
logspace_sum(double[] logx) |
static double |
pd_lower_cf(double y,
double d) |
static double |
pd_lower_series(double lambda,
double y) |
static double |
pd_upper_series(double x,
double y,
boolean log_p) |
static 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.
|
static double |
rexpm1(double x)
-----------------------------------------------------------------------
EVALUATION OF THE FUNCTION EXP(X) - 1
-----------------------------------------------------------------------
|
static double |
rlog1(double x)
-----------------------------------------------------------------------
Evaluation of the function x - ln(1 + x)
-----------------------------------------------------------------------
|
static double |
round(double val,
int places)
Rounding to desired num places
|
static float |
round(float val,
int places) |
static double |
signif(double val,
int places)
Mimicking R's signif
|
static double |
sinc(double x)
Compute sinc(x) = sin(x)/x for x != 0.
|
static double |
sinpi(double x) |
static double |
stirlerr(double n) |
static double |
tanpi(double x) |
static double |
trunc(double x) |
public static final double lmvgammafn(double a, int p)
a
- p
- the order (or dimension)public static final double trunc(double x)
public static final double round(double val, int places)
val
- places
- public static final float round(float val, int places)
public static final double signif(double val, int places)
val
- places
- public static final int gcd(int m, int n)
m
- n
- public static final double sinc(double x)
x
- public static final boolean isFinite(double x)
public static final boolean isInfinite(double x)
public static final double ldexp(double x, double ex)
public static final double chebyshev_eval(double x, double[] a, int n)
x
- a
- n
- public static final double lgammacor(double x)
public static final double lgammafn_sign(double x, int[] sgn)
public static final double lgammafn(double x)
public static final double[] lgammafn(double[] x)
x
- public static final double stirlerr(double n)
public static final double gammafn(double x)
public static final double[] gammafn(double[] x)
x
- public static final double bd0(double x, double np)
public static final double lbeta(double a, double b)
public static final double log1pmx(double x)
public static final double log1px(double x)
public static final double lgamma1p(double a)
public static final double logspace_add(double logx, double logy)
public static final double logspace_sub(double logx, double logy)
public static final double logspace_sum(double[] logx)
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 (not used currently) ierr = 9 NaN in a, b, x, or y ierr = 10 (not used currently) ierr = 11 bgrat() error code 1 [+ warning in bgrat()] ierr = 12 bgrat() error code 2 (no warning here) ierr = 13 bgrat() error code 3 (no warning here) ierr = 14 bgrat() error code 4 [+ WARNING in bgrat()] -------------------- Written by Alfred H. Morris, Jr. Naval Surface Warfare Center Dahlgren, Virginia Revised ... Nov 1991 -----------------------------------------------------------------------
public static final double fpser(double a, double b, double x, double eps, boolean log_p)
public static final double apser(double a, double b, double x, double eps)
public static final double bpser(double a, double b, double x, double eps, boolean log_p)
public static final double bup(double a, double b, double x, double y, int n, double eps, boolean give_log)
public static final double bfrac(double a, double b, double x, double y, double lambda, double eps, boolean log_p)
public static final double brcomp(double a, double b, double x, double y, boolean log_p)
public static final double brcmp1(int mu, double a, double b, double x, double y, boolean give_log)
public static final double bgrat(double a, double b, double x, double y, double w, double eps, int[] ierr, boolean log_w)
public static final double grat_r(double a, double x, double log_r, double eps)
public static final double basym(double a, double b, double lambda, double eps, boolean log_p)
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.--------------------------------------------------------------------
public static final double esum(int mu, double x, boolean give_log)
public static final double rexpm1(double x)
public static final double alnrel(double a)
public static final double rlog1(double x)
public static final double erf__(double x)
public static final double erfc1(int ind, double x)
public static final double gam1(double a)
public static final double gamln1(double a)
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). ---------------------------------------------------------------------
public static final double betaln(double a0, double b0)
public static final double gsumln(double a, double b)
public static final double bcorr(double a0, double b0)
public static final double algdiv(double a, double b)
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 -----------------------------------------------------------------------
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.
public static final double lchoose(double n, double k)
public static final double choose(double n, double k)
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 ----------------------------------------------------------------------
public static final double pd_upper_series(double x, double y, boolean log_p)
public static final double pd_lower_cf(double y, double d)
public static final double pd_lower_series(double lambda, double y)
public static final double _expm1(double x)
x
- public static final double _log1p(double x)
x
- public static final double gharmonic(int n)
n
- must be positivepublic static final double gharmonic(int n, double s)
public static final double gharmonic(int n, double s, double logexponent)
n
- must be positives
- logexponent
- public static final double lgharmonic(int n)
public static final double lgharmonic(int n, double s)
public static final double lgharmonic(int n, double s, double logexponent)
n
- must be positives
- logexponent
- public static final double cospi(double x)
public static final double sinpi(double x)
public static final double tanpi(double x)
public static final double frexp(double x, int[] i)
x
- i
- an array of 1 elementpublic static final double ldexp(double x, int p)
x
- p
- public static final boolean isNonInt(double x)