% This program plots partial sums of the Fourier series of f(x)=1_{0,1/2}

x = (0:0.0001:1);
Lmax = 100;

Phi = zeros(Lmax+1,length(x));

Phi(1,:) = 0.5 + (2/pi)*sin(2*pi*x);

for n=1:Lmax
    Phi(n+1,:) = Phi(n,:) + (2/(pi*(2*n+1)))*sin(2*pi*(2*n+1)*x);
end

figure(1)
plot(x,Phi(1,:))
hold on
for L=2:10:100
    plot(x,Phi(L,:))
end
grid on

figure(2)
plot(x,Phi(Lmax,:))
grid on
