Beispiel #1
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Beta_function">Beta function</seealso>
        public void Run()
        {
            // 1. Compute the Beta function at z = 1.0, w = 3.0
            Console.WriteLine(@"1. Compute the Beta function at z = 1.0, w = 3.0");
            Console.WriteLine(SpecialFunctions.Beta(1.0, 3.0));
            Console.WriteLine();

            // 2. Compute the logarithm of the Beta function at z = 1.0, w = 3.0
            Console.WriteLine(@"2. Compute the logarithm of the Beta function at z = 1.0, w = 3.0");
            Console.WriteLine(SpecialFunctions.BetaLn(1.0, 3.0));
            Console.WriteLine();

            // 3. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 0.7
            Console.WriteLine(@"3. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 0.7");
            Console.WriteLine(SpecialFunctions.BetaIncomplete(1.0, 3.0, 0.7));
            Console.WriteLine();

            // 4. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 1.0
            Console.WriteLine(@"4. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 1.0");
            Console.WriteLine(SpecialFunctions.BetaIncomplete(1.0, 3.0, 1.0));
            Console.WriteLine();

            // 5. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 0.7
            Console.WriteLine(@"5. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 0.7");
            Console.WriteLine(SpecialFunctions.BetaRegularized(1.0, 3.0, 0.7));
            Console.WriteLine();

            // 6. Compute the Beta regularized  function at z = 1.0, w = 3.0, x = 1.0
            Console.WriteLine(@"6. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 1.0");
            Console.WriteLine(SpecialFunctions.BetaRegularized(1.0, 3.0, 1.0));
            Console.WriteLine();
        }
 public void BetaIncomplete(
     [Values(0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000, 5.500000)] double a,
     [Values(0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000)] double b,
     [Values(0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x,
     [Values(8.0117356206774655704238957309013421730449536344797, 9.8573197445250802696495512442154091185464210677262, 11.045931323774722512127911008108711428206559153167, 7.906686887040059574762793470136627722332467302241, 9.1012542128394916083902345366778109992938115490192, 9.368806890135865087467208304972858639790010273545, 7.8363997919172974609110616787835466667385876309684, 8.7385989355952880797816267602947881842609716646237, 8.8379245631995373736838511405978394101548418300997, 7.6464829466025722609741358285691936422732595850987, 8.0832162883698521112308593494639236817925940654185, 8.089843275520988350320569916795581670946930566783, 0.022303834332028031481145155068151014763064226606192, 0.33465159984030260689318592198561677643426763544959, 1.002080089012839104050394134134167486035896540574, 0.02043763859916055001568569052740016093388906615616, 0.19634954084936207740391521145496893026232308746094, 0.33678717944852264351783475904713816723851995610486, 0.019218819299580275673976660038794008316192763455412, 0.13984143709134770536862427239415113179782821039714, 0.18972692305759464976318019465615085035583828745353, 0.016056550082674778556355475820652277420877772570937, 0.061380263212265132490746506045997506787829048203228, 0.064403479961606576649564368278872635247235510624673, 0.001352753157951915161848451666929681258878645850634, 0.10756276379201896635529117527407904299772826375257, 0.5587192957063609402827988523062144494394362102048, 0.0012188192995802743417090304886061526176963027007477, 0.056508103758014372035290939060817798464494877063805, 0.14706025639092799375465456439098731688268166865133, 0.0011320572373426029655709496224583878329664195067652, 0.036815538909255389513234102147806674424185578898927, 0.067947596146597995171095886486269312250373204235372, 0.00091001787485888099434748885472859856478675247779447, 0.012036842116913956962302822724142322883106224614977, 0.0137861171346299807272679372975664758815098236357, 0.00000062268687636453588281206442354375188797585844216401, 0.0066577573700032687517874433540471831930305154614716, 0.15893826959760073090597940189540380779121963557728, 0.00000055008267477746389601958949824166456746390970113234, 0.0030469298789317991574131727126641734544957148698945, 0.029928813294939917230433606365228383142081556070117, 0.00000050358914459517094905570885392504304689450166185919, 0.0017689849740568141051599655812851800259633674721202, 0.010158231420344267874007806875642686140428489302542, 0.00000038687628134504851234251462244340434107233073666673, 0.00037750308451873202137593561772653328266987165863158, 0.00074361660080007708142054771607396897718180545812717)] double f)
 {
     AssertHelpers.AlmostEqual(f, SpecialFunctions.BetaIncomplete(a, b, x), 12);
 }
Beispiel #3
0
 public void BetaIncomplete(double a, double b, double x, double f)
 {
     AssertHelpers.AlmostEqualRelative(f, SpecialFunctions.BetaIncomplete(a, b, x), 11);
 }
Beispiel #4
0
        /// <summary>
        /// Executes the example.
        /// </summary>
        public override void ExecuteExample()
        {
            // <seealso cref="http://en.wikipedia.org/wiki/Beta_function">Beta function</seealso>
            MathDisplay.WriteLine("<b>Beta fuction</b>");

            // 1. Compute the Beta function at z = 1.0, w = 3.0
            MathDisplay.WriteLine(@"1. Compute the Beta function at z = 1.0, w = 3.0");
            MathDisplay.WriteLine(SpecialFunctions.Beta(1.0, 3.0).ToString());
            MathDisplay.WriteLine();

            // 2. Compute the logarithm of the Beta function at z = 1.0, w = 3.0
            MathDisplay.WriteLine(@"2. Compute the logarithm of the Beta function at z = 1.0, w = 3.0");
            MathDisplay.WriteLine(SpecialFunctions.BetaLn(1.0, 3.0).ToString());
            MathDisplay.WriteLine();

            // 3. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 0.7
            MathDisplay.WriteLine(@"3. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 0.7");
            MathDisplay.WriteLine(SpecialFunctions.BetaIncomplete(1.0, 3.0, 0.7).ToString());
            MathDisplay.WriteLine();

            // 4. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 1.0
            MathDisplay.WriteLine(@"4. Compute the Beta incomplete function at z = 1.0, w = 3.0, x = 1.0");
            MathDisplay.WriteLine(SpecialFunctions.BetaIncomplete(1.0, 3.0, 1.0).ToString());
            MathDisplay.WriteLine();

            // 5. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 0.7
            MathDisplay.WriteLine(@"5. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 0.7");
            MathDisplay.WriteLine(SpecialFunctions.BetaRegularized(1.0, 3.0, 0.7).ToString());
            MathDisplay.WriteLine();

            // 6. Compute the Beta regularized  function at z = 1.0, w = 3.0, x = 1.0
            MathDisplay.WriteLine(@"6. Compute the Beta regularized function at z = 1.0, w = 3.0, x = 1.0");
            MathDisplay.WriteLine(SpecialFunctions.BetaRegularized(1.0, 3.0, 1.0).ToString());
            MathDisplay.WriteLine();



            MathDisplay.WriteLine("<b>Common functions</b>");

            // 1. Calculate the Digamma function at point 5.0
            // <seealso cref="http://en.wikipedia.org/wiki/Digamma_function">Digamma function</seealso>
            MathDisplay.WriteLine(@"1. Calculate the Digamma function at point 5.0");
            MathDisplay.WriteLine(SpecialFunctions.DiGamma(5.0).ToString());
            MathDisplay.WriteLine();

            // 2. Calculate the inverse Digamma function at point 1.5
            MathDisplay.WriteLine(@"2. Calculate the inverse Digamma function at point 1.5");
            MathDisplay.WriteLine(SpecialFunctions.DiGammaInv(1.5).ToString());
            MathDisplay.WriteLine();

            // 3. Calculate the 10'th Harmonic number
            // <seealso cref="http://en.wikipedia.org/wiki/Harmonic_number">Harmonic number</seealso>
            MathDisplay.WriteLine(@"3. Calculate the 10'th Harmonic number");
            MathDisplay.WriteLine(SpecialFunctions.Harmonic(10).ToString());
            MathDisplay.WriteLine();

            // 4. Calculate the generalized harmonic number of order 10 of 3.0.
            // <seealso cref="http://en.wikipedia.org/wiki/Harmonic_number#Generalized_harmonic_numbers">Generalized harmonic numbers</seealso>
            MathDisplay.WriteLine(@"4. Calculate the generalized harmonic number of order 10 of 3.0");
            MathDisplay.WriteLine(SpecialFunctions.GeneralHarmonic(10, 3.0).ToString());
            MathDisplay.WriteLine();

            // 5. Calculate the logistic function of 3.0
            // <seealso cref="http://en.wikipedia.org/wiki/Logistic_function">Logistic function</seealso>
            MathDisplay.WriteLine(@"5. Calculate the logistic function of 3.0");
            MathDisplay.WriteLine(SpecialFunctions.Logistic(3.0).ToString());
            MathDisplay.WriteLine();

            // 6. Calculate the logit function of 0.3
            // <seealso cref="http://en.wikipedia.org/wiki/Logit">Logit function</seealso>
            MathDisplay.WriteLine(@"6. Calculate the logit function of 0.3");
            MathDisplay.WriteLine(SpecialFunctions.Logit(0.3).ToString());
            MathDisplay.WriteLine();

            // <seealso cref="http://en.wikipedia.org/wiki/Error_function">Error function</seealso>
            MathDisplay.WriteLine("<b>Error function</b>");

            // 1. Calculate the error function at point 2
            MathDisplay.WriteLine(@"1. Calculate the error function at point 2");
            MathDisplay.WriteLine(SpecialFunctions.Erf(2).ToString());
            MathDisplay.WriteLine();

            // 2. Sample 10 values of the error function in [-1.0; 1.0]
            MathDisplay.WriteLine(@"2. Sample 10 values of the error function in [-1.0; 1.0]");
            var data = Generate.LinearSpacedMap <double>(10, -1.0, 1.0, SpecialFunctions.Erf);

            for (var i = 0; i < data.Length; i++)
            {
                MathDisplay.Write(data[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 3. Calculate the complementary error function at point 2
            MathDisplay.WriteLine(@"3. Calculate the complementary error function at point 2");
            MathDisplay.WriteLine(SpecialFunctions.Erfc(2).ToString());
            MathDisplay.WriteLine();

            // 4. Sample 10 values of the complementary error function in [-1.0; 1.0]
            MathDisplay.WriteLine(@"4. Sample 10 values of the complementary error function in [-1.0; 1.0]");
            data = Generate.LinearSpacedMap <double>(10, -1.0, 1.0, SpecialFunctions.Erfc);
            for (var i = 0; i < data.Length; i++)
            {
                MathDisplay.Write(data[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 5. Calculate the inverse error function at point z=0.5
            MathDisplay.WriteLine(@"5. Calculate the inverse error function at point z=0.5");
            MathDisplay.WriteLine(SpecialFunctions.ErfInv(0.5).ToString());
            MathDisplay.WriteLine();

            // 6. Sample 10 values of the inverse error function in [-1.0; 1.0]
            MathDisplay.WriteLine(@"6. Sample 10 values of the inverse error function in [-1.0; 1.0]");
            data = Generate.LinearSpacedMap <double>(10, -1.0, 1.0, SpecialFunctions.ErfInv);
            for (var i = 0; i < data.Length; i++)
            {
                MathDisplay.Write(data[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 7. Calculate the complementary inverse error function at point z=0.5
            MathDisplay.WriteLine(@"7. Calculate the complementary inverse error function at point z=0.5");
            MathDisplay.WriteLine(SpecialFunctions.ErfcInv(0.5).ToString());
            MathDisplay.WriteLine();

            // 8. Sample 10 values of the complementary inverse error function in [-1.0; 1.0]
            MathDisplay.WriteLine(@"8. Sample 10 values of the complementary inverse error function in [-1.0; 1.0]");
            data = Generate.LinearSpacedMap <double>(10, -1.0, 1.0, SpecialFunctions.ErfcInv);
            for (var i = 0; i < data.Length; i++)
            {
                MathDisplay.Write(data[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();


            // <seealso cref="http://en.wikipedia.org/wiki/Factorial">Factorial</seealso>
            MathDisplay.WriteLine("<b>Factorial</b>");

            // 1. Compute the factorial of 5
            MathDisplay.WriteLine(@"1. Compute the factorial of 5");
            MathDisplay.WriteLine(SpecialFunctions.Factorial(5).ToString("N"));
            MathDisplay.WriteLine();

            // 2. Compute the logarithm of the factorial of 5
            MathDisplay.WriteLine(@"2. Compute the logarithm of the factorial of 5");
            MathDisplay.WriteLine(SpecialFunctions.FactorialLn(5).ToString("N"));
            MathDisplay.WriteLine();


            // <seealso cref="http://en.wikipedia.org/wiki/Binomial_coefficient">Binomial coefficient</seealso>
            MathDisplay.WriteLine("<b>Binomial coefficient</b>");

            // 3. Compute the binomial coefficient: 10 choose 8
            MathDisplay.WriteLine(@"3. Compute the binomial coefficient: 10 choose 8");
            MathDisplay.WriteLine(SpecialFunctions.Binomial(10, 8).ToString("N"));
            MathDisplay.WriteLine();

            // 4. Compute the logarithm of the binomial coefficient: 10 choose 8
            MathDisplay.WriteLine(@"4. Compute the logarithm of the binomial coefficient: 10 choose 8");
            MathDisplay.WriteLine(SpecialFunctions.BinomialLn(10, 8).ToString("N"));
            MathDisplay.WriteLine();

            // <seealso cref="http://en.wikipedia.org/wiki/Multinomial_theorem#Multinomial_coefficients">Multinomial coefficients</seealso>
            MathDisplay.WriteLine("<b>Multinomial coefficient</b>");

            // 5. Compute the multinomial coefficient: 10 choose 2, 3, 5
            MathDisplay.WriteLine(@"5. Compute the multinomial coefficient: 10 choose 2, 3, 5");
            MathDisplay.WriteLine(SpecialFunctions.Multinomial(10, new[] { 2, 3, 5 }).ToString("N"));
            MathDisplay.WriteLine();


            // <seealso cref="http://en.wikipedia.org/wiki/Gamma_function">Gamma function</seealso>
            MathDisplay.WriteLine("<b>Gamma function</b>");

            // 1. Compute the Gamma function of 10
            MathDisplay.WriteLine(@"1. Compute the Gamma function of 10");
            MathDisplay.WriteLine(SpecialFunctions.Gamma(10).ToString("N"));
            MathDisplay.WriteLine();

            // 2. Compute the logarithm of the Gamma function of 10
            MathDisplay.WriteLine(@"2. Compute the logarithm of the Gamma function of 10");
            MathDisplay.WriteLine(SpecialFunctions.GammaLn(10).ToString("N"));
            MathDisplay.WriteLine();

            // 3. Compute the lower incomplete gamma(a, x) function at a = 10, x = 14
            MathDisplay.WriteLine(@"3. Compute the lower incomplete gamma(a, x) function at a = 10, x = 14");
            MathDisplay.WriteLine(SpecialFunctions.GammaLowerIncomplete(10, 14).ToString("N"));
            MathDisplay.WriteLine();

            // 4. Compute the lower incomplete gamma(a, x) function at a = 10, x = 100
            MathDisplay.WriteLine(@"4. Compute the lower incomplete gamma(a, x) function at a = 10, x = 100");
            MathDisplay.WriteLine(SpecialFunctions.GammaLowerIncomplete(10, 100).ToString("N"));
            MathDisplay.WriteLine();

            // 5. Compute the upper incomplete gamma(a, x) function at a = 10, x = 0
            MathDisplay.WriteLine(@"5. Compute the upper incomplete gamma(a, x) function at a = 10, x = 0");
            MathDisplay.WriteLine(SpecialFunctions.GammaUpperIncomplete(10, 0).ToString("N"));
            MathDisplay.WriteLine();

            // 6. Compute the upper incomplete gamma(a, x) function at a = 10, x = 10
            MathDisplay.WriteLine(@"6. Compute the upper incomplete gamma(a, x) function at a = 10, x = 100");
            MathDisplay.WriteLine(SpecialFunctions.GammaLowerIncomplete(10, 10).ToString("N"));
            MathDisplay.WriteLine();

            // 7. Compute the lower regularized gamma(a, x) function at a = 10, x = 14
            MathDisplay.WriteLine(@"7. Compute the lower regularized gamma(a, x) function at a = 10, x = 14");
            MathDisplay.WriteLine(SpecialFunctions.GammaLowerRegularized(10, 14).ToString("N"));
            MathDisplay.WriteLine();

            // 8. Compute the lower regularized gamma(a, x) function at a = 10, x = 100
            MathDisplay.WriteLine(@"8. Compute the lower regularized gamma(a, x) function at a = 10, x = 100");
            MathDisplay.WriteLine(SpecialFunctions.GammaLowerRegularized(10, 100).ToString("N"));
            MathDisplay.WriteLine();

            // 9. Compute the upper regularized gamma(a, x) function at a = 10, x = 0
            MathDisplay.WriteLine(@"9. Compute the upper regularized gamma(a, x) function at a = 10, x = 0");
            MathDisplay.WriteLine(SpecialFunctions.GammaUpperRegularized(10, 0).ToString("N"));
            MathDisplay.WriteLine();

            // 10. Compute the upper regularized gamma(a, x) function at a = 10, x = 10
            MathDisplay.WriteLine(@"10. Compute the upper regularized gamma(a, x) function at a = 10, x = 100");
            MathDisplay.WriteLine(SpecialFunctions.GammaUpperRegularized(10, 10).ToString("N"));
            MathDisplay.WriteLine();

            MathDisplay.WriteLine("<b>Numerical stability</b>");

            // 1. Compute numerically stable exponential of 10 minus one
            MathDisplay.WriteLine(@"1. Compute numerically stable exponential of 4.2876 minus one");
            MathDisplay.WriteLine(SpecialFunctions.ExponentialMinusOne(4.2876).ToString());
            MathDisplay.WriteLine();

            // 2. Compute regular System.Math exponential of 15.28 minus one
            MathDisplay.WriteLine(@"2. Compute regular System.Math exponential of 4.2876 minus one ");
            MathDisplay.WriteLine((Math.Exp(4.2876) - 1).ToString());
            MathDisplay.WriteLine();

            // 3. Compute numerically stable hypotenuse of a right angle triangle with a = 5, b = 3
            MathDisplay.WriteLine(@"3. Compute numerically stable hypotenuse of a right angle triangle with a = 5, b = 3");
            MathDisplay.WriteLine(SpecialFunctions.Hypotenuse(5, 3).ToString());
            MathDisplay.WriteLine();
        }