Evaluate a Chebyshev series using single-precision floating-point arithmetic.
A Chebyshev series in a variable x can be expressed as
where c_n, c_{n-1}, ..., c_0 are constants and T_i are Chebyshev polynomials of the first kind.
var chebyshevSeriesf = require( '@stdlib/math/base/tools/chebyshev-seriesf' );Evaluates a Chebyshev series having coefficients c at a value x.
var Float32Array = require( '@stdlib/array/float32' );
var v = chebyshevSeriesf( 1.0, new Float32Array( [ 1.0, 0.5 ] ) );
// returns 0.75The function evaluates Chebyshev polynomials at x/2.
Uses code generation to in-line coefficients and return a function for evaluating a Chebyshev series using single-precision floating-point arithmetic.
var Float32Array = require( '@stdlib/array/float32' );
var evaluate = chebyshevSeriesf.factory( new Float32Array( [ 1.0, 0.5 ] ) );
// 0.5 * T_0(0.5) + 1.0 * T_1(0.5)
var v = evaluate( 1.0 );
// returns 0.75The returned function evaluates Chebyshev polynomials at x/2.
- The value at which to evaluate a Chebyshev series is expected to reside on the interval
[-2, 2]. - The coefficients
cmust be ordered in descending degree. - For hot code paths in which coefficients are invariant, a compiled function will be more performant than
chebyshevSeriesf(). - 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.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var chebyshevSeriesf = require( '@stdlib/math/base/tools/chebyshev-seriesf' );
// Create an array of random coefficients:
var coef = discreteUniform( 10, -100, 100, {
'dtype': 'float32'
});
// Evaluate the series at random values using the direct function:
var v = uniform( 100, -2.0, 2.0, {
'dtype': 'float32'
});
var i;
for ( i = 0; i < v.length; i++ ) {
console.log( 'f(%0.4f) = %0.4f', v[ i ], chebyshevSeriesf( v[ i ], coef ) );
}
// Generate a chebyshev series evaluation function:
var evaluate = chebyshevSeriesf.factory( coef );
var x = uniform( 100, -2.0, 2.0, {
'dtype': 'float32'
});
logEachMap( 'f(%0.4f) = %0.4f', x, evaluate );