# Numerical Integration: Summary and Conclusions

In this lab we looked at some various methods to compute integrals.
Those methods were, Riemann Sums: left rectangle, midpoint, and right rectangle, Trapezoidal, and Simpsons Rule.

We tested various methods and got results that showed that Simpsons Rule was very accurate, in many cases exact for cubic functions. We explored this more saw that Simpsons rule and the actual integration yielded the same result. This was also a proof of our conjectures about this method Finally we showed where the Simpsons Rule came from.

Now with all of that there are many other things that can be explored. Exploring more functions than cubics, (trig functions, logarithmic, exponential, etc.) and seeing which methods work best for those. Other routes one might take would be to explore higher dimensions. Some questions that could be explored would be how to test the accuracy for functions that don’t have an antiderivative? What methods would seem to work best? How small of an interval would be needed?

# Equation for Simpsons Rule: Proof and Derivation

We get in the book that an equation for a parabola for any three points is

$q(x)=A\frac {(x-b)(x-c)}{(a-b)(a-c)}+ B \frac{(x-a)(x-c)}{(b-a)(b-c)} +C\frac{(x-a)(x-b)}{(c-a)(c-b)}$

This is the formula for some parabola $q= mx^2+nx+p$ through the points, (a, A), (b,B), (c,C), we will take this as a given and go from there.

First we need to say we are working on a interval [-h, h]. Then our three points will be (-h, f(-h)), (0,f(0)), (h,f(h)).

First we write a generic equation for this quadratic. We can do this using the formula given and replacing the values:
$q(x)=f(-h)\frac {(x)(x-h)}{(-h)(-2h)}+ f(0) \frac{(x+h)(x-h)}{(h)(-h)} +f(h)\frac{(x+h)(x)}{(2h)(h)}$

Reducing this we get:

$q(x)=f(-h)\frac {x^2-xh}{2h^2}+ f(0) \frac{(x^2-h^2)}{-h^2} +f(h)\frac{x^2+xh}{2h^2}$

Now we integrate from [-h, h].

$\int^h_{-h} f(-h)\frac {x^2-xh}{2h^2}+ \int^h_{-h} f(0) \frac{(x^2-h^2)}{-h^2} +\int^h_{-h} f(h)\frac{x^2+xh}{2h^2}$

$=f(-h) (\frac{x^3}{6h^2} – \frac{x^2}{4h}) |_{-h}^h + f(0) (\frac{x^3}{-h^2} + x) |_{-h}^h + f(h) (\frac{x^3}{6h^2} + \frac{x^2}{4h}) |_{-h}^h$

Just taking the first integral:

$f(-h)((\frac{h^3}{6h^2} – \frac{h^2}{4h})-(\frac{-h^3}{6h^2} – \frac{h^2}{4h}))$

$=f(-h)\frac{h}{3}$

Evaluating the other integrals and reducing we get

$f(0)\frac{4}{3}h$ and $f(h)\frac{h}{3}$

So we have: $f(-h)\frac{h}{3} + f(0)\frac{4}{3}h +f(h)\frac{h}{3}$
$=\frac{h}{3}[f(-h)+4f(0)+f(h)]$

Now the points if you change the points we were working with to

$(x_{i-1},f(x_{i-1})),(x_i,f(x_{i})), (x_{i+1},f(x_{i+1}))$

we get
$=\frac{h}{3}[f(x_{i-1})+4f(x_{i})+f(x_{i+1})]$

This is the formula for Simpson’s Rule. This has major implications. It shoes how accurate it can be. This is accurate because when you have three points and a function that goes through them Simpsons rule finds a best fit quadratic for that region. Then we see that the formula does not depend on the actual equations themselves, but the points that one is evaluating them at and the interval they are going across.

# 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.

# Numerical Integration Methods-Motivation

I’m sure most of us have at least some experience with integrals being tricky and hard to compute. Whether it be trig substitution or some other method integrals can be very difficult. There are also functions, real functions that do not have an antiderivative, functions like:

$e^{-x^2}$ or $\frac{sin x}{x}$

However, there are ways to evaluate these integrals, and these are contained in the numerical methods. It is worth studying these methods one, to find the area under the cover for these certain functions, and two, to test the accuracy of these methods. There are certain methods in this chapter which my teammates will tell you more about.

# Numerical Integration

Numerical Integration is a lab exploring numerical methods for computing integrals. That is, using a computer program or calculator to find an approximation to the integral of some function $f(x)$.

Of course, because we are talking about integration we can’t go very far without the fundamental theorem of calculus: $F(x) = \int_a^x{f(t)dt}$. Further, in this lab we will talk about a few methods for numerically computing integrals, namely: Rectangle/ Riemann Sum, Trapezoidal Sum, Parabola/ Simpson’s Rule, just to name a few.

In Calculus courses, we are usually given “nice” functions, functions that are “easy” to solve or do not require numerical methods to compute. However, the set of functions that are “nice” is very small. Thus, we must resort to numerical methods. For example, there is no elementary antiderivative to the following integral:

$$\int{e^{e^x}dx}$$

But we can approximate it using one of the methods that we explore in this lab.

I was initially drawn toward this lab because other courses have introduced numerical integration and I have used other numerical methods by hand and wanted to further explore the topic by automating it and exploring the different methods.