% % w03oe.m % % initialize workspace & set some control variables clear; Np = 500; % number of plot points % set x (row) vector (type "x" at the >>) dx = pi/Np; x = -pi+dx:dx:pi; xh = 0:dx:pi; % choose figure & clear (type "help hold") figure(1); clf; subplot(2,1,2); hold on % odd fourier series subplot(2,1,1); hold on plot(x,sin(x)); plot(xh,sin(xh),'r--','linewidth',2) title('\bf fourier sine series') xlabel('\bf x-axis') ylabel('\bf F_{odd}(x)') axis([-pi pi -1.1 1.1]) % even fourier series ye = 2/pi; for j = 2:2:64 ye = ye - (4/pi/(j^2-1))*cos(j*x); end subplot(2,1,2) plot(x,ye,'b'); plot(xh,sin(xh),'r--','linewidth',2) title('\bf fourier cosine series') xlabel('\bf x-axis') ylabel('\bf F_{even}(x)') axis([-pi pi -1.1 1.1])