clear all j=input('Enter the value of "N": '); if ischar(i)==1%Exception handling for char input fprintf('Please enter an integer value') break; end hold on for m=1:j cla axis([-4 4 -1 1]) axis equal line([-4 4], [0 0],'Color', 'k') line([0 0], [-4 4],'Color', 'k') a=line([0 pi], [1 1],'Color', 'b','LineWidth',2); line([0 -pi], [-1 -1],'Color', 'b','LineWidth',2) for i=-3:-1 text(i,-0.25,int2str(i)) text(0.2,i,int2str(i)) end for i=1:3 text(i+0.05,-0.25,int2str(i)) text(-0.2,i,int2str(i)) end for i=-3:-1 text(-0.05,i,'--') text(i,0,'|','FontSize',6) end for i=1:3 text(-0.05,i,'--') text(i,0,'|','FontSize',6) end x=-pi:0.05:pi; f2=0; xx=-pi:0.05:pi; for n=1:m f1=4*(sin((2*n-1)*x)/(2*n-1))/pi; f2=f2+f1; end yy=spline(x,f2,xx); p=plot(x,f2,xx,yy,'r','LineWidth',2); title(['At N=',int2str(m)]) ylabel('f(x)') set(gca,'XTick',-pi:pi/2:pi) set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) if m