Tag Archives: Numerical Analysis

Numerical Integration Analysis

Now that we have a number of numerical methods implemented, we want to compare them to see which method is best and in what circumstances.

We have a few test functions we were trying these methods over. Namely the following:

  • $\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]

Let’s start with some examples of our output.

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

Method Delta Percent Error
Midpoint $0.1$ -0.208927
Simpsons $0.1$ 0.054748
Right Rectangle $0.1$ 4.31267
Riemann $0.1$ 5.020046
Trapezoidal $0.1$ -0.33364
Left Rectangle $0.1$ -4.979954

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

Method Delta Percent Error
Midpoint $0.00001$ -0.00181
Simpsons $0.00001$ 0.00000
Right Rectangle $0.00001$ -0.00284
Riemann $0.00001$ -0.00103
Trapezoidal $0.00001$ -0.00181
Left Rectangle $0.00001$ -0.00078

Between these two sets of data, Let’s take a closer look at the magnitudes of the percent errors to see which method is more correct and then rank them.

Looking back at the first table, we can fairly easily tell that Simpsons rule is the best and Riemman sums was the worst. A little more difficult to pull out an order, so we made the computer compute the order: Simpsons, Midpoint, Trapezoidal, Right Rectangle, Left Rectangle, Riemann.

And same for the second table, we can easily see Simpsons was the best and Right Rectangle was the worst. And the order: Simpsons, Left Rectangle, Riemann, Trapezoidal, Midpoint, Right_rectangle.

Remember, when looking at the order between these two functions, we cannot say anything about each of the methods because we are changing two things in the comparison (the width of the rectangles summed and the function).

Now let’s take a closer look at the overall most correct method for all functions for each delta. That is, we will be varying the delta and looking at which method was the best.

Looking at a delta of $0.1$, we see that the Simpsons method is the most accurate for all our test functions. Interestingly though, with a delta of $0.01$ and $0.001$, the Midpoint method is better than Simpsons for $\cos{x}$, but Simpsons is still better for the other three. Moving to a delta of $0.0001$, we see Simpsons method is best for all functions again and remains to be for $0.00001$ as well.

So far, we can see that Simpsons method is amazing at single variable integration. But we will want to know how good? What’s the relative rates of accuracy increase between the methods?

Look for a follow up post where we post more data about our analysis and try to answer the above questions.

* Simpsons method looks to be $0.000$ here; this is the result of some rounding for presentation. The actual value is really close to zero but not quite zero.