README.md (3772B)
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 # Gamma Scaled Lanczos Sum 22 23 > Calculate a scaled Lanczos sum for the approximation of the [gamma function][gamma-function]. 24 25 <section class="intro"> 26 27 The [Lanczos approximation][lanczos-approximation] for the [gamma function][gamma-function] can be written in partial fraction form as follows: 28 29 <!-- <equation class="equation" label="eq:lanczos_approximation" align="center" raw="\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)" alt="Lanczos approximation for gamma function."> --> 30 31 <div class="equation" align="center" data-raw-text="\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)" data-equation="eq:lanczos_approximation"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled/docs/img/equation_lanczos_approximation.svg" alt="Lanczos approximation for gamma function."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `g` is an [arbitrary constant][@stdlib/constants/float64/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. The scaled Lanczos sum is given by 39 40 <!-- <equation class="equation" label="eq:scaled_lanczos_sum" align="center" raw="L_g(n) \cdot \exp(-g)" alt="Scaled Lanczos sum."> --> 41 42 <div class="equation" align="center" data-raw-text="L_g(n) \cdot \exp(-g)" data-equation="eq:scaled_lanczos_sum"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled/docs/img/equation_scaled_lanczos_sum.svg" alt="Scaled Lanczos sum."> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 </section> 50 51 <!-- /.intro --> 52 53 <section class="usage"> 54 55 ## Usage 56 57 ```javascript 58 var gammaLanczosSumExpGScaled = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' ); 59 ``` 60 61 #### gammaLanczosSumExpGScaled( x ) 62 63 Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] (scaled by `exp(-g)`, where `g = 10.900511`). 64 65 ```javascript 66 var v = gammaLanczosSumExpGScaled( 4.0 ); 67 // returns ~0.018 68 69 v = gammaLanczosSumExpGScaled( -1.5 ); 70 // returns ~25.337 71 72 v = gammaLanczosSumExpGScaled( -0.5 ); 73 // returns ~-12.911 74 75 v = gammaLanczosSumExpGScaled( 0.5 ); 76 // returns ~1.772 77 78 v = gammaLanczosSumExpGScaled( 0.0 ); 79 // returns Infinity 80 81 v = gammaLanczosSumExpGScaled( NaN ); 82 // returns NaN 83 ``` 84 85 </section> 86 87 <!-- /.usage --> 88 89 <section class="examples"> 90 91 ## Examples 92 93 <!-- eslint no-undef: "error" --> 94 95 ```javascript 96 var linspace = require( '@stdlib/array/linspace' ); 97 var gammaLanczosSumExpGScaled = require( '@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled' ); 98 99 var x = linspace( -10.0, 10.0, 100 ); 100 var v; 101 var i; 102 103 for ( i = 0; i < x.length; i++ ) { 104 v = gammaLanczosSumExpGScaled( x[ i ] ); 105 console.log( 'x: %d, f(x): %d', x[ i ], v ); 106 } 107 ``` 108 109 </section> 110 111 <!-- /.examples --> 112 113 <section class="links"> 114 115 [@stdlib/constants/float64/gamma-lanczos-g]: https://www.npmjs.com/package/@stdlib/constants-float64-gamma-lanczos-g 116 117 [gamma-function]: https://en.wikipedia.org/wiki/Gamma_function 118 119 [lanczos-approximation]: https://en.wikipedia.org/wiki/Lanczos_approximation 120 121 </section> 122 123 <!-- /.links -->