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.

  • 6
    $\begingroup$ 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. $\endgroup$ Jul 21, 2014 at 13:46
  • 1
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Jul 21, 2014 at 15:39
  • $\begingroup$ @OleksandrR. thanks for the clarification. $\endgroup$
    – MvP
    Jul 21, 2014 at 16:38
  • $\begingroup$ @MichaelE2: yes, I had noticed that but was not sure why Mathematica did not treat N[f(x)] the same as f(N[x]). $\endgroup$
    – MvP
    Jul 21, 2014 at 16:39

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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