We finished the example from lecture 18, which was to calculate the Fourier series of the -periodic extension of the function defined on . The Fourier series is given by where we showed that and 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 -periodic odd extension of the function on .
We showed that to do this, first construct the odd extension to , and then construct the extension from there. Then the Fourier series is where we showed that 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