Numerical Integration Report

Authors Avatar

Ali Adnan Ahmed

Numerical Integration

08-01-2007

Numerical Integration

Ali Adnan Ahmed

08-01-2007

Abstract:

For functions in Physics that cannot be integrated exactly, it is appropriate to use alternative, numerical techniques to calculate the integral. I examined two of these methods. The Trapezium Rule and Simpson’s Rule. By using the given relationship of the error being inversely proportional to the number of strips to the power of another number, m, I plotted a log-log graph thus calculating that the power when using the Trapezium rule is 1, and the power when using the Simpson’s rule is approximately 3.75. This proves that the Simpson’s rule is a far more accurate way of carrying out numerical integration.

Introduction:

The trapezium rule is a way of estimating the area under a curve. We know that the  is also given by , therefore the trapezium rule can also be used to estimating integrals. This comes in use when it is difficult to find the integral of a function. The Simpson’s Rule works in a similar way to the Trapezium Rule; however it uses polynomials to split the curve rather than just straight lines. Theoretically this should make it a more accurate approximation. To find out to what degree this is true,I a computer program was designed which carried out the Trapezium Rule and Simpson’s Rule, for a given integral, for a specified number of strips. For each number of strips i will calculate the error value between the numerical answer and the exact answer.

The formula I will be integrating will be y = 1/x, with limits 1 and 10.

The exact value is found by integrating this function.

dy/dx = lnx + c.

With limits 1 and 10, the exact value will be ln10.

Significantly large numbers of strips will be used to get a large spread of results, which will enable me to compare the accuracies of the two different methods.

Theory:

The trapezium rule works by splitting the curve into ‘’strips’’ in the shape of trapeziums. Then the area of each trapezium is calculated individually, with the sum of all the individual trapeziums representing the total value of the intergral.

The diagram briefly explains this. Again, I will be using the curve y=1/x, with limits 1 and 10. In the diagram I have decided to use 4 strips.

The total value of the integral will be the sum of the areas of trapezium 1,2,3 and 4.

Clearly from above you can see that it is just a rough estimate, showing that the higher the number of strips used, the more accurate the value obtained will be.

The formula which is used to calculate an Integral using Trapezium Rule is

I = dx/2 x (y0 + 2(y1 + y2 + y3….yn-1) + yn)

Where dx=(b-a)/2        dx= height of each strip

y1 + y2…. Are the corresponding y values.

In Simpson’s Rule, the variables are the same however the formula used is slightly different.


I = dx/3 x (y
0 + yn + 4(y1 + y3 +….. + yn-1) + 2(y2 + y4 +…..+ yn-2)

Also, this works only if the number of strips is even and is greater than or equal to 4.

Again, the greater the value of n, the more accurate the answer will be.

Experimental Method

To create the program, the programming language C++ was used, with the software Microsoft Visual Studio 2005.

Once the program headers and the main skeleton of the code had been set up, each variable was assigned as a double precision number, in order to get more accurate results. An integer counter was also implemented, to ensure that any loops were carried out the correct number of times. A command out, in which the user defines the upper and lower limits of integration, as well as the maximum number of strips, followed.

Join now!

cout <<"Enter the Lower limit"<<endl;

cin >> a;

cout <<"Enter the upper limit"<<endl;

cin >> b;

cout <<"Enter the MAX number of strips"<<endl;

cin >> nmax;

The number of strips to start off with was then defined. The trapezium rule, started with n=1, one strip, and Simpson’s Rule started with n=4, 4 number of strips.

A do…while loop, then began which calculated the Trapezium or Simpson’s rule, for each value of n, up to the maximum number of strips specified at the beginning by the user.

Also, dx was defined, right at the beginning of each code, ...

This is a preview of the whole essay