Skip to content

Latest commit

 

History

History
148 lines (93 loc) · 4.24 KB

File metadata and controls

148 lines (93 loc) · 4.24 KB

Chebyshev Series

Evaluate a Chebyshev series using double-precision floating-point arithmetic.

A Chebyshev series in a variable x can be expressed as

$$\sum_{i=0}^{n} c_i T_i(x/2)$$

where c_n, c_{n-1}, ..., c_0 are constants and T_i are Chebyshev polynomials of the first kind.

Usage

var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' );

chebyshevSeries( x, c )

Evaluates a Chebyshev series having coefficients c at a value x.

var v = chebyshevSeries( 1.0, [ 1.0, 0.5 ] );
// returns 0.75

The input x is expected to lie in the interval [-2, 2]. The function internally evaluates Chebyshev polynomials at x/2.

The coefficients c should be ordered in descending degree.

chebyshevSeries.factory( c )

Uses code generation to in-line coefficients and return a function for evaluating a Chebyshev series using double-precision floating-point arithmetic.

var evaluate = chebyshevSeries.factory( [ 1.0, 0.5 ] );

// 0.5 * T_0(0.5) + 1.0 * T_1(0.5)
var v = evaluate( 1.0 );
// returns 0.75

Notes

  • For hot code paths in which coefficients are invariant, a compiled function will be more performant than chebyshevSeries().
  • While code generation can boost performance, its use may be problematic in browser contexts enforcing a strict content security policy (CSP). If running in or targeting an environment with a CSP, avoid using code generation.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var runiform = require( '@stdlib/random/array/uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var chebyshevSeries = require( '@stdlib/math/base/tools/chebyshev-series' );

// Create an array of random coefficients:
var coef = discreteUniform( 10, -100, 100 );

// Evaluate the series at random values using the direct function:
var v;
var i;
for ( i = 0; i < 100; i++ ) {
    v = uniform( -2.0, 2.0 );
    console.log( 'f(%d) = %d', v, chebyshevSeries( v, coef ) );
}

// Generate a chebyshev series evaluation function:
var evaluate = chebyshevSeries.factory( coef );
var x = runiform( 100, -2.0, 2.0 );
logEachMap( 'f(%d) = %d', x, evaluate );