% script per la soluzione del punto 2
%
% FB 12 Jan 2007

figure(1)

NP = 251;

x = linspace( -pi, pi, NP );

Fx = zeros( 1, NP );

for k = 1:25
    
    yk = 1/(2*k+1) * cos( (2*k+1)*x );
    Fx = Fx + yk ;
       
    if k > 6 break; end
     
    subplot( 2, 3, k )
    plot( x, yk, 'color', [0 k/6 (7-k)/6] );

    hold on
    plot( [-pi pi ], [0 0], 'k-', 'LineWidth', 2.0 );
    plot( [0 0], [-0.4 0.4], 'k-',  'LineWidth', 2.0 );

    axis tight
    xlabel('\it x');
    ylabel('\it f_k(x)')
    
    titolo = sprintf('Grafico per k = %d', k );
    title(titolo)
      
end

figure(2)

hold on 
plot( x, Fx, 'color', [ 1 1 0 ] );
plot( [-pi pi ], [0 0], 'k-', 'LineWidth', 2.0 );
plot( [0 0], [-1 1], 'k-',  'LineWidth', 2.0 );
axis tight

xlabel('\it x');
ylabel('\it F_k(x)', 'Rotation',0, ...
    'Position', [-3.5 1 0])

title('Grafico di F(x)')

