Skip to main content
added 8 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]
Manipulate[
 Plot[Tooltip@Table[g[x, n], {n, i}] // Evaluate, {x, -1, 1}, 
  PlotRange -> {-1, 1}, AspectRatio -> 1, 
  PlotLegends -> Automatic], {i, Range[5]}]

enter image description here

f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]

enter image description here

f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]
Manipulate[
 Plot[Tooltip@Table[g[x, n], {n, i}] // Evaluate, {x, -1, 1}, 
  PlotRange -> {-1, 1}, AspectRatio -> 1, 
  PlotLegends -> Automatic], {i, Range[5]}]

enter image description here

added 8 characters in body
Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179
f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Table[g[xPlot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]

enter image description here

f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]

enter image description here

f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Tooltip@Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]

enter image description here

Source Link
cvgmt
  • 84.1k
  • 6
  • 97
  • 179

f[x_] := x;
T = 2;
a0 = 2/T*Integrate[f[x], {x, -1, 1}];
a[k_] := 2/T*Integrate[f[x]*Cos[2*Pi*k/T*x], {x, -1, 1}];
b[k_] := 2/T*Integrate[f[x]*Sin[2*Pi*k/T*x], {x, -1, 1}];
g[x_, n_] := 
  a0/2 + Sum[a[k]*Cos[2*Pi*k/T*x], {k, 1, n}] + 
   Sum[b[k]*Sin[2*Pi*k/T*x], {k, 1, n}];
g[x, 3]
Plot[Table[g[x, n], {n, 5}] // Evaluate, {x, -1, 1}, 
 PlotRange -> {-1, 1}, AspectRatio -> 1, PlotLegends -> Automatic]

enter image description here