Exercise "adaptive integration"

  1. Implement an open quadrature open24 which calculates 2- and 4-point quadratures and returns the estimates of the integral and the error:
    function open24(f,a,b){
    	h=b-a;
    	f1=f(a+h*1/6); f2=f(a+h*2/6); f3=f(a+h*4/6); f4=f(a+h*5/6);
    	i2=(f2+f3)/2*h;
    	i4=(2*f1+f2+f3+2*f4)/6*h;
    	i=i4; err=abs(i4-i2); return {i:i,err:err};}
    
  2. Implement an adaptive integrator which estimates the integral with a given absolute (acc) and relative (eps) accuracy:
    function adapt(f,a,b,acc,eps){
    	y=open24(f,a,b); tol = acc+eps*abs(y.i);
    	if (y.err < tol) then return y;
    	else {
    		y1=adapt(f,a,(a+b)/2,acc/√[2],eps);
    		y2=adapt(f,(a+b)/2,b,acc/√[2],eps);
    		return {i:y1.i+y2.i, err:√[y1.err2 + y2.err2]}
    		}
    
  3. Reuse points.
  4. Calculate 01   ln(x)/√[x] dx = -4 with acc=eps=0.001 and estimate the number of need integrand evaluations.
  5. Test your implementation on some interesting integrals.