We finished the example from lecture 18, which was to calculate the Fourier series of the $2\pi$-periodic extension of the function $f(x) = x^2$ defined on $[0, 2\pi]$. The Fourier series is given by $$ f(x) \sim \frac{a_0}{2} + \sum_{n=1}^\infty [a_n \cos(nx) + b_n\sin(nx)] $$ where we showed that $$ a_0 = \frac{1}{\pi}\frac{(2\pi)^3}{3}, \qquad a_n = \frac{4}{n^2}, \ n \geq 1 $$ and $$ b_n = -\frac{4\pi}{n}. $$ We then used a Matlab code to plot it.

Fourier series of x^2

x = linspace(-pi, 3*pi, 5000); Nvals = [1, 5, 10, 50]; figure(1); hold all for j = 1:length(Nvals) N = Nvals(j); a0 = 1/pi*(2*pi)^3/3; S = a0/2; for n = 1:N S = S + 4/n^2*cos(n*x) - 4*pi/n*sin(n*x); end plot(x, S, 'LineWidth', 2) end xlabel('x'); ylabel('f'); title('Fourier series for x^2 on [0, 2*pi]'); xx = linspace(0, 2*pi, 50); plot(xx, xx.^2, 'k', 'LineWidth', 2); grid on

We then tackled the following problem: calculate the $2\pi$-periodic odd extension of the function $f(x) = x^2$ on $[0, \pi]$.

We showed that to do this, first construct the odd extension to $[-\pi, \pi]$, and then construct the $2\pi$ extension from there. Then the Fourier series is $$ f(x) \sim \sum_{n=1}^\infty b_n\sin(nx) $$ where we showed that $$ b_n = \frac{2}{\pi}\left[-\frac{\pi^2 (-1)^n}{n} + \frac{2}{n^2} [(-1)^n - 1)]\right]. $$ We then used the following code to plot it.

Fourier series of odd extension of x^2

x = linspace(-2*pi, 2*pi, 5000); Nvals = [1, 5, 10, 50]; b = @(n) 2/pi*(-pi^2*(-1).^n./n + 2./n.^2.*((-1).^n - 1)); figure(1); hold all for j = 1:length(Nvals) N = Nvals(j); S = 0; for n = 1:N S = S + b(n)*sin(n*x); end plot(x, S, 'LineWidth', 2) end xlabel('x'); ylabel('f'); title('Fourier series for the odd extension of x^2'); xx = linspace(0, pi, 30); plot(xx, xx.^2, 'k', 'LineWidth', 2); grid on

Last modified: 2020/03/20 21:22