## Numerical integration

### Trapezoidal Rule:

The trapezoid rule in mathematics is a numerical integration method that we use to calculate the approximate value of the definite integral.

$$\int\limits_a^b f(x)dx$$

The rule is on the basis of an approximating value of the integral of f (x) by that of the linear function that passes through the points (a, f (a)) and (b, f (b)). The integral of this is always equal to the area of the trapezoid under the graph of the linear function. It follows that:

$$\int\limits_a^b f(x)dx = (b-a) \frac {f(a)+f(b)}{2}$$

### Composite Trapezoidal Rule:

• Assuming n+1 data points are evenly spaced, there will be n intervals over which to integrate
• The total integral can be calculated by integrating each subinterval and then adding them together:
$$\int\limits_a^b f(x)dx = \frac h2 \left[ f(x_0)+ 2\sum_{i=1}^{n-1} f(x_i) +f(x_n) \right]$$

### Simpson’s 1/3 Rule:

• Simpson’s 1/3 rule assumes 3 equispaced data/interpolation/integration points
• The integration rule is based on approximating using Lagrange quadratic (second degree) interpolation.
• The sub-interval is defined as [xo ,x2] and the integration point to integration point spacing equals
$$h=\frac {b-a}{2}$$
$$\int\limits_a^b f(x)dx = \frac h3 \left[ f(x_0)+4f(x_1)+f(x_2) \right]$$

### Composite Simpson’s 1/3 Rule:

• Simpson’s 1/3 rule can be used on a set of subintervals in much the same way the trapezoidal rule was, except there must be an odd number of points
• Because of the heavy weighting of the internal points, the formula is a little more complicated than for the trapezoidal rule:
$$\int\limits_a^b f(x)dx = \frac h3 \left[ f(x_0)+ 4\sum_{\substack{{i=1} \\ i, \ \text{odd} }}^{n-1} f(x_i)+ 2\sum_{\substack{{j=2} \\ j, \ \text{even} }}^{n-2} f(x_i) +f(x_n) \right]$$

### Simpson’s 3/8 Rule:

Simpson’s 3/8 rule is similar to Simpson’s 1/3 rule, the only difference being that, for the 3/8 rule, the interpolant is a cubic polynomial. Though the 3/8 rule uses one more function value, it is about twice as accurate as the 1/3 rule.

$$\int\limits_a^b f(x)dx = \frac {3h}{8} \left[ f(x_0)+3f(x_1)+3f(x_2)+f(x_3) \right]$$