function y=f(t)
  y=4.0./(1+t.^2)
endfunction

function y=rectangle(n)
  s=0
  for k=0:(n-1)
    s=s+f((2*k+1)/2/n)
  end
  y=s/n
endfunction

//Autre solution
function y=rectangle1(n)
  L=f([0:n-1]/n+1/2/n)
  y=sum(L)/n
endfunction

rectangle(3)
rectangle(50)
rectangle1(3)
rectangle1(50)

//Question 3
L=[]
for i=10:100
  L=[L,rectangle(i)-%pi];
end

plot2d(10:100,L)
logx=log(10:100);
logy=log(L);
  plot2d(logx,logy)
  // On trouve bien une droite de pente 
  a=(logy(91)-logy(1))/(logx(91)-logx(1))
  
  //Question 5
  
function y=trapeze(n)
  L=f([1:n-1]/n)
  y=(sum(L)+f(0)/2+f(1)/2)/n
endfunction

trapeze(100)-%pi
rectangle(100)-%pi
simpson(50)-%pi

function y=simpson(m)
  n=2*m
  Lpair=f((2*[1:m-1])/n)
  Limpair=f((2*[0:m-1]+1)/n)
  y=(2*sum(Lpair)+4*sum(Limpair)+f(0)+f(1))/6/m
endfunction

rectangle(100)-%pi
simpson(50)-%pi

//L=[]
//for i=10:50
//  L=[L,abs(simpson(i)-%pi)];
//end
//logx=log(10:50);
//logy=log(L);
//  plot2d(logx,logy)
//  // On trouve bien une droite de pente 
//  a=(logy(41)-logy(1))/(logx(41)-logx(1))