I was coding an algorithm to approximate the integral $\int_{0}^{1} f(x) dx\int_{0}^{1} cos(x)+1/10cos(10x)+1/50cos(50x) dx$ as i encountered some interessting graphs. When approximating for $N=2^k$ for $k\in \mathbb{N}$ intervals with an size of $h=\frac{b-a}{N}=\frac{1}{2^k}$ i realized that the error between the excact integration and the approximations (here: $|T(h)-I(f)| $ and $|S(h)-I(f)|$ with T being the Trapezodial sum and S being the Simpson sum) went down as assumed until a certain point number of intervals with the error in Simpson decreasing fast than the Trapezoid one (also excpected).
But at a certain interval size $h=\frac{1}{2^{15}}$ (therefor $2^{15}$ intervals) i realized that the error rate is certainly increasing. This goes so far, that even the boundary set for the maximum error $E_{Simpson}=-h^4(b-a)\frac{f^4(\xi)}{2880}$ and $E_{Trapezoid}=-h^2(b-a)\frac{f^2(\xi)}{12}$ for $a=0$ and $b=1$ got broken. As i am assuming my algorithm is completly correct i was interessted in how this boundary could be broken. An aspect could be computation errors due to very low numbers but i was thinking that there might be a mathematical reason behind it.
I am also sharing a plot with you (axis are written in german but Y-Axis meaning the absolute error and X-Axis meaning k with interval amount $2^k$, both axis scaled with Logarithm to base 2. Graph
I am interessted wether some of you have an explanation to this phenomen or if it is really just an data error due to the limits of computers.
Greetings, Florian
It looks like rounding error.
I ran trapz on octave and got:
The absolute error for $t30$ is greater than $t15$. Similar to your results.
I then ran a C++ program using $128$ binary bit floating point numbers and got:
The trapezoidal errors are now less than the estimated errors.
The C++ code uses gmp GNU Multiple Precision Arithmetic Library and mpreal a C++ interface to it.
The mpreal.h file should be in the same directory.
The build instruction on cygwin Linux is: