Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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

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

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.

share|improve this answer
You might be interested in this – J. M. May 27 '15 at 10:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.