Tag Archives: Numerical Integration Analysis

Numerical Integration- Simpson’s Rule

If you’ve kept up on recent blog posts, you’ll notice that in our data one method for integration seemed to work without any error. This method was Simpson’s Rule. This fact sparked our interest as to why does this method work so well? In particular, we noticed that it was almost flawless with cubic functions. Why is this? From the text, we were given the idea to algebraically compute Simpson’s rule approximation and compare it to the actual integral of the special case in which our interval is [-h,h] and n, our number of rectangles, being 2 for $f(x)=ax^{3}+bx^{2}+cx+d$.

We began by computing the actual integration:

$\int\limits_{-h}^{h} (ax^{3}+bx^{2}+cx+d) dx$ $\implies$ ($\frac{ax^{4}}{4}$ + $\frac{bx^{3}}{3}$ + $\frac{cx^{2}}{2}$ + $dx$ + $C$)|$^{h}_{-h}$

[$\frac{ah^{4}}{4}$ + $\frac{bh^{3}}{3}$ + $\frac{ch^{2}}{2}$ + $dh$ + $C$]-[$\frac{a(-h)^{4}}{4}$ + $\frac{b(-h)^{3}}{3}$ + $\frac{c(-h)^{2}}{2}$ + $d(-h)$ + $C$]

$= \frac{2bh^{3}}{3} + 2dh$

The equation for Simpson’s Rule is $\frac{1}{3}[f(x_{i-1})+4f(x_{i})+f(x_{i+1})]h$

In using two rectangles we get: $\frac{h}{3}[f(-h)+4f(0)+f(h)]$ $\implies$ $\frac{h}{3}[(a(-h)^{3}+b(-h)^{2}+c(-h)+d)+4d+(a(h)^{3}+b(h)^{2}+c(h)+d)]$

$= \frac{h}{3}(2bh^{2}+6d)= \frac{2bh^{3}}{3} + 2dh$

And thus we find that in cubic functions Simpson’s rule is the most accurate method for computing the integration.

For further research we can look at what happens when we change the bounds to [a,b]. We can also calculate the actual integral and the Simpson’s rule for different types of functions too see if this method really holds up as being the most accurate method for numerical integration.

 

Numerical Integration Analysis — Data!

We wanted to follow up with a post that contains a dump of our data. This includes, essentially, our percent error from the expected value of the given test functions:

  • $\cos{x}$ over [0, $\pi{}$]
  • $2x + 1$ over [0, 1]
  • $4-x^2$ over [0, 2]
  • $5x^3 – 6x^2 + 0.3x$ over [-1, 3]
  • $x^3$ over [-1, 3]
  • $x^3 -27x^2 + 8x$ over [0, 3]

We tested 5 different deltas (rectangle widths), $dx$, namely, $0.1$, $0.01$, $0.001$, $0.0001$, $0.00001$. But we are not going to put tables for each method and each delta; it’s just too much. However, we will do the first delta ($0.1$) and the last delta ($0.00001$).

Summary of Methods for $\cos{x}$ over [0, $\pi{}$]

Method Delta Percent Error
Trapezoidal $0.100000$ -0.33364
Trapezoidal $0.000010$ -0.00000
Midpoint $0.100000$ -0.20893
Midpoint $0.000010$ -0.00000
Simpsons $0.100000$ 0.05475
Simpsons $0.000010$ 0.00000
Left Rectangle $0.100000$ -4.97995
Left Rectangle $0.000010$ -0.00050
Right Rectangle $0.100000$ 4.31267
Right Rectangle $0.000010$ 0.00050

Summary of Methods for $2x + 1$ over [0, 1]

Method Delta Percent Error
Trapezoidal $0.100000$ -14.50000
Trapezoidal $0.000010$ -0.00150
Midpoint $0.100000$ -14.50000
Midpoint $0.000010$ -0.00150
Simpsons $0.100000$ 0.00000
Simpsons $0.000010$ 0.00000
Left Rectangle $0.100000$ -10.00000
Left Rectangle $0.000010$ -0.00100
Right Rectangle $0.100000$ -19.00000
Right Rectangle $0.000010$ -0.00200

Summary of Methods for $4-x^2$ over [0, 2]

Method Delta Percent Error
Trapezoidal $0.100000$ -0.42813
Trapezoidal $0.000010$ -0.00000
Midpoint $0.100000$ -0.33906
Midpoint $0.000010$ -0.00000
Simpsons $0.100000$ 0.00000
Simpsons $0.000010$ -0.00000
Left Rectangle $0.100000$ -3.81250
Left Rectangle $0.000010$ -0.00038
Right Rectangle $0.100000$ 2.95625
Right Rectangle $0.000010$ 0.00037

Summary of Methods for $5x^3 – 6x + 0.3x$ over [-1, 3]

Method Delta Percent Error
Trapezoidal $0.100000$ -16.93086
Trapezoidal $0.000010$ -0.00181
Midpoint $0.100000$ -17.10882
Midpoint $0.000010$ -0.00181
Simpsons $0.100000$ -0.00000
Simpsons $0.000010$ -0.00000
Left Rectangle $0.100000$ -7.67699
Left Rectangle $0.000010$ -0.00078
Right Rectangle $0.100000$ -26.18473
Right Rectangle $0.000010$ -0.00284

Summary of Methods for $x^3$ over [-1, 3]

Method Delta Percent Error
Trapezoidal $0.100000$ -14.87537
Trapezoidal $0.000010$ -2.44034
Midpoint $0.100000$ -15.01091
Midpoint $0.000010$ -2.44034
Simpsons $0.100000$ -2.43902
Simpsons $0.000010$ -2.43902
Left Rectangle $0.100000$ -8.68293
Left Rectangle $0.000010$ -2.43966
Right Rectangle $0.100000$ -21.06780
Right Rectangle $0.000010$ -2.44102

Summary of Methods for $x^3 – 27x^2 + 8x$ over [0, 3]

Method Delta Percent Error
Trapezoidal $0.100000$ -9.88570
Trapezoidal $0.000010$ -0.00103
Midpoint $0.100000$ -9.97363
Midpoint $0.000010$ -0.00103
Simpsons $0.100000$ 0.00000
Simpsons $0.000010$ -0.00000
Left Rectangle $0.100000$ -5.08032
Left Rectangle $0.000010$ -0.00051
Right Rectangle $0.100000$ -14.69108
Right Rectangle $0.000010$ -0.00154

Of course, we must mention that there is some rounding in the percent errors. Simpsons, Midpoint, and Trapezoidal methods are not perfect.