method=0
%input('Automatic 0, Adaptive 1, Adaptive2 2: ');

format long

F=@(x) exp(-x.*x).*sin(12.*x)+1.;

a=0;
b=5;

x=linspace(a,b,1000);

tolerance = 1.e-6;
nInitial = 2; % if you use Adaptive2, this should be divisible by 4; for the other methods, divisible by 2
topLevel=10; % bottom level = 1, you cannot go below that

exact = quadl(F,a,b,1.e-15)

if(method==0)
   fignumber=1;
   figure(fignumber)
   plot(x,F(x))
   hold on
   title('Automatic')
   [resultAutomatic,errorEstimatedAutomatic,finestLevelAutomatic] = Automatic(a,b,nInitial,F,tolerance,topLevel);
   resultAutomatic
   errorEstimatedAutomatic
   finestLevelAutomatic
   errorRealAutomatic = exact-resultAutomatic
end

if(method==1)
   fignumber=2;
   figure(fignumber)
   plot(x,F(x))
   hold on
   title('Adaptive')
   [resultAdaptive,errorEstimatedAdaptive,finestLevelAdaptive] = Adaptive(a,b,nInitial,F,tolerance,topLevel);
   resultAdaptive;
   errorEstimatedAdaptive
   finestLevelAdaptive
   errorRealAdaptive = exact-resultAdaptive
end

if(method==2)
   fignumber=3;
   figure(fignumber)
   plot(x,F(x))
   hold on
   title('Adaptive2')
   [resultAdaptive2,errorEstimatedAdaptive2,finestLevelAdaptive2] = Adaptive2(a,b,nInitial,F,tolerance,topLevel);
   resultAdaptive2;
   errorEstimatedAdaptive2
   finestLevelAdaptive2
   errorRealAdaptive2 = exact-resultAdaptive2
end

hold off
