Order of accuracy for trapezoidal integration I have a question regarding the order of accuracy for certain function using the trapezoidal formula.
I know that from theory the formula is second order accurate, but when working with matlab I get different answers.
I calculated the order of accuracy by plotting the logarithm of the error vs the logarithm of the step size $H$.
When using functions which are infinitely differentiable, for example $\sin(x)$ or $e^x$, I get a slope of $-2$, as expected. 
But when using the formula $\arctan(\sqrt{x})$ I get a slope of about -1.5. 
Why does the order of accuracy depend on the function that is integrated?

You can compute the error in the trapeze method by using integration by parts, let $f:(0,1) \to \Bbb R$.
Then the error is the sum of local errors:
$$E=\sum_{k=0}^{n-1} \left(\int_\frac{k}{n}^\frac{k+1}{n}\left(f(t)-\frac{f\left(\frac{k}{n}\right)+f\left(\frac{k+1}{n}\right)}{2} \right) dt \right)$$
integrating by parts:
$$\int_\frac{k}{n}^\frac{k+1}{n}\left(f(t)-\frac{f\left(\frac{k}{n}\right)+f\left(\frac{k+1}{n}\right)}{2} \right) =0-\int_\frac{k}{n}^\frac{k+1}{n}f'(t) \left(t-\frac{k+\frac{1}{2}}{n} \right) dt$$
and integrating by parts again:
$$\int_\frac{k}{n}^\frac{k+1}{n}\left(f(t)-\frac{f\left(\frac{k}{n}\right)+f\left(\frac{k+1}{n}\right)}{2} \right) =0+\int_\frac{k}{n}^\frac{k+1}{n}f''(t) \left(t-\frac{k}{n} \right)\left(t-\frac{k+1}{n} \right) dt$$

If $f''$ is bounded the idea to recover the standard bound is to write:
$$|E|=\left|\sum_{k=0}^{n-1}\int_\frac{k}{n}^\frac{k+1}{n}f''(t) \left(t-\frac{k}{n} \right)\left(t-\frac{k+1}{n} \right) dt \right|\leq \|f''\|_{\infty} \left|\sum_{k=0}^{n-1}\int_\frac{k}{n}^\frac{k+1}{n} \left(t-\frac{k}{n} \right)\left(t-\frac{k+1}{n} \right) dt \right|=\|f''\|_{\infty} n \cdot \frac{1}{6 n^3}$$

Here we can write, as $f''$ is not bounded:
$$E=\int_0^\frac{1}{n}f''(t)\left(t-0\right)\left(t-\frac{1}{n} \right)dt+\sum_{k=1}^{n-1}\int_\frac{k}{n}^\frac{k+1}{n}f''(t) \left(t-\frac{k}{n} \right)\left(t-\frac{k+1}{n} \right) dt$$
so for $f(t)=\sqrt{t}$ (in fact or any function that looks like $\sqrt{t}$ near $0$ and is smooth far from $0$):
$$|E|\leq\int_0^\frac{1}{n} \left|\frac{1}{4t^\frac{3}{2}}t\left(\frac{1}{n} -t\right)\right|dt+\sum_{k=1}^{n-1} \frac{1}{4n^2}\int_\frac{k}{n}^\frac{k+1}{n}|f''(t)| dt$$
so as $f''$ is of constant sign:
$$|E|\leq\frac{1}{3n^\frac{3}{2}}+\frac{1}{4n^2}\int_\frac{1}{n}^1 |f''(t) |dt=\frac{1}{3n^\frac{3}{2}}+\frac{1}{4n^2}\left|f'(1)-f'\left(\frac{1}{n} \right) \right|\leq\frac{1}{3n^\frac{3}{2}}+\frac{1}{4n^2}+\frac{1}{2n^\frac{3}{2}}$$
so the $\frac{3}{2}$ rate of convergence. Note that the problem lies near $t=0$, as for example the part between $0$ and $\frac{1}{n}$ contribute with a $n^\frac{-3}{2}$ in itself.
