# Numerical evaluation of ChebyshevT

When I evaluate the following Chebyshev series of the first kind in two different ways, I get two very different results:

N[ChebyshevT[100, Cos[Pi/7]], 8]
N[ChebyshevT[100, Cos[Pi/7]]]

Out[1] = 0.62348980
Out[2] = 3.71097*10^18


Clearly the first result is the correct one. Could someone please explain why the difference occurs e.g. is it perhaps because of a peculiar way that the long Chebyshev polynomial is numerically evaluated? The problem does not arise for shorter length Chebyshev polynomials.

-
Numerical instability. N without any precision specified works in machine precision with precision tracking switched off. For high-order polynomials, this is a bad idea. When a precision is specified, the working precision is adjusted so as to ensure that all of the requested digits are correct. – Oleksandr R. Jul 21 '14 at 13:46
Note also that ChebyshevT[100, N@Cos[Pi/7]] is accurate and fast, no doubt because stable algorithms are used to compute built-in functions with machine precision inputs. – Michael E2 Jul 21 '14 at 15:39
@OleksandrR. thanks for the clarification. – MvP Jul 21 '14 at 16:38
@MichaelE2: yes, I had noticed that but was not sure why Mathematica did not treat N[f(x)] the same as f(N[x]). – MvP Jul 21 '14 at 16:39

## 1 Answer

If you want to evaluate ChebyshevT polynomials accurately you can consider using the Chebyshev recurrence, using memoization.

T[0,x_]:=1;
T[1,x_]:=x;
T[n_,x_]:= T[n,x]=2*x*T[n-1,x]-T[n-2,x];


This should be fast and stable. If you are doing a lot of these, rearranging the computation working from the low index upward would make memoization unnecessary. Using this recurrence for symbol x is probably a bad idea though.

Try T[100, N[Cos[Pi/7]]] though.

-
You might be interested in this – J. M. May 27 '15 at 10:23