Integrals don't have to get very complicated before symbolic methods fail to work. Consider, for example, the integral $$\int_0^1\cos(x^3+x)\,dx:$$ there are no know symbolic methods, based on indefinite integration, that can be brought to bear on this problem.

Instead, we can sample the integrand at regular integrals and carry out an estimate based on this. One way of doing that is to approximate the function by a sequence of straight line segments, as in the figure. The area between each segment and the x-axis is a trapezium, meaning that if the width of the interval is h, and the y-values at each end of the interval are y_i and y_{i+1}, then the area of the trapezium is $$\frac{h}{2}\,(y_i+y_{i+1}).$$ The entire area between the curve and the x-axis, which is to say the integral, can be approximated by adding together several such trapezia. If there are n trapezia, and n+1 y-values (ordinates) running from y_0 to y_n, then the integral is approximately $$T_n=\frac{h}{2}\,(y_0+2\,y_2+2\,y_2+\dots+2\,y_{n-2}+2\,y_{n-1}+y_n).$$ This is called the trapezium rule.

The trapezium rule with four ordinates

For example, let us estimate $$\int_0^1\cos(x^3+x)\,dx,$$ using five ordinates (four intervals). The interval width, h, is 0.25. From the table, $$T_4=\frac{0.25}{2}\times(0.58385+2\times2.16432)=0.6141.$$

i | x_i |
y_1 | ||

0 | 0.00 |
1.0000 | ||

1 | 0.25 |
0.96493 | ||

2 | 0.50 |
0.81096 | ||

3 | 0.7 |
0.38843 | ||

4 | 1.00 |
-0.41615 | ||

Totals |
0.58385 | 2.16432 |

An alternative, which is often (though not always) more accurate, is to approximate the curve with a sequence of quadratic parabolic segments instead of straight lines. Each parabola requires three points to specify it, so each parabola spans two intervals. This method can only be used, therefore, if the number of intervals is even (and the number of ordinates, therefore, odd).

Figure 2: Approximating a curve (red) with a quadratic (blue): the basis of Simpson's rule

Now, consider the quadratic passing through the points (-h,y_0), (0,y_1) and (h,y_2). It's not hard to show that this has the equation $$y=\left(\frac{y_0-2y_1+y_2}{2h^2}\right)\,x^2+\left(\frac{y_2-y_0}{2h}\right)\,x+y_1.$$ If we integrate this between -h and h we get $$\frac{h}{3}\,(y_0+4\,y_1+y_2).$$ This would also have been the area if we'd situated the middle of the interval somewhere other than zero (though the calculations would have been harder). So from our quadratic approximation we get the estimate $$S_n=\frac{h}{3}\,(y_0+4\,y_2+2\,y_2+4\,y_3+\dots+4\,y_{n-3}+2\,y_{n-2}+4\,y_{n-1}+y_n),$$ where n must be even. This is called Simpson's rule.

From the table,

i | x_i |
y_1 | ||

0 | 0.00 |
1.0000 | ||

1 | 0.25 |
0.96493 | ||

2 | 0.50 |
|||

3 | 0.7 |
0.38843 | ||

4 | 1.00 |
-0.41615 | ||

Totals |
0.58385 | 1.35335 | 0.81096 |

$$S_4=\frac{0.25}{3}\,(0.58395+4\times1.35335+2\times0.81096)=0.6349.$$