time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (5893B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # gammainc
     22 
     23 > [Incomplete gamma function][incomplete-gamma-function].
     24 
     25 <section class="intro">
     26 
     27 Evaluates the regularized lower [incomplete gamma function][incomplete-gamma-function]:
     28 
     29 <!-- <equation class="equation" label="eq:lower_incomplete_gamma" align="center" raw="P( x, a ) = \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} e^{-t} \; dt" alt="Regularized lower incomplete gamma function."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="P( x, a ) = \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} e^{-t} \; dt" data-equation="eq:lower_incomplete_gamma">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammainc/docs/img/equation_lower_incomplete_gamma.svg" alt="Regularized lower incomplete gamma function.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 The function can also be used to evaluate the regularized upper incomplete gamma function, which is defined as follows:
     39 
     40 <!-- <equation class="equation" label="eq:upper_incomplete_gamma" align="center" raw="Q( x, a ) = \frac{\Gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_x^\infty t^{a-1} e^{-t} \; dt" alt="Regularized upper incomplete gamma function."> -->
     41 
     42 <div class="equation" align="center" data-raw-text="Q( x, a ) = \frac{\Gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_x^\infty t^{a-1} e^{-t} \; dt" data-equation="eq:upper_incomplete_gamma">
     43     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammainc/docs/img/equation_upper_incomplete_gamma.svg" alt="Regularized upper incomplete gamma function.">
     44     <br>
     45 </div>
     46 
     47 <!-- </equation> -->
     48 
     49 The two functions have the relationship `Q(x,a) = 1 - P(x,a)`.
     50 
     51 In addition, this routine can be used to evaluate the _unregularized_ gamma functions. The range of above functions is `[0,1]`, which is not the case for the _unregularized_ versions. The unregularized lower incomplete gamma function is defined as
     52 
     53 <!-- <equation class="equation" label="eq:unreg_lower_incomplete_gamma" align="center" raw="\gamma(a,x) = \int_0^x t^{a-1} e^{-t} \; dt" alt="Unregularized lower incomplete gamma function."> -->
     54 
     55 <div class="equation" align="center" data-raw-text="\gamma(a,x) = \int_0^x t^{a-1} e^{-t} \; dt" data-equation="eq:unreg_lower_incomplete_gamma">
     56     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammainc/docs/img/equation_unreg_lower_incomplete_gamma.svg" alt="Unregularized lower incomplete gamma function.">
     57     <br>
     58 </div>
     59 
     60 <!-- </equation> -->
     61 
     62 and the upper unregularized incomplete gamma function is
     63 
     64 <!-- <equation class="equation" label="eq:unreg_upper_incomplete_gamma" align="center" raw="\Gamma(a,x)= \int_x^\infty t^{a-1} e^{-t} \; dt" alt="Unregularized upper incomplete gamma function."> -->
     65 
     66 <div class="equation" align="center" data-raw-text="\Gamma(a,x)= \int_x^\infty t^{a-1} e^{-t} \; dt" data-equation="eq:unreg_upper_incomplete_gamma">
     67     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gammainc/docs/img/equation_unreg_upper_incomplete_gamma.svg" alt="Unregularized upper incomplete gamma function.">
     68     <br>
     69 </div>
     70 
     71 <!-- </equation> -->
     72 
     73 The relationship between the two functions is `Γ(a,x) = γ(a,x) + Γ(a)`.
     74 
     75 </section>
     76 
     77 <!-- /.intro -->
     78 
     79 <section class="usage">
     80 
     81 ## Usage
     82 
     83 ```javascript
     84 var gammainc = require( '@stdlib/math/base/special/gammainc' );
     85 ```
     86 
     87 #### gammainc( x, s\[, regularized\[, upper ]] )
     88 
     89 By default, evaluates the regularized lower [incomplete gamma function][incomplete-gamma-function] for inputs `x` and `s`. The third and fourth parameters of the function can be used to specify whether instead to evaluate the non-regularized and/or upper incomplete gamma functions, respectively.
     90 
     91 ```javascript
     92 var y = gammainc( 6.0, 2.0 );
     93 // returns ~0.9826
     94 
     95 y = gammainc( 1.0, 2.0, true, true );
     96 // returns ~0.7358
     97 
     98 y = gammainc( 7.0, 5.0 );
     99 // returns ~0.8270
    100 
    101 y = gammainc( 7.0, 5.0, false );
    102 // returns ~19.8482
    103 ```
    104 
    105 If provided `NaN` as any argument, the function returns `NaN`.
    106 
    107 ```javascript
    108 var y = gammainc( NaN, 1.0 );
    109 // returns NaN
    110 
    111 y = gammainc( 1.0, NaN );
    112 // returns NaN
    113 ```
    114 
    115 If provided a negative `x`, the function returns `NaN`.
    116 
    117 ```javascript
    118 var y = gammainc( -2.0, 2.0 );
    119 // returns NaN
    120 ```
    121 
    122 If provided a nonpositive `s`, the function returns `NaN`.
    123 
    124 ```javascript
    125 var y = gammainc( 2.0, -1.0 );
    126 // returns NaN
    127 
    128 y = gammainc( 2.0, 0.0 );
    129 // returns NaN
    130 ```
    131 
    132 </section>
    133 
    134 <!-- /.usage -->
    135 
    136 <section class="examples">
    137 
    138 ## Examples
    139 
    140 <!-- eslint no-undef: "error" -->
    141 
    142 ```javascript
    143 var randu = require( '@stdlib/random/base/randu' );
    144 var gammainc = require( '@stdlib/math/base/special/gammainc' );
    145 
    146 var i;
    147 var x;
    148 var s;
    149 
    150 for ( i = 0; i < 100; i++ ) {
    151     x = randu() * 10.0;
    152     s = randu() * 10.0;
    153     console.log( 'x: %d, \t s: %d, \t f(x,s): %d', x.toFixed( 4 ), s.toFixed( 4 ), gammainc( x, s ).toFixed( 4 ) );
    154 }
    155 ```
    156 
    157 </section>
    158 
    159 <!-- /.examples -->
    160 
    161 <section class="links">
    162 
    163 [incomplete-gamma-function]: https://en.wikipedia.org/wiki/Incomplete_gamma_function
    164 
    165 </section>
    166 
    167 <!-- /.links -->