Skip to main content
added 37 characters in body
Source Link

Let's say 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[kTranspose @ 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 getting the numerical values of coefficients is sufficient, you can use the discrete Fourier transformstransform, which is an extremlyextremely fast method.

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

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

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

P.S. The last method can be used for the Chebyshev expansion of an arbitrary function (there can be a problem with Gibbs oscillations, but that is another story).

Let's say 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 getting the numerical values of coefficients is sufficient, you can use Fourier transforms, an extremly fast method.

$\qquad 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} *)

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

P.S. The last method can be used for Chebyshev expansion of an arbitrary function (there can be a problem with Gibbs oscillations, but that is another story).

Let's say 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 getting the numerical values of coefficients is sufficient, you can use the discrete Fourier transform, which is an extremely fast method.

$\qquad 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} *)

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

P.S. The last method can be used for the Chebyshev expansion of an arbitrary function (there can be a problem with Gibbs oscillations, but that is another story).

Made English more idiomatic
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

LetLet's say 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 getting the numerical values of coefficients are enoughis sufficient, you can apply extremlyuse Fourier transforms, an extremly fast method with Fourier transform since.

$$ T_n(x) = \cos(n \arccos x) $$$\qquad 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} *)

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

P.S. The last method can be used for Chebyshev expansion of an arbitrary function (there iscan be a problem ofwith Gibbs oscillations, but itthat is another story).

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} *)

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

P.S. The last method can be used for Chebyshev expansion of arbitrary function (there is a problem of Gibbs oscillations, but it is another story).

Let's say 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 getting the numerical values of coefficients is sufficient, you can use Fourier transforms, an extremly fast method.

$\qquad 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} *)

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

P.S. The last method can be used for Chebyshev expansion of an arbitrary function (there can be a problem with Gibbs oscillations, but that is another story).

added 3 characters in body
Source Link
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]]Sum[c[[k]] ChebyshevT[k - 1, x], {k, n}] // Expand // Chop
(* 1. - 1. x + 2. x^2 - 5. x^4 *)

P.S. The last method can be used for Chebyshev expansion of arbitrary function (there is a problem of Gibbs oscillations, but it is another story).

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 (there is a problem of Gibbs oscillations, but it is another story).

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} *)

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

P.S. The last method can be used for Chebyshev expansion of arbitrary function (there is a problem of Gibbs oscillations, but it is another story).

added 68 characters in body
Source Link
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215
Loading
Source Link
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215
Loading