Ejemplo n.º 1
0
    public static void normal_01_cdf_inverse_test( )

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_01_CDF_INVERSE_TEST tests NORMAL_01_CDF_INVERSE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 February 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx     = 0;
        int    n_data = 0;
        double x      = 0;
        double x2     = 0;

        Console.WriteLine("");
        Console.WriteLine("NORMAL_01_CDF_INVERSE_TEST:");
        Console.WriteLine("  NORMAL_01_CDF_INVERSE inverts the normal 01 CDF.");
        Console.WriteLine("");
        Console.WriteLine("    FX      X    NORMAL_01_CDF_INVERSE(FX)");
        Console.WriteLine("");

        n_data = 0;

        for ( ; ;)
        {
            Burkardt.Values.Normal.normal_01_cdf_values(ref n_data, ref x, ref fx);

            if (n_data == 0)
            {
                break;
            }

            x2 = CDF.normal_01_cdf_inv(fx);

            Console.WriteLine("  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "  "
                              + x2.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Ejemplo n.º 2
0
    public static double normal_truncated_ab_sample(double mu, double s, double a, double b,
                                                    ref int seed)
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    NORMAL_TRUNCATED_AB_SAMPLE samples the truncated Normal PDF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 August 2013
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, double MU, S, the mean and standard deviation of the
    //    parent Normal distribution.
    //
    //    Input, double A, B, the lower and upper truncation limits.
    //
    //    Input/output, int &SEED, a seed for the random number
    //    generator.
    //
    //    Output, double NORMAL_TRUNCATED_AB_SAMPLE, a sample of the PDF.
    //
    {
        double alpha = (a - mu) / s;
        double beta  = (b - mu) / s;

        double alpha_cdf = CDF.normal_01_cdf(alpha);
        double beta_cdf  = CDF.normal_01_cdf(beta);

        double u      = UniformRNG.r8_uniform_01(ref seed);
        double xi_cdf = alpha_cdf + u * (beta_cdf - alpha_cdf);
        double xi     = CDF.normal_01_cdf_inv(xi_cdf);

        double x = mu + s * xi;

        return(x);
    }