• https://me.yahoo.com
COST (GBP)
0.50
0.00
0

# Cheb Eval

viewed 3348 times and licensed 117 times
Evaluates the Chebyshev polynomial series
Controller: CodeCogs
Contents

C++

## ChebEval

 doublechebEval( double x const double* coef int N )
Evaluates the Chebyshev polynomial series of the First Kind:
$f(x)&space;=&space;\sum_{i=0}^{N-1}&space;c_i&space;T_i(\frac{x}{2})$
where c are the coefficient, and $\inline&space;T-i$ are the Chebyshev polynomials evaluated at x/2,
$T_0(n)&space;=&space;1$
$T_1(n)&space;=&space;x$
$T_2(n)&space;=&space;2n^2&space;-1$
$T_3(n)&space;=&space;4n^3&space;-&space;3n$
$T_4(n)&space;=&space;8n^4&space;-&space;8n^2&space;+1$
$T_5(n)&space;=&space;16n^5&space;-&space;20n^3&space;+&space;5n$
$T_6(n)&space;=&space;32n^6&space;=&space;48n^4&space;+&space;18n^2&space;-1$

The Chebyshev polynomials of the first kind are a set of orthogonal polynomials defined as the solutions to the Chebyshev differential equation. They are also used as an approximation to a least squares fit and are intimately connected with trigonometric multiple-angle formulas.

If coefficients are for the interval a to b, x must be transformed to
$x&space;\rightarrow&space;\frac{2&space;(2x&space;-&space;b&space;-&space;a)}{b-a}$
before entering the routine. This maps x from (a, b) to (-1, 1), over which the Chebyshev polynomials are defined.

If the coefficients are for the inverted interval, in which (a, b) is mapped to (1/b, 1/a), the transformation required is
$x&space;\rightarrow&space;\frac{2&space;(2ab/x&space;-&space;b&space;-&space;a)}{b-a}$

If b is infinity, this becomes
$x&space;\rightarrow&space;\frac{4a}{x}&space;-&space;1$

## Speed:

Taking advantage of the recurrence properties of the Chebyshev polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same degree.

## Example:

The following code computes solutions to the polynomial
$f(x)&space;=&space;1&space;+&space;2\frac{x}{2}&space;+&space;3&space;\left&space;(&space;2\frac{x}{2}^2&space;-&space;1&space;\right&space;)$
#include <stdio.h>
#include <codecogs/maths/approximation/polynomial/cheb_eval.h>

int main()
{
using namespace Maths::Algebra::Polynomial;
static double C[] = { 3,2,1 };
for(int x=2;x<=5;x++)
printf("\n chebEval(%d, A, 2)=%.1lf", x, chebEval(x, C, 2));

return 0;
}

## Output:

chebEval(2, A, 2)=4.0
chebEval(3, A, 2)=5.5
chebEval(4, A, 2)=7.0
chebEval(5, A, 2)=8.5

## References

Cephes Math Library Release 2.0: April, 1987

### Note

The provided coefficients are stored in reverse order, i.e.
$coef[0]&space;=&space;C_{N-1},&space;...,&space;coef[N-1]=C_0$

### Parameters

 x value to evaluate coef coefficients from [0..N-1], stored in reverse order. N number of coefficients, not the order. Must be 2 or more

### Authors

Stephen L. Moshier Copyright 1985, 1987
Documentation by Will Bateman (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.