## Lecture 3.4:Trapezoidal, Simpson's, and Midpoint integration formulas

Linear electrical circuits can be easily miniaturized if they do not include inductors, which are relatively large and bulky. Here we consider a simple resistor-capacitor (RC) one-port network driven by the same current source as in Lecture 3.1. When a current I = I(t) is applied to the input port, the voltage V = V(t) develops across the port terminals. The voltage output V(t) at the time instance t = T can be determined as a sum of the voltage drop across the resistor (which is R I(T) from the Ohm's law) and of the voltage drop across the capacitor (which is V0 + ST[I(t)]/C, where V0 is an initial voltage and ST[I(t)] denotes the integral of I(t) from initial time instance t = 0 to the present time instance t = T). If the input current I(t) can be measured (detected) at different times t = tk for k = 0,1,...,n, where t0 = 0 and tn = T, then the output voltage V(t) can be computed at the time t = T as

V(T) = R I(T) + V0 + ST[I(t)] / C.

Thus, the integral ST[I(t) must be estimated numerically from the given data set (tk,Ik). This is the problem of numerical integration. Since the function I = I(t) is not known between the data values t = tk, numerical interpolation must be applied first, from which different formulas of numerical integration can then be developed. This is a Newton-Cotes integration algorithm. The most important Newton-Cotes integration formulas are trapezoidal, Simpson's and midpoint rules.

### Trapezoidal rule

Consider a linear piecewise interpolation between the data values (tk,Ik) for k = 0,1,...,n (linear spline). In other words, two adjacent points can be connected by a straight line. Suppose also that the data set is equally spaced, i.e. tk = t0 + k h, where h is the step size. Then, the signed area under the curve I = I(t) between t = t0 and t = t1 (which is the integral Sh[I(t)]) can be approximated by the area of the trapezoid between (t0,I0) and (t1,I1):

Sh[I(t)] = 0.5 h (I0 + I1)

Summating areas of all n trapezoids between t = 0 and t = T, we obtain the composite trapezoidal rule for numerical integration:

ST[I(t)] = 0.5 h (I0 + 2I1 + 2I2 + ... + 2In-1 + In)

The truncation error of the composite trapezoidal rule has the order of O(h2), where the coefficient is proportional to the length of the interval, i.e. to T, and to the second derivative of I''(t), where t is in the intermediate interval: 0 < t < T. Thus, the trapezoidal rule is exact for a linear function I = I(t), while for other functions the error reduces in four times if the step size is reduced by half (i.e. if the number of trapezoids between t = 0 and t = T is doubled). Trapezoidal rule is quite popular in numerical integration, when the accuracy can be controled by doubling the number of elementary subintervals (trapezoids).

### Simpson's rule

Consider a quadratic interpolation between three points: (t0,I0), (t1,I1), and (t2,I2). The Newton interpolating polynomial is:

P2(t) = I0 + f[t0,t1] (t - t0) + f[t0,t1,t2] (t - t0)(t - t1),

where f[t0,t1] and f[t0,t1,t2] are the first and second divided differences (see Lecture 2.2). Integrating the polynomial P2(t), we find another approximation of the signed area under the curve I = I(t) between t = t0 and t = t2 (which is the integral S2h[I(t)]):

S2h[I(t)] = h (I0 + 4I1 + I2) / 3

If the whole interval T is divided into even number n of equally spaced subintervals, then the piecewise quadratic interpolation can be applied to each two adjacent subintervals. Notice that such a piecewise interpolation is not a quadratic spline since the quadratic interpolating polynomials P2(t) are not matched at different subintervals. Summating integrals of all n/2 quadratic polynomials P2(t) between t = 0 and t = T, we obtain the composite Simpson's rule for numerical integration:

ST[I(t)] = h (I0 + 4I1 + 2I2 + 4I3 + 2I4 + ... + 2In-2 + 4In-1 + In) / 3

The truncation error of the composite Simpson's rule has the order of O(h4), where the coefficient is proportional to the length of the interval, i.e. to T, and to the fourth derivative of the function I(4)(t), where t is in the intermediate interval: 0 < t < T. Thus, the Simpson's rule is exact for polynomial functions I = I(t) of the degree one, two, and three. For other functions the error reduces in sixteen times if the step size is reduced by half (i.e. if the number of subintervals between t = 0 and t = T is doubled).

### Midpoint rule

If the function I = I(t) has a singularity at the end of the interval, i.e. either at t = 0 or at t = T or at both, the trapezoidal or Simpson's integration formulas for ST[I(t)] are not useful, since the data values I0 or/and In diverge. Instead, it is more convenient to compute the integral ST[I(t)] from values of I(t) in the interior points: t1, t3, ..., tn-1 (assuming even number n of subintervals). The signed area under the curve I = I(t) between t = t0 and t = t2 (which is the integral S2h[I(t)]) can be approximated by the area of the rectangle centered at the midpoint (t1,I1):

S2h[I(t)] = 2 h I1

Replacing the function I(t) by a piecewise constant interpolation and summating areas of all n/2 rectangles between t = 0 and t = T, we obtain the composite midpoint rule for numerical integration:

ST[I(t)] = 2 h (I1 + I3 + I5 + ... + In-3 + In-1)

The truncation error of the composite trapezoidal rule has the order of O(h2), where the coefficient is proportional to the length of the interval, i.e. to T, and to the second derivative of I''(t), where t is in the intermediate interval: 0 < t < T. Midpoint rule can be used in combination with the trapezoidal or Simpson's rules, e.g., the two end subintervals can be integrated by the midpoint rule, while the remaining interior subintervals can be integrated by the trapezoidal rule.

Errors of numerical integration
Presents graphs of numerical integration for the current I(t)