My textbook gives me the error term for the Composite Trapezoidal Rule as this:
$-\frac{b-a}{12}h^2f''(\mu)$, where $\mu \in(a,b)$ and $f \in C^2 [a,b]$
I am using MatLab to produce approximations with the Composite Trapezoidal Rule for $\int_0^{0.99} \frac{1}{\sqrt{1-x^2}}{\rm d}x$ with the intervals $h = 0.01, 0.005, 0.0025, 0.00125, 0.000625$
Below is my table of the approximations by my code and the absolute error for each interval:
....h............S(h)...........abs. err...
0.010000 1.432052842622 0.002795989152
0.005000 1.429980957924 0.000724104453
0.002500 1.429439827337 0.000182973867
0.001250 1.429302728001 0.000045874530
0.000625 1.429268330467 0.000011476997
Evaluating the error with the error formula, however, gives me a very different number than what my code is spitting out. For example, evaluating the error term for $h = 0.01, a = 0, b = 0.99$, I end up with $0.437161725$. Should my approximation of the error be that off? Am I not using the error term properly?
You should be careful with this expression:
$$ {\rm err} = -\frac{b-a}{12}h^2f''(\mu) \tag{1} $$
The meaning is: there is a point $\mu \in (a,b)$ such that the error is given by this expression. To show this is true I calculate $S(h)$ for various values of $h$ and the absolute error $\epsilon$. I then find the value of $\mu$ guaranteed by Eq. (1), that is, the value of $\mu$ such that ${\rm err} = \epsilon$