Skip to main content
1 of 5
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215

Let you have a polynomial

f[x_] := 1 - x + 2 x^2 - 5 x^4
n = 5; (* Polynomial order + 1 *)

Now you have to solve a system of linear equations

a = Transpose@PadRight@Table[CoefficientList[ChebyshevT[k - 1, x], x], {k, n}];
c = LinearSolve[a, CoefficientList[f[x], x]]
(* {1/8, -1, -3/2, 0, -5/8} *)

Sum[c[[k]] ChebyshevT[k - 1, x], {k, n}] // Expand
(* 1 - x + 2 x^2 - 5 x^4 *)

If the numerical values of coefficients are enough you can apply extremly fast method with Fourier transform since

$$ T_n(x) = \cos(n \arccos x) $$

c = 2 MapAt[#/2 &, #, 1]/Sqrt[n] &@FourierDCT@f@Cos[π Range[.5, n]/n]
(* {0.125, -1., -1.5, -9.93014*10^-17, -0.625} *)

Chop@Sum[c[[k]] ChebyshevT[k - 1, x], {k, n}] // Expand
(* 1. - 1. x + 2. x^2 - 5. x^4 *)

P.S. The last method can be used for Chebyshev expansion of arbitrary function.

ybeltukov
  • 43.9k
  • 5
  • 109
  • 215