close all;

x = linspace(0,pi,300);
y = zeros(1, length(x));

%control parameters
tres = 0.005;
t = [0: tres: 5];
nmax = 20;
v=2;

for i = 1:length(t)
    
    % number of terms in the fourier series
    y = 0;
    for n = 1:nmax
        fterm = 4/pi*sin((2*n-1)*x)/(2*n-1)*cos((2*n-1)*v*t(i));
        y = y + fterm;
        plot(x,fterm);
        hold on;
    end
    
    plot(x,y,'r','LineWidth',1);
    axis([0 pi -2 2]);
    drawnow;
    hold off;
    
end

