% % hw00code.m -- djm -- 04 jan 2009 % clear % interval (-L < x < +L) L = 1; % parameters Nterms = 15; Npts = max(4*Nterms,256); % vector of plotting points dx = 2*L/Npts; x = -L:dx:L; % summation loop Ssum = 0; % j = 1, 2 ... Nterms for k = 1:1:Nterms Ssum = Ssum + (1/(2*k-1))*sin((2*k-1)*pi*x); end Ssum = (4/pi)*Ssum; % make a plot % % initialize a figure figure(1); clf % plot red line plot([-L 0 0 L],[-1 -1 1 1],'r'); % multiple plots: type "help hold" at matlab prompt hold on % plot sum with points (thick curve for emphasis) plot(x,Ssum,'b','linewidth',2); if(Npts<=1024) plot(x,Ssum,'k.'); end % add info title(['\bf fourier series (example p299): k=1 to ' num2str(Nterms) ' terms'],'fontsize',14) xlabel('\bf x-axis','fontsize',12) ylabel('\bf partial sum, S_{2N-1}(x)','fontsize',12)