lower_gamma_series.js (2204B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * 19 * ## Notice 20 * 21 * The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_61_0/boost/math/special_functions/gamma.hpp}. The implementation has been modified for JavaScript. 22 * 23 * ```text 24 * Copyright John Maddock 2006-7, 2013-14. 25 * Copyright Paul A. Bristow 2007, 2013-14. 26 * Copyright Nikhar Agrawal 2013-14. 27 * Copyright Christopher Kormanyos 2013-14. 28 * 29 * Use, modification and distribution are subject to the 30 * Boost Software License, Version 1.0. (See accompanying file 31 * LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) 32 * ``` 33 */ 34 35 'use strict'; 36 37 // MODULES // 38 39 var sumSeries = require( './../../../../base/tools/sum-series' ); 40 var lowerIncompleteGammaSeries = require( './lower_incomplete_gamma_series.js' ); 41 42 43 // VARIABLES // 44 45 var opts = { 46 'maxIter': 1000 47 }; 48 49 50 // MAIN // 51 52 /** 53 * Sums elements of the series expansion of the lower incomplete gamma function. 54 * 55 * ## Method 56 * 57 * - Multiply result by `(z^a)*(e^-z) / a` to get the full lower incomplete integral. 58 * - Divide by `tgamma(a)` to get the normalized value. 59 * 60 * @private 61 * @param {number} a - function parameter 62 * @param {number} z - function parameter 63 * @param {number} initialValue - initial value of the resulting sum 64 * @returns {number} sum of terms of lower gamma series 65 */ 66 function lowerGammaSeries( a, z, initialValue ) { 67 var result; 68 var s; 69 70 initialValue = initialValue || 0.0; 71 s = lowerIncompleteGammaSeries( a, z ); 72 opts.initialValue = initialValue; 73 result = sumSeries( s, opts ); 74 return result; 75 } 76 77 78 // EXPORTS // 79 80 module.exports = lowerGammaSeries;