private static void normal_truncated_b_cdf_test() //****************************************************************************80 // // Purpose: // // NORMAL_TRUNCATED_B_CDF_TEST tests NORMAL_TRUNCATED_B_CDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 April 2016 // // Author: // // John Burkardt // { int i; const double b = 150.0; const double mu = 100.0; const double s = 25.0; int seed = 123456789; Console.WriteLine(""); Console.WriteLine("NORMAL_TRUNCATED_B_CDF_TEST"); Console.WriteLine(" NORMAL_TRUNCATED_B_CDF evaluates the Normal Truncated B CDF."); Console.WriteLine(" NORMAL_TRUNCATED_B_CDF_INV inverts the Normal Truncated B CDF."); Console.WriteLine(" NORMAL_TRUNCATED_B_PDF evaluates the Normal Truncated B PDF."); Console.WriteLine(""); Console.WriteLine(" The parent normal distribution has"); Console.WriteLine(" mean = " + mu + ""); Console.WriteLine(" standard deviation = " + s + ""); Console.WriteLine(" The parent distribution is truncated to"); Console.WriteLine(" the interval [-oo," + b + "]"); Console.WriteLine(""); Console.WriteLine(" X PDF CDF CDF_INV"); Console.WriteLine(""); for (i = 1; i <= 10; i++) { double x = Truncated.normal_truncated_b_sample(mu, s, b, ref seed); double pdf = Truncated.normal_truncated_b_pdf(x, mu, s, b); double cdf = CDF.normal_truncated_b_cdf(x, mu, s, b); double x2 = CDF.normal_truncated_b_cdf_inv(cdf, mu, s, b); Console.WriteLine(" " + x.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + pdf.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + cdf.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + x2.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } }
private static void normal_truncated_b_sample_test() //****************************************************************************80 // // Purpose: // // NORMAL_TRUNCATED_B_SAMPLE_TEST tests NORMAL_TRUNCATED_B_SAMPLE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 April 2016 // // Author: // // John Burkardt // { int i; const int sample_num = 1000; double[] x = new double[sample_num]; const double b = 150.0; const double mu = 100.0; const double s = 25.0; int seed = 123456789; Console.WriteLine(""); Console.WriteLine("NORMAL_TRUNCATED_B_SAMPLE_TEST"); Console.WriteLine(" NORMAL_TRUNCATED_B_MEAN computes the Normal Truncated B mean;"); Console.WriteLine(" NORMAL_TRUNCATED_B_SAMPLE samples the Normal Truncated B distribution;"); Console.WriteLine(" NORMAL_TRUNCATED_B_VARIANCE computes the Normal Truncated B variance."); Console.WriteLine(""); Console.WriteLine(" The parent normal distribution has"); Console.WriteLine(" mean = " + mu + ""); Console.WriteLine(" standard deviation = " + s + ""); Console.WriteLine(" The parent distribution is truncated to"); Console.WriteLine(" the interval [-oo," + b + "]"); double mean = Truncated.normal_truncated_b_mean(mu, s, b); double variance = Truncated.normal_truncated_b_variance(mu, s, b); Console.WriteLine(""); Console.WriteLine(" PDF mean = " + mean + ""); Console.WriteLine(" PDF variance = " + variance + ""); for (i = 0; i < sample_num; i++) { x[i] = Truncated.normal_truncated_b_sample(mu, s, b, ref seed); } mean = typeMethods.r8vec_mean(sample_num, x); variance = typeMethods.r8vec_variance(sample_num, x); double xmax = typeMethods.r8vec_max(sample_num, x); double xmin = typeMethods.r8vec_min(sample_num, x); Console.WriteLine(""); Console.WriteLine(" Sample size = " + sample_num + ""); Console.WriteLine(" Sample mean = " + mean + ""); Console.WriteLine(" Sample variance = " + variance + ""); Console.WriteLine(" Sample maximum = " + xmax + ""); Console.WriteLine(" Sample minimum = " + xmin + ""); }