Class Gamma


  • public class Gamma
    extends java.lang.Object

    This code calculates the gamma function of an input argument x.

    A typical usage would be:

     double result[] = new double[1];
     Gamma gammaTest = new Gamma(5.0, result);
     gammaTest.run();
     Preferences.debug("Gamma(5.0) = " + result[0] + "\n");
     UI.setDataText("Gamma(5.0) = " + result[0] + "\n");
     


    The FORTRAN code this class is based upon is from Computation of Special Functions by Shanjie Zhang and Jianming Jin and copyright 1996 John Wiley & Sons, Inc.

    From the diskette that the FORTRAN code came on:

     DISCLAIMER OF WARRANTY
     
     Although we have made a great effort to test and validate the 
     computer programs, we make no warranties, express or implied, that 
     these  programs  are  free  of  error,  or are consistent with any 
     particular  standard  of  merchantability,  or that they will meet 
     your requirements for any particular application.  They should not 
     be relied on for  solving problems  whose incorrect solution could 
     result in  injury to  a person or loss of property.  If you do use 
     the programs in such a manner, it is at your own risk. The authors 
     and publisher  disclaim all liability for  direct or consequential 
     damages resulting from your use of the programs.
     

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double a  
      private double b  
      static int CDF  
      static int CGAMMA
      Compute gamma function or log of gamma function for complex arguments
      private int functionCode
      In lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0
      static int GAMMA
      Compute gamma function for real x, x is not equal to 0 or a negative integer
      private double[] imagResult
      Imaginary part of outputted result
      private double imagX
      Imaginary part of input argument
      static int INCOG
      Compute incompete gamma functions and regularized gamma P function
      static int INVERSE_CDF  
      static int LGAMMA
      Compute gamma function or log of gamma function for real x > 0
      private double[] lowerIncompleteGamma  
      private double[] realResult
      Real part of outputted result
      private double realX
      Real part of input argument
      private double[] regularizedGammaP  
      private double[] result
      output result
      private double[] upperIncompleteGamma  
      private int version
      GAMMA, LGAMMA, CGAMMA, or INCOG
      private double x
      input argument Note that the gamma function is not defined for x equal to zero or a negative integer
    • Constructor Summary

      Constructors 
      Constructor Description
      Gamma()  
      Gamma​(double x, double[] result)  
      Gamma​(double a, double x, double[] lowerIncompleteGamma, double[] upperIncompleteGamma, double[] regularizedGammaP)  
      Gamma​(double a, double b, double x, boolean inverse, double[] result)  
      Gamma​(double realX, double imagX, int functionCode, double[] realResult, double[] imagResult)  
      Gamma​(double x, int functionCode, double[] result)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void cdf()  
      private void cgamma()
      This code is a port of the FORTRAN routine CGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 51-52.
      void finalize()
      Cleanup memory.
      private void gamma()
      This code is a port of the FORTRAN routine GAMMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 49-50.
      private void incog()
      This code is a port of the FORTRAN routine INCOG from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 63-64.
      private void inverseCumulativeDistributionFunction()  
      private void lgamma()
      This code is a port of the FORTRAN routine LGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 50-51.
      void run()  
      void testCDF()  
      void testcgamma()  
      void testgamma()  
      void testincog()  
      void testInverseCDF()  
      void testlgamma()  
      • Methods inherited from class java.lang.Object

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

      • GAMMA

        public static final int GAMMA
        Compute gamma function for real x, x is not equal to 0 or a negative integer
        See Also:
        Constant Field Values
      • LGAMMA

        public static final int LGAMMA
        Compute gamma function or log of gamma function for real x > 0
        See Also:
        Constant Field Values
      • CGAMMA

        public static final int CGAMMA
        Compute gamma function or log of gamma function for complex arguments
        See Also:
        Constant Field Values
      • INCOG

        public static final int INCOG
        Compute incompete gamma functions and regularized gamma P function
        See Also:
        Constant Field Values
      • x

        private double x
        input argument Note that the gamma function is not defined for x equal to zero or a negative integer
      • realX

        private double realX
        Real part of input argument
      • imagX

        private double imagX
        Imaginary part of input argument
      • functionCode

        private int functionCode
        In lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0
      • result

        private double[] result
        output result
      • realResult

        private double[] realResult
        Real part of outputted result
      • imagResult

        private double[] imagResult
        Imaginary part of outputted result
      • version

        private int version
        GAMMA, LGAMMA, CGAMMA, or INCOG
      • a

        private double a
      • b

        private double b
      • lowerIncompleteGamma

        private double[] lowerIncompleteGamma
      • upperIncompleteGamma

        private double[] upperIncompleteGamma
      • regularizedGammaP

        private double[] regularizedGammaP
    • Constructor Detail

      • Gamma

        public Gamma()
      • Gamma

        public Gamma​(double x,
                     double[] result)
        Parameters:
        x - Input argument
        result - outputted gamma(x)
      • Gamma

        public Gamma​(double x,
                     int functionCode,
                     double[] result)
        Parameters:
        x - input argument, must have x > 0
        functionCode - 1 for gamma(x), 0 for ln(gamma(x))
        result - outputted gamma(x) or ln(gamma(x))
      • Gamma

        public Gamma​(double realX,
                     double imagX,
                     int functionCode,
                     double[] realResult,
                     double[] imagResult)
        Parameters:
        realX - real part of input argument
        imagX - imaginary part of input argument
        functionCode - 1 for gamma(x),0 for ln(gamma(x))
        realResult - real part of outputted gamma(x) or ln(gamma(x))
        imagResult - imaginary part of outputted gamma(x) or ln(gamma(x))
      • Gamma

        public Gamma​(double a,
                     double x,
                     double[] lowerIncompleteGamma,
                     double[] upperIncompleteGamma,
                     double[] regularizedGammaP)
        Parameters:
        a -
        x -
        lowerIncompleteGamma -
        upperIncompleteGamma -
        regularizedGammaP -
      • Gamma

        public Gamma​(double a,
                     double b,
                     double x,
                     boolean inverse,
                     double[] result)
    • Method Detail

      • finalize

        public void finalize()
                      throws java.lang.Throwable
        Cleanup memory.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable - DOCUMENT ME!
      • testInverseCDF

        public void testInverseCDF()
      • testCDF

        public void testCDF()
      • testgamma

        public void testgamma()
      • testlgamma

        public void testlgamma()
      • testcgamma

        public void testcgamma()
      • testincog

        public void testincog()
      • run

        public void run()
      • inverseCumulativeDistributionFunction

        private void inverseCumulativeDistributionFunction()
      • cdf

        private void cdf()
      • gamma

        private void gamma()
        This code is a port of the FORTRAN routine GAMMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 49-50. x is not 0 or a negative integer
      • lgamma

        private void lgamma()
        This code is a port of the FORTRAN routine LGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 50-51. This routine calculates the gamma(x) for functionCode = 1 or the ln(gamma(x)) for the function code = 0. x must be greater than zero.
      • cgamma

        private void cgamma()
        This code is a port of the FORTRAN routine CGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 51-52. This routine calculates the gamma(x) for functionCode = 1 or the ln(gamma(x)) for the function code = 0. x is complex and the output is complex.
      • incog

        private void incog()
        This code is a port of the FORTRAN routine INCOG from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley & Sons, Inc., 1996, pp. 63-64. It calculates the incomplete gamma functions and the regularized gamma function P.