clear; figure;
n = 1:1000;
   
i=1; % initialize the index to the first index of y
for x = [0:0.1:8] * pi

    y(i) = sum(sin(n*x)./n);    % need element-wise division, n is a vector here
                                % save value in position i of y

    i = i + 1;                  % update the index for the next iteration

end

x = [0:0.1:8] * pi
plot(x,y);
axis([x(1) x(length(x)),  -pi/2, pi/2])
title('second method')