JMSLTM Numerical Library 7.2.0
com.imsl.math

## Class Sfun

• ```public class Sfun
extends Object```
Collection of special functions.
Example
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `EPSILON_LARGE`
The largest relative spacing for doubles.
`static double` `EPSILON_SMALL`
The smallest relative spacing for doubles.
• ### Method Summary

Methods
Modifier and Type Method and Description
`static double` ```beta(double a, double b)```
Returns the value of the beta function.
`static double` ```betaIncomplete(double x, double p, double q)```
Returns the incomplete beta function ratio.
`static double` `cot(double x)`
Returns the cotangent of a `double`.
`static double` `erf(double x)`
Returns the error function of a `double`.
`static double` `erfc(double x)`
Returns the complementary error function of a `double`.
`static double` `erfce(double x)`
Returns the exponentially scaled complementary error function.
`static double` `erfcInverse(double x)`
Returns the inverse of the complementary error function.
`static double` `erfInverse(double x)`
Returns the inverse of the error function.
`static double` `fact(int n)`
Returns the factorial of an integer.
`static double` `gamma(double x)`
Returns the Gamma function of a `double`.
`static double` ```gammaIncomplete(double a, double x)```
Evaluates the incomplete gamma function.
`static double` `log10(double x)`
Returns the common (base 10) logarithm of a `double`.
`static double` ```logBeta(double a, double b)```
Returns the logarithm of the beta function.
`static double` `logGamma(double x)`
Returns the logarithm of the absolute value of the Gamma function.
`static double` ```poch(double a, double x)```
Returns a generalization of Pochhammer's symbol.
`static double` `psi(double x)`
Returns the derivative of the log gamma function, also called the digamma function.
`static double` `psi1(double x)`
Returns the function, also known as the trigamma function.
`static double` ```sign(double x, double y)```
Returns the value of x with the sign of y.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### EPSILON_LARGE

`public static final double EPSILON_LARGE`
The largest relative spacing for doubles.
Constant Field Values
• #### EPSILON_SMALL

`public static final double EPSILON_SMALL`
The smallest relative spacing for doubles.
Constant Field Values
• ### Method Detail

• #### beta

```public static double beta(double a,
double b)```
Returns the value of the beta function. The beta function is defined to be See `gamma(double)` for the definition of .

The method `beta` requires that both arguments be positive.

Parameters:
`a` - a `double` value
`b` - a `double` value
Returns:
a `double` value specifying the Beta function
Example
• #### betaIncomplete

```public static double betaIncomplete(double x,
double p,
double q)```
Returns the incomplete beta function ratio. The incomplete beta function is defined to be See `beta(double, double)` for the definition of .

The parameters p and q must both be greater than zero. The argument x must lie in the range 0 to 1. The incomplete beta function can underflow for sufficiently small x and large p; however, this underflow is not reported as an error. Instead, the value zero is returned as the function value.

The method `betaIncomplete` is based on the work of Bosten and Battiste (1974).

Parameters:
`x` - a `double` value specifying the upper limit of integration. It must be in the interval [0,1] inclusive.
`p` - a `double` value specifying the first Beta parameter. It must be positive.
`q` - a `double` value specifying the second Beta parameter. It must be positive.
Returns:
a `double` value specifying the incomplete Beta function ratio
Example
• #### cot

`public static double cot(double x)`
Returns the cotangent of a `double`.
Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the cotangent of x. If x is NaN, the result is NaN.
• #### erf

`public static double erf(double x)`
Returns the error function of a `double`.

The error function method, `erf`(x), is defined to be All values of x are legal. Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the error function of x
Example
• #### erfc

`public static double erfc(double x)`
Returns the complementary error function of a `double`.

The complementary error function method, `erfc` (x), is defined to be The argument x must not be so large that the result underflows. Approximately, x should be less than where s = `Double.MIN_VALUE` is the smallest representable positive floating-point number. Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the complementary error function of x
Example
• #### erfce

`public static double erfce(double x)`
Returns the exponentially scaled complementary error function.

The exponentially scaled complementary error function is defined as where erfc(x) is the complementary error function. See `erfc(double)` for its definition.

To prevent the answer from underflowing, x must be greater than where b = `Double.MAX_VALUE` is the largest representable double precision number.

Parameters:
`x` - a `double` value for which the function value is desired.
Returns:
a `double` value specifying the exponentially scaled complementary error function of `x`.
• #### erfcInverse

`public static double erfcInverse(double x)`
Returns the inverse of the complementary error function.

The `erfcinverse` method computes the inverse of the complementary error function erfc x, defined in `erfc`.

`erfcinverse(x)` is defined for . If , then the answer will be less accurate than half precision. Very approximately, where = machine precision (approximately 1.11e-16). Parameters:
`x` - a `double` value, .
Returns:
a `double` value specifying the inverse of the error function of `x`.
Example
• #### erfInverse

`public static double erfInverse(double x)`
Returns the inverse of the error function.

The `erfInverse` method computes the inverse of the error function erf x, defined in `erf(double)`.

The method `erfInverse(x)` is defined for , then the answer will be less accurate than half precision. Very approximately, where is the machine precision (approximately 1.11e-16). Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the inverse of the error function of `x`.
Example
• #### fact

`public static double fact(int n)`
Returns the factorial of an integer.
Parameters:
`n` - an `int` value
Returns:
a `double` value specifying the factorial of n, n!. If n is negative, the result is NaN.
• #### gamma

`public static double gamma(double x)`
Returns the Gamma function of a `double`.

The gamma function, , is defined to be For , the above definition is extended by analytic continuation.

The gamma function is not defined for integers less than or equal to zero. Also, the argument x must be greater than -170.56 so that does not underflow, and x must be less than 171.64 so that does not overflow. The underflow limit occurs first for arguments that are close to large negative half integers. Even though other arguments away from these half integers may yield machine-representable values of , such arguments are considered illegal. Users who need such values should use the log gamma. Finally, the argument should not be so close to a negative integer that the result is less accurate than half precision. Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the Gamma function of `x`. If `x` is a negative integer, the result is NaN.
Example
• #### gammaIncomplete

```public static double gammaIncomplete(double a,
double x)```
Evaluates the incomplete gamma function.

The lower limit of integration of the incomplete gamma function, , is defined to be Although is well defined for , this algorithm does not calculate for negative x. For large a and sufficiently large x, may overflow. is bounded by , and users may find this bound a useful guide in determining legal values for a.

Note that the upper limit of integration of the incomplete gamma, , is defined to be Therefore, by definition, the two incomplete gamma function forms satisfy the relationship Parameters:
`a` - a `double` value representing the integrand exponent parameter of the incomplete gamma function. It must be positive.
`x` - a `double` value specifying the point at which the incomplete gamma function is to be evaluated. It must be nonnegative.
Returns:
a `double` value specifying the incomplete gamma function.
• #### log10

`public static double log10(double x)`
Returns the common (base 10) logarithm of a `double`.
Parameters:
`x` - a `double` value
Returns:
a `double` value specifying the common logarithm of `x`.
• #### logBeta

```public static double logBeta(double a,
double b)```
Returns the logarithm of the beta function.

Method `logBeta` computes . See `beta(double, double)` for the definition of .

`logBeta` is defined for a 0 and b 0. It returns accurate results even when a or b is very small. It can overflow for very large arguments; this error condition is not detected except by the computer hardware.

Parameters:
`a` - a `double` value
`b` - a `double` value
Returns:
a `double` value specifying the natural logarithm of the beta function.
Example
• #### logGamma

`public static double logGamma(double x)`
Returns the logarithm of the absolute value of the Gamma function.

Method `logGamma` computes . See `gamma(double)` for the definition of .

The gamma function is not defined for integers less than or equal to zero. Also, must not be so large that the result overflows. Neither should x be so close to a negative integer that the accuracy is worse than half precision. Parameters:
`x` - a `double` value
Returns:
a `double`, the natural logarithm of the Gamma function of `x`. If x is a negative integer, the result is NaN.
Example
• #### poch

```public static double poch(double a,
double x)```
Returns a generalization of Pochhammer's symbol.

Method `poch` evaluates Pochhammer's symbol for n a nonnegative integer. Pochhammer's generalized symbol is defined to be See `gamma(double)` for the definition of .

Note that a straightforward evaluation of Pochhammer's generalized symbol with either gamma or log gamma functions can be especially unreliable when a is large or x is small.

Substantial loss can occur if a + x or a are close to a negative integer unless is sufficiently small. To insure that the result does not overflow or underflow, one can keep the arguments a and a + x well within the range dictated by the gamma function method gamma or one can keep small whenever a is large. `poch` also works for a variety of arguments outside these rough limits, but any more general limits that are also useful are difficult to specify.

Parameters:
`a` - a `double` value specifying the first argument
`x` - a `double` value specifying the second, differential argument
Returns:
a `double` value specifying the generalized Pochhammer symbol, Example
• #### psi

`public static double psi(double x)`
Returns the derivative of the log gamma function, also called the digamma function.

The psi function is defined to be See `gamma(double)` for the definition of .

The argument x must not be exactly zero or a negative integer, or is undefined. Also, x must not be too close to a negative integer such that the accuracy of the result is less than half precision.

Parameters:
`x` - a `double` value, the point at which the digamma function is to be evaluated.
Returns:
a `double` value specifying the logarithmic derivative of the gamma function of x. If x is a zero or a negative integer, the result is NaN. If x is too close to a negative integer the accuracy of the result will be less than half precision.
Example
• #### psi1

`public static double psi1(double x)`
Returns the function, also known as the trigamma function.

The trigamma function, , is defined to be The trigamma function is not defined for integers less than or equal to zero.

Parameters:
`x` - a `double` value, the point at which the trigamma function is to be evaluated.
Returns:
a `double` value specifying the trigamma function of x. If x is a negative integer or zero, the result is NaN.
Example
• #### sign

```public static double sign(double x,
double y)```
Returns the value of x with the sign of y.
Parameters:
`x` - a `double` value
`y` - a `double` value
Returns:
a `double` value specifying the absolute value of `x` and the sign of `y`.
JMSLTM Numerical Library 7.2.0