예제 #1
0
    private static void geometric_cdf_test()

//****************************************************************************80
//
//  Purpose:
//
//    GEOMETRIC_CDF_TEST tests GEOMETRIC_CDF.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    27 January 2007
//
//  Author:
//
//    John Burkardt
//
    {
        int i;
        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("GEOMETRIC_CDF_TEST");
        Console.WriteLine("  GEOMETRIC_CDF evaluates the Geometric CDF;");
        Console.WriteLine("  GEOMETRIC_CDF_INV inverts the Geometric CDF.");
        Console.WriteLine("  GEOMETRIC_PDF evaluates the Geometric PDF;");

        const double a = 0.25E+00;

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter A =             " + a + "");

        if (!Geometric.geometric_check(a))
        {
            Console.WriteLine("");
            Console.WriteLine("GEOMETRIC_CDF_TEST - Fatal error!");
            Console.WriteLine("  The parameters are not legal.");
            return;
        }

        Console.WriteLine("");
        Console.WriteLine("       X            PDF           CDF            CDF_INV");
        Console.WriteLine("");

        for (i = 1; i <= 10; i++)
        {
            int    x   = Geometric.geometric_sample(a, ref seed);
            double pdf = Geometric.geometric_pdf(x, a);
            double cdf = Geometric.geometric_cdf(x, a);
            int    x2  = Geometric.geometric_cdf_inv(cdf, a);

            Console.WriteLine("  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + x2.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }