Example: The Special Functions

Various special functions are exercised. Their use in this example typifies the manner in which other special functions in the Sfun class would be used.

import com.imsl.math.*;

public class SfunEx1 {

    public static void main(String args[]) {
        double result;

        // Log base 10 of x
        double x = 100.;
        result = Sfun.log10(x);
        System.out.println("The log base 10 of 100. is " + result);

        // Factorial of 10
        int n = 10;
        result = Sfun.fact(n);
        System.out.println("10 factorial is " + result);

        // Gamma of 5.0
        double x1 = 5.;
        result = Sfun.gamma(x1);
        System.out.println("The Gamma function at 5.0 is " + result);

        // LogGamma of 1.85
        double x2 = 1.85;
        result = Sfun.logGamma(x2);
        System.out.println("The logarithm of the absolute value of the "
                + "Gamma function \n    at 1.85 is " + result);

        // Beta of (2.2, 3.7)
        double a = 2.2;
        double b = 3.7;
        result = Sfun.beta(a, b);
        System.out.println("Beta(2.2, 3.7) is " + result);

        // LogBeta of (2.2, 3.7)
        double a1 = 2.2;
        double b1 = 3.7;
        result = Sfun.logBeta(a1, b1);
        System.out.println("logBeta(2.2, 3.7) is " + result);
    }
}

Output

The log base 10 of 100. is 2.0
10 factorial is 3628800.0
The Gamma function at 5.0 is 24.0
The logarithm of the absolute value of the Gamma function 
    at 1.85 is -0.05592381301965721
Beta(2.2, 3.7) is 0.045375983484708095
logBeta(2.2, 3.7) is -3.0927723120378947
Link to Java source.