function A26

%maximale Anzahl von Integrationspunkten
nmax=1000;
% Gitterweite h=2 pi /n
h=2*pi./[1:nmax];
loglog(h,err('f1',nmax),'b-',h,err('f2',nmax),'r-',h,err('f3',nmax),'g-',h,err('f4',nmax),'c-');
legend('x','(2\pi-x)x','(2\pi-x)^2x^2','cos(x)e^{sin(x)}');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function e=err(f,nmax);
% Ergebnisse
Q=zeros(1,nmax);
% n: Anzahl Integrationspunkte
for n=1:nmax
 x=linspace(0,2*pi,n+1);
 x=x(1:end-1);
 y=feval(f,x);
 Q(n)=sum(y)/n*2*pi;
end;
% maximale Fehlerwerte
supQ=zeros(size(Q));
for i=1:length(Q)
  supQ(i)=max(abs(Q(i:end)));
end;
e=supQ;
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function y=f1(x)

y=x-pi;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function y=f2(x)

y=(2*pi-x).*x-2*pi^2/3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
function y=f3(x)

y=((2*pi-x).*x).^2 -8/15*pi^4;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function y=f4(x)

y=cos(1*x).*exp(sin(1*x));
