Trinh @ Bath

MA20223 Lecture 21

Table of Contents

Example 1

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, n1 and bn=4πn. We then used a Matlab code to plot it.

Fourier series of x^2

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

Example 2

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)n1)]]. We then used the following code to plot it.

Fourier series of odd extension of x^2

  1. x = linspace(-2*pi, 2*pi, 5000);
  2. Nvals = [1, 5, 10, 50];
  3.  
  4. b = @(n) 2/pi*(-pi^2*(-1).^n./n + 2./n.^2.*((-1).^n - 1));
  5.  
  6. figure(1); hold all
  7. for j = 1:length(Nvals)
  8. N = Nvals(j);
  9. S = 0;
  10. for n = 1:N
  11. S = S + b(n)*sin(n*x);
  12. end
  13. plot(x, S, 'LineWidth', 2)
  14. end
  15. xlabel('x');
  16. ylabel('f');
  17. title('Fourier series for the odd extension of x^2');
  18. xx = linspace(0, pi, 30);
  19. plot(xx, xx.^2, 'k', 'LineWidth', 2);
  20. grid on