0
$\begingroup$

I am learning FourierCoefficient and trying to plot Cos with it.

  1. Let us find it Fourier coefficients with FourierCoefficient[Cos[x], x, n]

    $\begin{array}{cc} \{ & \begin{array}{cc} \frac{1}{2} & n=-1\lor n=1 \\ 0 & \text{True} \\ \end{array} \\ \end{array}$

  2. I want to use 16 Fourier modes to approximate Cos:

    nn = 16;
    
    FTcoeffTab = Table[FTcoeff[m] == (KroneckerDelta[m, 1] + KroneckerDelta[m, -1])/2, {m, -nn/2, nn/2-1, 1}]
    
  3. Construst the Fourier expansion of Cos and plot:

    FT[x_] := Sum[FTcoeff[k]*Exp[I k x], {k, -nn/2, nn/2-1}]
    
    Plot[FT[x], {x, -Pi, Pi}, PlotRange -> All]
    

But it gives me a null plot. Please help me and thank you in advance.

$\endgroup$
  • $\begingroup$ FTcoeff[m_] := (KroneckerDelta[m, 1] + KroneckerDelta[m, -1])/2, no need for Table. Then FT[x_]:=... and Plot. $\endgroup$ – Alx Aug 4 at 7:51
  • $\begingroup$ Thanks. Your comment is actually the same as the answer by @Ulrich Neumann. $\endgroup$ – Nobody Aug 4 at 13:57
2
$\begingroup$

Try

FTcoeff[m_] := (KroneckerDelta[m, 1] + KroneckerDelta[m, -1])/2 

without Table!

FT[x_, n _] := Sum[FTcoeff[k]*Exp[I k x], {k, -n /2, n /2 }]
Plot[FT[x, nn] // Evaluate, {x, -Pi, Pi}, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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