Example 1: To run, save the following code in a file called chap10: function chap10 % Problem 10.3.8 % This function computes and graphs the partial sums of % the Fourier series for f(x) on the interval [-1/2, 1/2] % f(x) = 1/2 + x on [-1/2, 0]; f(x) = 1/2 - x on [0, 1/2] x = linspace(-0.5,0.5,100); for i=1:100 if x(i) <= 0 y(i) = 0.5 + x(i); %elseif x(i) <= 0 %y(i) = -1; else y(i) = 0.5 - x(i); end end for i=1:100 S1(i) = 0.25; S2(i) = S1(i) +2/(pi)^2*cos(2*pi*x(i)); S3(i) = S2(i) +2/((3*pi)^2)*cos(6*pi*x(i)); end plot(x,y,x,S1,'-',x,S2,'--',x,S3,'-.') legend('f(x)', 'S1', 'S2', 'S3') grid on % end function Example 2: To run, save the following code in a file called chap10_2: function chap10_2 % Problem 10.7.1 % This function computes and graphs the partial sums of % the Fourier series for f(x) on the interval [-pi, pi] % f(x) = -1 on [-pi, 0]; f(x) = 1 on [0, pi] x = linspace(-pi,pi,100); for i=1:100 if x(i) <= 0 y(i) = -1; else % x(i) <= 0 y(i) = 1; end end for i=1:100 S1(i) = 4/pi*sin(x(i)); S2(i) = S1(i) + 4/(3*pi)*sin(3*x(i)); S3(i) = S2(i) + 4/(5*pi)*sin(5*x(i)); end plot(x,y,x,S1,'-',x,S2,'--',x,S3,'-.') legend('f(x)', 'S1', 'S2', 'S3') grid on % end function