Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

You can just take Bob HanlonBob Hanlon's answer from 2006 directly, and modify the plot just a bit to update it.

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

You can just take Bob Hanlon's answer from 2006 directly, and modify the plot just a bit to update it.

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

You can just take Bob Hanlon's answer from 2006 directly, and modify the plot just a bit to update it.

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

added 50 characters in body
Source Link
Jason B.
  • 70.1k
  • 3
  • 144
  • 297

And youYou can just take Bob Hanlon's answer from 2006 directly, and modify the plot just a bit to update it.

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

And you can just take Bob Hanlon's answer directly,

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

You can just take Bob Hanlon's answer from 2006 directly, and modify the plot just a bit to update it.

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here

Source Link
Jason B.
  • 70.1k
  • 3
  • 144
  • 297

And you can just take Bob Hanlon's answer directly,

ChebyshevApprox[n_Integer?Positive, f_Function, x_] := 
  Module[{c, xk}, xk = Pi (Range[n] - 1/2)/n;
   c[j_] = 2*Total[Cos[j*xk]*(f /@ Cos[xk])]/n;
   Total[Table[c[k]*ChebyshevT[k, x], {k, 0, n - 1}]] - c[0]/2];

f = 3*#^2*Exp[-2*#]*Sin[2 #*Pi] &;

ChebyshevApprox[3, f, x] // Simplify

((-(3/4))*((-E^(2*Sqrt[3]))*(Sqrt[3] - 2*x) - 2*x - Sqrt[3])*x*
   Sin[Sqrt[3]*Pi])/E^Sqrt[3]

GraphicsGrid[
 Partition[
  Table[Plot[{f[x], ChebyshevApprox[n, f, x]}, {x, -1, 1}, 
    Frame -> True, Axes -> False, PlotStyle -> {Blue, Red}, 
    PlotRange -> {-2, 10}, 
    Epilog -> Text["n = " <> ToString[n], {0.25, 5}]], {n, 9}], 3], 
 ImageSize -> 500]

enter image description here