x=[-4:0.01:4];
n=size(x,2);
y=zeros(n,1);
for i=1:n
  if (x(i)<=-pi)|((x(i)>0)&(x(i)<=pi))
    y(i)=1;
  else
    y(i)=-1;
  end;
end;
%hold off;
%plot(x,y,'black');
for i=1:n
  y(i)=0;
  for j=1:2:101
    y(i)=y(i)+sin(j*x(i))/j;
  end;
  y(i)=y(i)*4/pi;
end;
%hold on;
plot(x,y,'black');
axis([-4 4 -1.5 1.5]);
axis on;
