Example #1
0
    private static void reciprocal_cdf_test()

//****************************************************************************80
//
//  Purpose:
//
//    RECIPROCAL_CDF_TEST tests RECIPROCAL_CDF.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    29 March 2016
//
//  Author:
//
//    John Burkardt
//
    {
        int i;
        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("RECIPROCAL_CDF_TEST");
        Console.WriteLine("  RECIPROCAL_CDF evaluates the Reciprocal CDF;");
        Console.WriteLine("  RECIPROCAL_CDF_INV inverts the Reciprocal CDF.");
        Console.WriteLine("  RECIPROCAL_PDF evaluates the Reciprocal PDF;");

        const double a = 1.0;
        const double b = 3.0;

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

        if (!Reciprocal.reciprocal_check(a, b))
        {
            Console.WriteLine("");
            Console.WriteLine("RECIPROCAL_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++)
        {
            double x   = Reciprocal.reciprocal_sample(a, b, ref seed);
            double pdf = Reciprocal.reciprocal_pdf(x, a, b);
            double cdf = Reciprocal.reciprocal_cdf(x, a, b);
            double x2  = Reciprocal.reciprocal_cdf_inv(cdf, a, b);

            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) + "");
        }
    }