chepolsum.js (1527B)
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 'use strict'; 20 21 // VARIABLES // 22 23 // Chebyshev polynomial coefficients... 24 var A = [ 25 1.996379051590076518221, 26 -0.17971032528832887213e-2, 27 0.131292857963846713e-4, 28 -0.2340875228178749e-6, 29 0.72291210671127e-8, 30 -0.3280997607821e-9, 31 0.198750709010e-10, 32 -0.15092141830e-11, 33 0.1375340084e-12, 34 -0.145728923e-13, 35 0.17532367e-14, 36 -0.2351465e-15, 37 0.346551e-16, 38 -0.55471e-17, 39 0.9548e-18, 40 -0.1748e-18, 41 0.332e-19, 42 -0.58e-20 43 ]; 44 45 46 // MAIN // 47 48 /** 49 * Computes the sum of a Chebyshev polynomial. 50 * 51 * @private 52 * @param {PositiveInteger} n - degree of polynomial 53 * @param {number} t - input value 54 * @returns {number} Chebyshev sum 55 */ 56 function chepolsum( n, t ) { 57 var tt; 58 var u0; 59 var u1; 60 var u2; 61 var k; 62 63 u0 = 0.0; 64 u1 = 0.0; 65 tt = t + t; 66 k = n; 67 do { 68 u2 = u1; 69 u1 = u0; 70 u0 = ( tt*u1 ) - u2 + A[ k ]; 71 k -= 1; 72 } while ( k >= 0 ); 73 return ( u0-u2 ) / 2.0; 74 } 75 76 77 // EXPORTS // 78 79 module.exports = chepolsum;