Write a program to evaluate $I=\int_a^bf(x)dx$ using the trapezoidal rule with $n$ subdivisions, calling the result $I_n$. Use the program to calculate the following integrals with $n=2,4,8,16,32,64,128,256$. Analyze empirically the rate of convergences of $I_n$ to $I$ by calculating the ratios $R_n=\frac{I_{2n}-I_n}{I_{4n}-I_{2n}}$.
a.$\int_0^{2\pi}\frac{dx}{2+cos(x)}$
b.$\int_{-4}^4\frac{dx}{1+x^2}$
c.$\int_0^1x^{5/2}dx$
My attempt at a pseudo-code:
Initialize $1-$dimensional arrays $I(8)$ and $R(6)$.
input function $\int_a^b f(x)$
for $m=1$ to $8$
$n = 2^m$
$h = \frac{(b - a)}{n}$
$t = f(a) + f(b)$
for $x = a + h$ to $b - h/2$ step $h$
$t = t + 2*f(x)$
next $x$
$t = t*(h/2)$
$I(m)=t$
next $m$
for $r = 1$ to $6$
$R(r)= (I(r+1) - I(r))/(I(r+2) - I(r+1))$
next $r$
Display values in arrays $I$ and $R$.