ll=menu('Select a function.','pi-t','sign(pi -t)','exp(-t)','abs(pi -t)',...
'(pi-t).^2');
switch ll
  case 1 
    fun='pi-t';
  case 2
    fun='sign(pi-t)';
  case 3
    fun = 'exp(-t)';
  case 4
    fun='abs(pi-t)';
  case 5
    fun='(pi-t).^2'
end
kk=menu('Select N in S_N.','8','16','32','64','128');
npts=2^(kk+2);
[t,y,y_app,a,b]=part_sum(fun,npts);
a0=a(1);
a=a(2:npts+1);
b=b(1:npts);
err_unif=max(abs(y-y_app))
err_mean=sqrt(trapz(t,(y-y_app).^2)/(2*pi))
err_mean_par=sqrt(abs(trapz(t,y.^2)/(2*pi) - a0^2 - a*a'/2-b*b'/2))
a=[a0,a]; %Restore a = [a_0,a_1,a_2,...,a_npts]
s0=num2str(npts)
s1=num2str(err_mean);
s2=num2str(err_unif);
s3=num2str(err_mean_par);
plot(t,y,'k',t,y_app,'-.b',t,y+err_mean,'--r',t,y-err_mean,'--g')
legend(['y=',fun],['S_N, N=',s0],'y+\epsilon','y-\epsilon')
text(0.1,0.1,['\epsilon=mean error=',s1])
text(0.6,0.60,['Uniform error=',s2])
%text(0.6,0.40,['Mean error (Parseval)=',s3])
