% inte01.m
% fd, 04 octobre 2008, 04 mars 2025   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
printf("Calcul numerique d une integrale \n");
 function  A=ff(x);   A = 1/(1+x) ;     endfunction 
% function  A=ff(x);   A = sqrt(x) ;     endfunction 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

 format long
%                                 donnees generales  
n = 5000  ,           dx = 1/n ; 
xx = zeros(n+1,1) ; uu = zeros(n+1,1) ;
for j=1:n+1 ; 
xx(j) = (j-1) * dx ; uu(j) = ff(xx(j)) ; 
end ; 
% plot (xx, uu,'*;1 sur 1+x;' ) ; 
%              somme de Riemann a gauche 
zi1 = 0 ;  
for j=1:n ; zi1 = zi1 + dx * uu(j) ; end 
%              somme de Riemann a droite 
zi2 = 0 ; 
for j=2:n+1 ; zi2 = zi2 + dx * uu(j) ; end  
%              point milieu  
zi3 = 0 ; 
for j=1:n ; 
xxx = (xx(j)+xx(j+1))/2 ; 
zi3 = zi3 + dx * ff(xxx) ; end  
%              trapezes  
zi4 =  dx * ( ff(xx(1)) + ff(xx(n+1)) ) / 2    ; 
for j=2:n ;  
zi4 = zi4 + dx * ff(xx(j)) ; end  
%              Simpson  
zi5 =  dx * ( ff(xx(1)) + ff(xx(n+1)) ) / 6    ; 
for j=2:n ;   zi5 = zi5 + dx * ff(xx(j)) / 3 ; end  
for j=1:n ;   
xxx = (xx(j)+xx(j+1))/2 ; 
zi5 = zi5 + 2 * dx * ff(xxx) / 3 ; end  

zi1 , zi2 , zi3 , zi4 , zi5 
err5 = abs (zi5 - log(2)) 
err5 = abs (zi5 - 2/3) ; 
