Ch5.2 Newton-Cotes Integration

Firstname Lastname

Introduction

  • Newton-Cotes integration methods estimate the area under a curve \( f(x) \) by using panels of successively smaller width.
  • For panels, rectangles and trapezoids are often used.

title

Introduction

  • These integration methods correspond to finding area under interpolating polynomials for values of \( f(x) \) on nodes \( x_k \) for each panel, and then adding up (composite Newton-Cotes).
    • Midpoint rule uses constant interpolation on panels.
    • Trapezoid rule uses linear interpolation on panels.

titletitle

Midpoint Rule

title

  • This method begins by finding midpoint of rectangular panels.
  • To compute area of panel, \( f \) is evaluated at midpoint to obtain height, then multiplied by width.
  • Areas of panels are added up to obtain an estimate of area under \( f(x) \) over \( [a,b] \).

Midpoint Rule

  • In the formula below, \( f \) is evaluated at panel midpoints, then multiplied by width \( h \), and added together.

\[ \small{ \int_a^b f(x)dx \cong \sum_{k=1}^m f \left( a + h \left(k - \frac{1}{2} \right) \right)h, \,\,\, h = \frac{b-a}{m} } \]

title

R Code: Midpoint Rule

midpt <- function (f, a, b, m = 100) {
nwidth = (b - a) / m
x = seq(a, b - nwidth,length.out = m) + nwidth / 2
y = f(x)
area = sum(y) * abs(b - a) / m
return ( area )
}

Example: Exact Value of Integral

\[ \small{ \int_0^1 x^2 dx = \frac{1}{3}x^3 |_0^1 = \frac{1}{3} } \]

title

Ex 1: Midpoint Rule

title

f <- function(x) { x^2 }
A1<-midpt(f,0,1,m = 10)
A2<-midpt(f,0,1,m = 100)
(A <- c(A1,A2))
[1] 0.332500 0.333325
(E <- abs(1/3 - A2))
[1] 8.333333e-06

Comments

  • As n increases, approximation of integral grows both more precise and more accurate.
  • This increasing precision and accuracy comes at cost of addition computing power.
  • More complex integrals will require more computing power to achieve less than desirable results.

title

Trapezoid Rule

  • Use formula for area of trapezoid for each panel, then add up.

\[ \small{ \begin{aligned} \int_a^b f(x)dx &\cong \sum_{k=1}^m \frac{f(c_k)+f(c_{k+1}) }{2}h \\ c_k & = a + h k, \,\,\, h = \frac{b-a}{m} \end{aligned} } \]

title

R Code: Trapezoid Rule

trap <- function (f, a, b, m = 100) {
x = seq(a, b, length.out = m + 1)
y = f(x)
p.area = sum((y[2:(m+1)] + y[1:m]))
p.area = p.area * abs(b - a) / (2 * m)
return (p.area )
}

Ex 2: Trapezoid Rule

title

f <- function(x) { x^2 }
A1<-trap(f,0,1,m = 10)
A2<-trap(f,0,1,m = 100)
(A <- c(A1,A2))
[1] 0.33500 0.33335
(E <- abs(1/3 - A2))
[1] 1.666667e-05

Ex 3: Trapezoid vs Midpoint

title

f <- function(x) { x^2 }
A1<-trap(f,0,1,m = 100)
A2<-midpt(f,0,1,m = 100)
c(A1,A2)
[1] 0.333350 0.333325
c(abs(1/3-A1),abs(1/3-A2))
[1] 1.666667e-05 8.333333e-06

Simpson's Rule

  • Simpson's Rule uses a quadratic interpolating polynomial for nodes and y-values; requires odd number of nodes.

title

Simpson's Rule: Formula

\[ \small{ \begin{aligned} \int_a^b f(x)dx &\cong \left[ f(a) + 4f(x_1) + 2f(x_2) + 4f(x_3) + 2f(x_4) + \cdots \right. \\ & \hspace{4in} \left. + 4f(x_{n-1}) + f(x_n) \right] h \\ h &= \frac{b-a}{3m} \end{aligned} } \]

title

R Code: Simpson's Rule

simp <- function (f, a, b, m = 100) {
x.ends = seq(a, b, length.out = m + 1)
y.ends = f(x.ends)
x.mids = (x.ends [2:( m + 1)] - x.ends [1:m]) / 2 + x.ends [1:m]
y.mids = f(x.mids )
p.area = sum(y.ends[2:(m+1)] + 4 * y.mids[1:m] + y.ends [1:m])
p.area = p.area * abs(b - a) / (6 * m)
return (p.area )
}

Ex 4: Simpson's Rule

title

f <- function(x) { x^2 }
A1<-simp(f,0,1,m = 4)
A2<-simp(f,0,1,m = 8)
c(A1,A2)
[1] 0.3333333 0.3333333
c(abs(1/3-A1),abs(1/3-A2))
[1] 0 0

Ex 5: Simpson's Rule

title

f <- function(x) { x^4 }
A1<-simp(f,0,1,m = 10)
A2<-simp(f,0,1,m = 100)
c(A1,A2)
[1] 0.2000008 0.2000000
c(abs(1/5-A1),abs(1/5-A2))
[1] 8.333333e-07 8.333334e-11

Conclusion

  • Newton-Cotes integration methods estimate the area under a curve \( f(x) \) by using panels of successively smaller width.
    • Midpoint rule uses constant interpolation on panels.
    • Trapezoid rule uses linear interpolation on panels.
    • Simpson's rule uses quadratic interpolation on panels.

title