Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.3.0/ALGLIB-2.3.0/betaf.cs @ 13783

Last change on this file since 13783 was 2806, checked in by gkronber, 15 years ago

Added plugin for new version of ALGLIB. #875 (Update ALGLIB sources)

File size: 3.4 KB
Line 
1/*************************************************************************
2Cephes Math Library Release 2.8:  June, 2000
3Copyright by Stephen L. Moshier
4
5Contributors:
6    * Sergey Bochkanov (ALGLIB project). Translation from C to
7      pseudocode.
8
9See subroutines comments for additional copyrights.
10
11>>> SOURCE LICENSE >>>
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation (www.fsf.org); either version 2 of the
15License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20GNU General Public License for more details.
21
22A copy of the GNU General Public License is available at
23http://www.fsf.org/licensing/licenses
24
25>>> END OF LICENSE >>>
26*************************************************************************/
27
28using System;
29
30namespace alglib
31{
32    public class betaf
33    {
34        /*************************************************************************
35        Beta function
36
37
38                          -     -
39                         | (a) | (b)
40        beta( a, b )  =  -----------.
41                            -
42                           | (a+b)
43
44        For large arguments the logarithm of the function is
45        evaluated using lgam(), then exponentiated.
46
47        ACCURACY:
48
49                             Relative error:
50        arithmetic   domain     # trials      peak         rms
51           IEEE       0,30       30000       8.1e-14     1.1e-14
52
53        Cephes Math Library Release 2.0:  April, 1987
54        Copyright 1984, 1987 by Stephen L. Moshier
55        *************************************************************************/
56        public static double beta(double a,
57            double b)
58        {
59            double result = 0;
60            double y = 0;
61            double sg = 0;
62            double s = 0;
63
64            sg = 1;
65            System.Diagnostics.Debug.Assert((double)(a)>(double)(0) | (double)(a)!=(double)((int)Math.Floor(a)), "Overflow in Beta");
66            System.Diagnostics.Debug.Assert((double)(b)>(double)(0) | (double)(b)!=(double)((int)Math.Floor(b)), "Overflow in Beta");
67            y = a+b;
68            if( (double)(Math.Abs(y))>(double)(171.624376956302725) )
69            {
70                y = gammafunc.lngamma(y, ref s);
71                sg = sg*s;
72                y = gammafunc.lngamma(b, ref s)-y;
73                sg = sg*s;
74                y = gammafunc.lngamma(a, ref s)+y;
75                sg = sg*s;
76                System.Diagnostics.Debug.Assert((double)(y)<=(double)(Math.Log(AP.Math.MaxRealNumber)), "Overflow in Beta");
77                result = sg*Math.Exp(y);
78                return result;
79            }
80            y = gammafunc.gamma(y);
81            System.Diagnostics.Debug.Assert((double)(y)!=(double)(0), "Overflow in Beta");
82            if( (double)(a)>(double)(b) )
83            {
84                y = gammafunc.gamma(a)/y;
85                y = y*gammafunc.gamma(b);
86            }
87            else
88            {
89                y = gammafunc.gamma(b)/y;
90                y = y*gammafunc.gamma(a);
91            }
92            result = y;
93            return result;
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.