kk=menu('Select number of points.','8','16','32','64','128');
npts=2^(kk+2);
x=linspace(0,1,2049);
inx0=find(x<1/2);
inx1=find(x>=1/2);
y=[1-4*x(inx0).^2,4*(1-x(inx1)).^2];
incr=floor(2048/npts);
x0=x(1:incr:end);
y0=y(1:incr:end);
y_app=interp1(x0,y0,x);
err_unif=max(abs(y-y_app))
err_mean=sqrt(trapz(x,(y-y_app).^2))
s=num2str(err_mean);
t=num2str(err_unif);
plot(x,y,x,y_app,'--',x0,y0,'o')
text(0.55,0.95,['Mean error=',s])
text(0.6,0.85,['Uniform error=',t])