public static double log_normal_cdf(double x, double a, double b) //****************************************************************************80 // // Purpose: // // LOG_NORMAL_CDF evaluates the Lognormal CDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 September 2004 // // Author: // // John Burkardt // // Parameters: // // Input, double X, the argument of the PDF. // 0.0 < X. // // Input, double A, B, the parameters of the PDF. // 0.0 < B. // // Output, double CDF, the value of the CDF. // { double cdf; switch (x) { case <= 0.0: cdf = 0.0; break; default: { double logx = Math.Log(x); cdf = CDF.normal_cdf(logx, a, b); break; } } return(cdf); }
public static double half_normal_cdf(double x, double a, double b) //****************************************************************************80 // // Purpose: // // HALF_NORMAL_CDF evaluates the Half Normal CDF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 17 October 2004 // // Author: // // John Burkardt // // Parameters: // // Input, double X, the argument of the CDF. // // Input, double A, B, the parameters of the PDF. // 0.0 < B. // // Output, double HALF_NORMAL_CDF, the value of the CDF. // { double cdf; if (x <= a) { cdf = 0.0; } else { double cdf2 = CDF.normal_cdf(x, a, b); cdf = 2.0 * cdf2 - 1.0; } return(cdf); }
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) + ""); } }