We finished the example from lecture 18, which was to calculate the Fourier series of the 2π-periodic extension of the function f(x)=x2 defined on [0,2π]. The Fourier series is given by f(x)∼a02+∞∑n=1[ancos(nx)+bnsin(nx)] where we showed that a0=1π(2π)33,an=4n2, n≥1 and bn=−4π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π-periodic odd extension of the function f(x)=x2 on [0,π].
We showed that to do this, first construct the odd extension to [−π,π], and then construct the 2π extension from there. Then the Fourier series is f(x)∼∞∑n=1bnsin(nx) where we showed that bn=2π[−π2(−1)nn+2n2[(−1)n−1)]]. 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