Hands-on-Fourier Series; Approximation of Functions with MATLAB II

To construct the trigonometric polynomial of order M of the form

\begin{displaymath}
f(x)=\frac{A_0}{2}+\sum_{j=1}^{M}[A_jcos(jx)+B_jsin(jx)]
\end{displaymath}

based on the N equally spaced values

\begin{displaymath}
x_k=-\pi+ 2\pi \frac{k}{N},~for~k=1,2,\ldots,N
\end{displaymath}

The construction is possible provided that $2M+1\leq N$. The following http://siber.cankaya.edu.tr/ozdogan/NumericalComputations/mfiles/chapter4/tpcoeff.m program constructs vectors A and B that contain the coefficients $A_j$ and $B_j$, respectively, of the equation above of order M.

You are given the function $Y(X)=X$ for the interval $[-\pi ,\pi ]$.
  1. Use the MATLAB program given above to calculate $A_j$s and $B_j$s.
    (Hint: You should first calculate all the $Y$ values for a given $M$, say 100.)
  2. The following program will evaluate the $f(x)$ of order $M$ at a particular value of $x$. $A,B$ and $M$ values are taken from the previous item.

    \includegraphics[scale=1]{figures/4-16}
    Study the following commands:
    >>x=-pi:.01:pi
    >>y=tp(A,B,x,M)
    >>plot(x,y,X,Y,'o')
    
  3. To summarize; repeat the procedure for the $M$-values, 10, 20, 50, 100. Compare the results.
    Solution:

    \includegraphics[scale=1]{figures/4-17}

    save with the names calc.m and drawer.m. Then;
    >> drawer
    
Cem Ozdogan 2010-12-30