Numerical Integration

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Newton-Cotes Gauss Legendre

Dr. Lim Soh Fong sflim@feng.unimas.my

How do you integrate this?

Analytical Integration
Numerical Integration
b

I
a

f ( x)dx

The

f(x) to be integrated is one of the following forms: A simple continuous function such as polynomial, an exponential, or a trigonometric function. b Eg. I [2 3x 2 7 x 4 ]dx [2 x x3 7 x5 ]b a
a

A complicated continuous function that is difficult or impossible to differentiate or integrate directly.

A tabulated function where values of x and f(x) are given at a number of discrete points, as is often the case with experimental or field data.

Complicated continuous function

i. Generate discrete values of f(x)

ii. Use numerical method to estimate the integral on the basis of the discrete points

This is the most common numerical integrations schemes. The strategy - replacing a complicated function or tabulated data simpler polynomial function for easy integration. Sampling points are equi-spaced in the domain of x Eg. Trapezoidal rule

Simpsons rule

Using

1st order polynomial:


b b

I
a

f ( x)dx
a

f1 ( x)dx

Where

the polynomial can be written as:


f1 ( x) f (a) f (b) f (a) ( x a) b a

Thus,

the integration result would be:


I
OR

(b a)

f (a) 2

f (b)

Trapezoidal rule

(b a) average height

Error of the Trapezoidal Rule (approximate)

When we employ the integral under a straight line segment to approximate the integral under a curve, error may be substantial:

Ea
where b.

1 f ( )(b 12

a )3

lies somewhere in the interval from a to


b

f ( )

f ( x)

f dx a

Example:
Use Trapezoidal Rule to numerically integrate f ( x) 0.2 25 x 200 x 2 675 x 3 900 x 4 400 x 5 from a=0 to b=0.8. The exact value of the integral is 1.640533. Find a percent relative true error and approximate error. Solution: The function values: f (0) 0.2
f (0.8) 0.232

Substitute into trapezoidal rule to yield:


I (b a ) f (a ) f (b) 2 0.2 0.232 0.8 2 0.1728

Percent relative true error (1.640533 0.1728) 100 89.5% t 1.640533 Approximate error

f ( x)
f ' ( x)
f ( x)
b

0.2 25 x 200 x 2
25 400x 2025x 2
0.8

675 x 3 900 x 4
3600x 3

400 x 5

2000x 4

400 4050 x 10800 x 2 8000 x3


0

f ( )

f ( x)

f dx a

( 400 4050 x 10800 x 2 8000 x3 )dx 0.8 0 60

f ( x)

Which can be substituted into equation to yield


Ea 1 f ( )(b 12 a)
3

Ea

1 ( 60)(0.8)3 12 2.56

The Multiple Application Trapezoidal Rule

In order to improve the accuracy of the trapezoidal rule, the integration interval can be divided into n segments of equal width. The areas of individual segments can then be added to yield the integral for the entire interval.
h I
x0

b n
x1

a
x2

x0

xn
xn

f ( x)dx
x1

f ( x)dx
xn
1

f ( x)dx

Substituting the trapezoidal rule for each integral yields:


I h f ( x0 ) 2
I

f ( x1 )

f ( x1 ) 2
f ( x0 ) 2

f ( x2 )
n 1

h
f ( xn )

f ( xn 1 ) f ( xn ) 2

f ( xi )
i 1

(b a)

2n

An error for multiple-application trapezoidal rule can be obtained by summing the individual errors for each segment:
f ( i) Ea nf (b a)3 f ( x) 2 12n

Thus, if the number of segments is doubled, the truncation error will be quartered.

Example:
Use two segment Trapezoidal Rule to numerically integrate f ( x) 0.2 25 x 200 x 2 675 x 3 900 x 4 400 x 5 from a=0 to b=0.8. The exact value of the integral is 1.640533. Find true error and approximate error.

Solution:
n 2 h b a 2 0.4 :

f (0) 0.2 f (0.4) 2.456 f (0.8) 0.232


n 1

f ( x0 ) 2 I (b a)
i 1

f ( xi ) 2n

f ( xn )

f ( i) Ea

nf

0.2 2(2.456) 0.232 I 0.8 1.0688 4 Et 1.640533 1.0688 0.57173 t Ea 0.83 ( 60) 0.64 2 12(2)
f ( x) f ( x) 400 4050 x 10800 x 2 8000 x3
0.8 0

34.9%

(b a)3 f ( x) 12n 2

( 400 4050 x 10800 x 2 8000 x3 )dx 0.8 0 60

Another

way to improve accuracy of an integral is to use higher-order polynomials SIMPSONS RULE

The

strategy use (n-1) order for total n number of points including a and b.

Simpsons 1/3 Rule


This

rule results when 2nd order interpolating polynomial is used. Means 3 points including a and b.
b b

I
a

f ( x)dx
a

f 2 ( x)dx

a I

x0
x2

x2

x0

( x x0 )( x x2 ) ( x x0 )( x x1 ) ( x x1 )( x x2 ) f ( x0 ) f ( x1 ) f ( x2 ) dx ( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 ) b a 2

I I

h f ( x0 ) 4 f ( x1 ) f ( x2 ) h 3 f ( x0 ) 4 f ( x1 ) f ( x2 ) (b a) 6

Simpsons 1/3 Rule

Single segment application of Simpsons 1/3 rule has a truncation error of:
Ea (b a)5 (4) f ( ) 2880 a b

Simpsons 1/3 rule is more accurate than trapezoidal rule.

Example:
Use Simpsons 1/3 Rule to numerically integrate
f ( x) 0.2 25 x 200 x 2 675 x 3 900 x 4 400 x 5 from a=0 to b=0.8. The exact value of the integral is 1.640533.

Solution:
f (0) 0.2 f (0.4) 2.456 f (0.8) 0.232

Use Simpsons 1/3 Rule,


I (b a) f ( x0 ) 4 f ( x1 ) 6 f ( x2 )

0.8

0.2 4(2.456) 0.2320 1.367467 6

Et

1.640533 1.367467
21600 48000x
0.8

0.2730667

16.6%

f '''' ( x)

( 21600 48000x)dx f 4( )
0

0.8 0

2400

Ea

(b a)5 (4) f ( ) 2880

Ea

0.2730667

Multiple-Application Simpsons 1/3 Rule

As in previous case, it is expected that the accuracy can be improved by dividing the integration interval into equispaced number of segments, n. It is limited to situations where there are an even number of segments and odd number of points.
I
I
x2 x0

f ( x)dx

x4 x2

f ( x )dx

xn xn
2

f ( x )dx

b a n

2h

f ( x0 ) 4 f ( x1 ) f ( x2 ) f ( x2 ) 4 f ( x3 ) 2h 6 6 f ( xn 2 ) 4 f ( xn 1 ) f ( xn ) 2h 6
n 1 n 2

f ( x4 )

f ( x0 ) 4 I (b a )
i 1,3,5

f ( xi ) 2
j 2,4,6

f (x j )

f ( xn )

3n

The estimated error: Ea

(b a)5 (4) f 4 180n

Example:
Use Multiple-Application version of Simpsons 1/3 Rule with n = 4 to numerically integrate
f ( x) 0.2 25 x 200 x 2 675 x 3 900 x 4 400 x 5

from a=0 to b=0.8. The exact value of the integral is 1.640533.

Solution:
n 4 (h 0.2) f (0.2) 1.288 f (0.6) 3.464 2.456 f (0) 0.2 f (0.4) f (0.8) 0.232
From Multiple-Application Simpsons 1/3 Rule
n 1 n 2

f ( x0 ) 4 I (b a )
i 1,3,5

f ( xi ) 2
j 2,4,6

f (x j )

f ( xn )

3n

0.8

0.2 4(1.288 3.464) 2(2.456) 0.232 1.623467 12

Et
Ea (b a) (4) f 180n4
5

1.640533 1.623467 0.017067 (0.8)5 ( 2400) 0.017067 4 180(4)

1.04%

Ea

Simpsons 3/8 Rule


This

rules is resulted from integration of 3rd order Lagrange interpolating polynomial to fit 4 points including a and b An odd-segment-even-point formula.
b b

I
a

f ( x)dx
a

f 3 ( x)dx f ( x3 )

3h f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) 8 (b a) h 3 (b a)5 (4) Ea f ( ) 6480 I

More accurate

Remarks: Simpsons 3/8 rule is used in conjunction with the 1/3 rule to permit evaluation of both even and odd numbers of segments.

Example: a) Use Simpsons 3/8 rule to integrate

f ( x)

0.2 25 x 200 x 2 675 x 3 900 x 4

400 x 5

from a=0 to b=0.8. b) Use Simpsons 3/8 rule in conjunction with Simpsons 1/3 rule to integrate the same function for five segments.

Solution: a) A single application of Simpsons 3/8 rule requires four equal spaced points
f (0) 0.2 f (0.5333) 3.487177
b b

f (0.2667) 1.432724 f (0.8) 0.232

Usea Simpsons 3/8 rule will give a


3h f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 ) 8 (b 0.2 3(1.432724 3.487177) 0.232 a) h 0.8 I 1.519170 3 8 (b a)5 1.519170 0.1213630 Et ett = 7.4% 7.4% Ea 1.640533 f (4) ( ) 64805 I

f ( x)dx

f 3 ( x)dx

Ea

(0.8) ( 2400) 0.1213630 6480

b)

The data needed for a 5-segment application (h=0.8/5=0.16)


f (0) 0.2 f (0.16) 1.296919 f (0.32) 1.743393 f (0.48) 3.186015 f (0.64) f (0.80) 3.181929 0.232

Integral of 1st 2 segments using Simpson' s 1/3 rule, 0.2 4(1.296919) 1.743393 0.3803237 6 Last 3 segments using Simpson' s 3/8 rule, I 0.32 1.743393 3(3.186015 3.181929) 0.232 8 Total integral is obtained by summing the 2 results, I 0.48 I Et
t

1.264754

0.3803237 1.264754 1.6450777 1.640533 1.6450777 0.28%


25

0.0045447

Strategy - positioning any two points on a curve to define a straight line that would balance the positive and negative errors. Not equi-spaced. Hence, the area evaluated under this straight line provides an improved estimate of the integral.

a) Trapezoidal rule.

b) An improved integral estimate results.

Method of Undetermined Coefficients


I c0 f (a) c1 f (b) The trapezoidal rule yields exact results when the function being integrated is a constant (Fig. a; y=1) or a straight line (Fig. b; y=x):
(b a ) / 2

c0 c1
(b a ) / 2

1 dx
(b a ) / 2

b a b a c0 c1 2 2 c0 c1 b a

x dx
(b a ) / 2

b a b a c0 c1 0 2 2 b a c0 c1 2 b a b a I f (a) f (b) 2 2

Solve simultaneously

Trapezoidal rule

Derivation of the Two-Point Gauss-Legendre Formula


I

c0 f ( x0 )

c1 f ( x1 )

Now, we have 4 unknowns (c0, c1, x0, x1) which require four conditions.
1

Constant

c0 f ( x0 ) c1 f ( x1 )
Linear
1

1 dx 2
1

Solved simultaneously c0 c1 1
x0
2 3

c0 f ( x0 ) c1 f ( x1 )
1

x dx 0
1

1 3 1 3 f 1 3

0.5773503 0.5773503 f 1 3

Parabolic

c0 f ( x0 ) c1 f ( x1 )
1

x dx
1

x1 I

Cubic

c0 f ( x0 ) c1 f ( x1 )
1

x 3 dx 0

Two-points Gauss-Legendre formula

Remark: Notice that the integration limits are from -1 to 1 for simplification purpose. For evaluating integral for other limits, a new variable, xd is introduced with an assumption of linear relationship with x.

a0

a1 xd

With lower limit (a) and upper limit (b) equation becomes:
x (b a) (b a) xd 2

dx

b a dxd 2

These 2 terms will be substituted to the integral eqn. The new function , f(xd) is evaluated at (-1/ 3) and (1/ 3)

Example:
Use two-point Gauss Legendre formula to numerically integrate
f ( x) 0.2 25 x 200 x 2 675 x 3 900 x 4 400 x 5

Between the limit of a=0 and b=0.8. The exact value of the integral is 1.640533.

Solution:
Before integrating the function, we must perform a change of variable so that the limits are from -1 to +1. To do this, we substitute a=0 and b=0.8 into this equation (b a) (b a) xd x 2 to yield x 0.4 0.4 xd and dx 0.4dxd Substituted both of these into original equation will give
0.8 0

(0.2 25 x 200 x 2 675 x3 900 x 4 400 x5 )dx


1 1

[0.2 25(0.4 0.4 xd ) 200(0.4 0.4 xd ) 2 675(0.4 0.4 xd )3 900(0.4 0.4 xd ) 4 400(0.4 0.4 xd )5 ]0.4dxd

Use right hand side to evaluate using Gauss quadrature.

xd xd 1

1 3

f f

1 3 1 3

0.516741 1.305873

Two-point Gauss-Legendre formula yields

I
t

0.516741 1.305837 1.822578 11.1%

Higher-Point Formulas
General form of higher-point version is

c0 f ( x0 ) c1 f ( x1 )

cn 1 f ( xn 1 )

Weighting factors c and function arguments x used in Gauss Quadrature Formulas.


Points Weighting Factors
c1 = 1.000000000 c2 = 1.000000000 c1 = 0.555555556 c2 = 0.888888889 c3 = 0.555555556 c1 = 0.347854845 c2 = 0.652145155 c3 = 0.652145155 c4 = 0.347854845

Function Arguments
x1 = -0.577350269 x2 = 0.577350269 x1 = -0.774596669 x2 = 0.000000000 x3 = 0.774596669 x1 = -0.861136312 x2 = -0.339981044 x3 = 0.339981044 x4 = 0.861136312

2 3

Points 5

Weighting Factors c1 = 0.236926885 c2 = 0.478628670 c3 = 0.568888889 c4 = 0.478628670 c5 = 0.236926885 c1 = 0.171324492 c2 = 0.360761573 c3 = 0.467913935 c4 = 0.467913935 c5 = 0.360761573 c6 = 0.171324492

Function Arguments x1 = -0.906179846 x2 = -0.538469310 x3 = 0.000000000 x4 = 0.538469310 x5 = 0.906179846 x1 = -0.932469514 x2 = -0.661209386 x3 = -0.2386191860 x4 = 0.2386191860 x5 = 0.661209386 x6 = 0.932469514

Example: Use the three-point Gauss Legendre formula to estimate the integral for the same function as previous example. Solution:

c0 f ( x0 ) c1 f ( x1 ) c2 f ( x2 ) 0.5555556 f ( 0.7745967) 0.8888889 f (0) 0.5555556 f (0.7745967) 0.2813013 0.8732444 0.4859876 1.640533

Error Analysis for Gauss Quadrature

Provided that the higher order derivatives do not increase substantially with increasing number of points (n), Gauss quadrature is superior to Newton-Cotes formulas.
2 2 n 3[( n 1)!]4 f (2n (2n 3)[( 2n 2)!]3
2)

Ea

( )

You might also like