/// <summary>
 /// This function return the cummulative distribution function (CDF)
 /// for ChiSquare Distribution where X2 from 0 t x2 and
 /// number degree of freedom k.
 /// </summary>
 /// <param name="x2">double. x2</param>
 /// <param name="k">int. k is number degree of freedom</param>
 /// <returns>
 /// The value of cummulative distribution function (CDF)
 /// for ChiSquare Distribution where X2 form 0 t x2 and
 /// number degree of freedom k.
 /// </returns>
 public static double CDF(double x2, int k)
 {
     // the number degree of freedom must be
     // more or equal than 1. The value of x must be
     // not less than 0
     if (k < 1 || x2 < 0) return double.NaN;
     ChiSquareFunction function = new ChiSquareFunction(k);
     return Integrator.GaussLegendre(function, 0, x2, 1.0e-6);
 }
        /// <summary>
        /// This function return the probability density function (PDF)
        /// for ChiSquare Distribution for X2=x2 and
        /// number degree of freedom k.
        /// </summary>
        /// <param name="x2">double. x2</param>
        /// <param name="k">int. k is number degree of freedom</param>
        /// <returns>
        /// The value of probability distribution function (PDF)
        /// for ChiSquare Distribution for X2=x2 and
        /// number degree of freedom k.
        /// </returns>
        private static double PDF(double x2, int k)
        {
            // the number degree of freedom must be
            // more or equal than 1. The value of x must be
            // not less than 0
            if (k < 1 || x2 < 0)
            {
                return(double.NaN);
            }
            ChiSquareFunction function = new ChiSquareFunction(k);

            return(function.Value(x2));
        }
        /// <summary>
        /// This function return the cummulative distribution function (CDF)
        /// for ChiSquare Distribution where X2 from 0 t x2 and
        /// number degree of freedom k.
        /// </summary>
        /// <param name="x2">double. x2</param>
        /// <param name="k">int. k is number degree of freedom</param>
        /// <returns>
        /// The value of cummulative distribution function (CDF)
        /// for ChiSquare Distribution where X2 form 0 t x2 and
        /// number degree of freedom k.
        /// </returns>
        public static double CDF(double x2, int k)
        {
            // the number degree of freedom must be
            // more or equal than 1. The value of x must be
            // not less than 0
            if (k < 1 || x2 < 0)
            {
                return(double.NaN);
            }
            ChiSquareFunction function = new ChiSquareFunction(k);

            return(Integrator.GaussLegendre(function, 0, x2, 1.0e-6));
        }
 /// <summary>
 /// This function return the probability density function (PDF)
 /// for ChiSquare Distribution for X2=x2 and
 /// number degree of freedom k.
 /// </summary>
 /// <param name="x2">double. x2</param>
 /// <param name="k">int. k is number degree of freedom</param>
 /// <returns>
 /// The value of probability distribution function (PDF)
 /// for ChiSquare Distribution for X2=x2 and
 /// number degree of freedom k.
 /// </returns>
 private static double PDF(double x2, int k)
 {
     // the number degree of freedom must be
     // more or equal than 1. The value of x must be
     // not less than 0
     if (k < 1 || x2 < 0) return double.NaN;
     ChiSquareFunction function = new ChiSquareFunction(k);
     return function.Value(x2);
 }