Implementation of the Composite Simpson Rule for the approximation.
+
The following is an implementation of the Composite Simpson Rule for the approximation of definite integrals. More info -> wiki: https://en.wikipedia.org/wiki/Simpson%27s_rule#Composite_Simpson's_rule
+
The idea is to split the interval in an EVEN number N of intervals and use as interpolation points the xi for which it applies that xi = x0 + i*h, where h is a step defined as h = (b-a)/N where a and b are the first and last points of the interval of the integration [a, b].
+
We create a table of the xi and their corresponding f(xi) values and we evaluate the integral by the formula: I = h/3 * {f(x0) + 4*f(x1) + 2*f(x2) + ... + 2*f(xN-2) + 4*f(xN-1) + f(xN)}
+
That means that the first and last indexed i f(xi) are multiplied by 1, the odd indexed f(xi) by 4 and the even by 2.
+
In this program there are 4 sample test functions f, g, k, l that are evaluated in the same interval.
+
Arguments can be passed as parameters from the command line argv[1] = N, argv[2] = a, argv[3] = b
+
N must be even number and a<b.
+
In the end of the main() i compare the program's result with the one from mathematical software with 2 decimal points margin.
+
Add sample function by replacing one of the f, g, k, l and the assert
+
- Author
- ggkogkou
+