## Author: M. Turhan ÇOBAN
## Created: 2021-06-13
## ROberg İntegration with trapezoidal rule
function retval = romberg_integral (f,a,b)
  ##integral f(x)dx
  n=10;
  R=zeros(n,n);
  m=1;
  h=b-a;
  close=1;
  tol=1e-40;
  j=1;
  k=1;
  ret=0;
  R(1,1)=h/2.0*(f(a)+f(b));
while close>tol && j<n
  j++;
  h=h/2.0;
  R(j,1)=newton_cotes_integral(f,a,b,2*j,2);
  m*=2;
  for k=2:j
    if k==n
      R(j,k)=R(j,k-1)+(R(j,k-1)-R(j-1,k-1))/(4^k-1.0)
    else
      R(j,k)=R(j,k-1)+(R(j,k-1)-R(j-1,k-1))/(4^k-1.0);
    endif
    close=abs(R(j-1,j-1)-R(j,j));
    ret=R(j,k);
  endfor
endwhile
retval = ret;
endfunction
