Example #1
0
    public static double half_normal_cdf_inv(double cdf, double a, double b)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    HALF_NORMAL_CDF_INV inverts the Half Normal CDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    17 October 2004
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double CDF, the value of the CDF.
    //    0.0 <= CDF <= 1.0.
    //
    //    Input, double A, B, the parameters of the PDF.
    //    0.0 < B.
    //
    //    Output, double HALF_NORMAL_CDF_INV, the corresponding argument.
    //
    {
        switch (cdf)
        {
        case < 0.0:
        case > 1.0:
            Console.WriteLine(" ");
            Console.WriteLine("HALF_NORMAL_CDF_INV - Fatal error!");
            Console.WriteLine("  CDF < 0 or 1 < CDF.");
            return(1);
        }

        double cdf2 = 0.5 * (cdf + 1.0);

        double x = CDF.normal_cdf_inv(cdf2, a, b);

        return(x);
    }
Example #2
0
    private static void normal_cdf_test()

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

        Console.WriteLine("");
        Console.WriteLine("NORMAL_CDF_TEST");
        Console.WriteLine("  NORMAL_CDF evaluates the Normal CDF;");
        Console.WriteLine("  NORMAL_CDF_INV inverts the Normal CDF.");
        Console.WriteLine("  NORMAL_PDF evaluates the Normal PDF;");

        const double mu    = 100.0;
        const double sigma = 15.0;

        Console.WriteLine("");
        Console.WriteLine("  PDF parameter MU =    " + mu + "");
        Console.WriteLine("  PDF parameter SIGMA = " + sigma + "");

        if (!Normal.normal_check(mu, sigma))
        {
            Console.WriteLine("");
            Console.WriteLine("NORMAL_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   = Normal.normal_sample(mu, sigma, ref seed);
            double pdf = Normal.normal_pdf(x, mu, sigma);
            double cdf = CDF.normal_cdf(x, mu, sigma);
            double x2  = CDF.normal_cdf_inv(cdf, mu, sigma);

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