Sei sulla pagina 1di 56

Numerical Integration

Integration

• Integration is the process of evaluating an indefinite integral or a


definite integral
Integral sign

ò f (x) dx
b x is called variable of
I= a the integration

Integrand

I is the total value, or summation, of


f(x) dx over the range from a to b:

• Graphically integration is simply to


find the area under a certain curve
between the two integration limits.
Integration
Example:

Solve ," - $"

Solution: Using power law

" #&' ./0 1(2 0314 (56730 ( ≠ −1


#
!" $" = ++ 1$$ 1 :/ :ℎ3 exp/(3(: 1($ $?@?$3
(+1
72 :ℎ1: (56730

" -&'
!" - $" = ++
5+1

"B
= ++
6
Numerical Integration

ò
Example: 2
sin( x )dx
The solution of this integral equation with Matlab is
1/2*2^(1/2)*pi^(1/2)*FresnelS(2^(1/2)/pi^(1/2)*x)
we cannot find this solution analytically by techniques in calculus.

Many such integrals cannot be evaluated explicitly. It is often faster


to integrate them numerically rather than evaluating them exactly
using a complicated antiderivative of f(x)
Numerical Integration Methods
Newton-Cotes formulas
• The most common numerical integration schemes.
• Based on replacing a complicated function or tabulated data with a
polynomial that is easy to integrate:

ò f (x) dx @ ò f (x) dx
b b
I= a a n
where fn(x) is an nth order interpolating polynomial.

• The integrating function


can be polynomials of
any order –
• for example,
(a) straight lines or
(b) parabolas.
Numerical Integration Methods

Newton-Cotes Formulas
• The integral can be approximated in one step or
in a series of steps to improve accuracy.

• There are two types of Newton-Cotes formulas,


open and closed.

• The Trapezoidal and Simpson’s rules are


examples of Newton Cotes formulas.
Numerical Integration Methods

Newton-Cotes Formulas
The Trapezoidal Rule
The trapezoidal rule is the first of the Newton-Cotes closed integration
formulas; it uses a straight-line approximation for the function:

I = ò f n ( x ) dx
b

é f (b ) - f (a ) ù
(x - a )ú dx
b
I = ò ê f (a) +
a
ë b-a û
f (a ) + f (b )
I = (b - a )
2
Numerical Integration Methods
Error of the trapezoidal rule

• An estimate for the local truncation


error of a single application of the
trapezoidal rule is:
1
Et = - f ¢¢(x )(b - a)
3

12
where x is somewhere between a and
b.
• This formula indicates that the error is
dependent upon the curvature of the
actual function as well as the distance
between the points.
• Error can thus be reduced by breaking
the curve into parts.
Single Application of the Trapezoidal Rule
Example 1.
Problem Statement. Use trapezoidal rule to numerically integrate
2

ò x dx
0
Solution:
The integrand function is f (x ) = x

The function values are f (0 ) = 0 & f (2 ) = 2


f (a ) + f (b )
Trapezoidal rule is given by I = (b - a )
2
f (2 ) + f (0 ) 2+0
\ I = (2 - 0 ) = 2. =2
2 2
Analytical solution
2 2
2
éx 1+1
ù éx 2
ù 22 03
ò0 x dx = êë1 + 1 + C úû = êë 2 + C úû = 2 + C - 3 - C = 2
0 0
Single Application of the Trapezoidal Rule
Example 2.
Problem Statement. Use trapezoidal rule to numerically integrate a higher order
polynomial.

from a = 0 to b = 0.8. The exact value of the integral can be determined analytically
to be 1.640533.

f (a ) + f (b )
I = (b - a )
2
Single Application of the Trapezoidal Rule
Example (Cont...)

The reason for this large error is evident


from the graphical depiction in Fig.

Notice that the area under the straight line


neglects a significant portion of the
integral lying above the line.

In actual situations, we would have no foreknowledge of the true value. Therefore,


an approximate error estimate is required.
Composite Trapezoidal Rule (Multiple-Application)
• Assuming n+1 data points are evenly spaced, there will be n intervals over which
to integrate.
• The total integral can be calculated by integrating each subinterval and then
adding them together:

ò fn (x) dx = ò fn (x) dx + ò fn (x) dx + "+ ò fn (x) dx


xn x1 x2 xn
I=
x0 x0 x1 x n-1

f (x0) + f (x1) f (x1) + f (x2 ) f (xn-1) + f (xn )


I = (x1 - x0 ) + (x2 - x1) + "+ (xn - xn-1)
2 2 2
hé n-1 ù
I = ê f (x0 ) + 2å f (xi ) + f (xn)ú
!! 2 ë i =1 û

Estimated
Error:
Multiple-Application Trapezoidal Rule
Example 3.
Problem Statement. Use the two-segment trapezoidal rule to estimate the integral of

from a = 0 to b = 0.8. The exact value of the integral can be determined analytically
to be 1.640533.
Multiple-Application Trapezoidal Rule
Example 4.
Problem Statement. For growth rates as given below

the number N of bacterial cells is given by

where N0 = 10 is the initial number of cells. Find the number N of bacterial


cells at the end of the measurements

Solution: Here, n = 6 (h=1)

Integrand f(t) = v(t)

f(0) = v(t=0)=1; f(1) = v(t=1)=2; f(2) = v(t=2)=5; f(3) = v(t=3)=11 ;


f(4) = v(t=4)=22; f(5) = v(t=5)=44; f(6) = v(t=6)=178 ;
Multiple-Application Trapezoidal Rule
Example 4 (Cont...)

f (0) + 2[ f (1) + f (2) + f (3) + f (4) + f (5)] + f (6)


I = (6 - 0) ×
2×6
1 + 2 × [2 + 5 + 11 + 22 + 44] + 178
= 6×
12
=173.5

=10 + 173.5
= 183.5 » 183 Number of cells cannot be a fraction, hence
should be rounded to the nearest lesser integer.
Numerical Integration Methods
Simpson’s Rules
• One drawback of the trapezoidal rule is that the error is related to the second
derivative of the function.
• More complicated approximation formulas can improve the accuracy for
curves - these include using (a) 2nd and (b) 3rd order polynomials.
• The formulas that result from taking the integrals under these polynomials are
called Simpson’s rules.
Numerical Integration Methods
Simpson’s 1/3rd Rule

• Simpson’s 1/3 rule corresponds to using second-order polynomials. Using


the Lagrange form for a quadratic fit of three points:

fn (x) =
(x - x1 ) (x - x2 ) f x + (x - x0 ) (x - x2 ) f x + (x - x0 ) (x - x1 ) f x
( 0) ( 1) ( 2)
( 0 1) ( 0 2 )
x - x x - x ( 1 0) ( 1 2)
x - x x - x ( 2 0 ) ( 2 1)
x - x x - x

• Integration over the three points simplifies to:

I = ò f n ( x ) dx
x2

x0

h
I= [ f (x0 ) + 4 f (x1 ) + f (x2 )]
3
Numerical Integration Methods
Error of Simpson’s 1/3 Rule
• An estimate for the local truncation error of a single application of
Simpson’s 1/3 rule is:
1
f (4 ) (x )(b - a)
5
Et = -
2880
where again x is somewhere between a and b.
• This formula indicates that the error is dependent upon the fourth-derivative
of the actual function as well as the distance between the points.
• Note that the error is dependent on the fifth power of the step size (rather
than the third for the trapezoidal rule).
• Error can thus be reduced by breaking the curve into parts.
Single Application of Simpson’s 1/3 Rule
Example 5.
Problem Statement. Use Simpson’s 1/3 rule to numerically integrate
2

ò x dx
0
Solution:
The integrand function is f (x ) = x

The function values are f (0 ) = 0, f (1) = 1 & f (2 ) = 2


h
Simpson’s 1/3 rule is given by I= [ f (x0 ) + 4 f (x1 ) + f (x2 )]
3
2
\ I = [0 + 1 + 2] = 2
3
Analytical solution
2 2
2
éx 1+1
ù éx 2
ù 22 03
ò0 x dx = êë1 + 1 + C úû = êë 2 + C úû = 2 + C - 3 - C = 2
0 0
Single Application of Simpson’s 1/3 Rule
Example 6.
Problem Statement. Use Simpson’s 1/3 rule to numerically integrate

from a = 0 to b = 0.8. The exact value of the integral can be determined analytically
to be 1.640533.

h
I= [ f (x0 ) + 4 f (x1 ) + f (x2 )]
3
Composite Simpson’s 1/3 rule (Multiple-Application)
• Simpson’s 1/3 rule can be used on a
set of subintervals in much the same
way the trapezoidal rule was, except
there must be an odd number of
points.
• Because of the heavy weighting of the
internal points, the formula is a little
more complicated than for the
trapezoidal rule:

ò fn (x) dx = ò fn (x ) dx + ò fn (x ) dx +"+ ò fn (x) dx


xn x2 x4 xn
I= x0 x0 x2 x n-2

h h h
I=
3
[ f ( 0)
x + 4 f ( 1 ) ( 2 )] [ ( 2 )
x + f x +
3
f x + 4 f ( 3 ) ( 4 )]
x + f x +"+
3
[ f (xn-2 ) + 4 f (xn-1 ) + f (xn )]

é ù Estimated Error:
hê ú
n-1 n-2
I = ê f (x0 ) + 4 å f (xi ) + 2 å f (xi ) + f (xn )ú
3
êë i=1 j=2
úû
!! i, odd j, even
Numerical Integration Methods
Simpson’s 3/8 rule
• Simpson’s 3/8 rule corresponds to using
third-order polynomials to fit four points.
Integration over the four points simplifies
to:

I = ò f n ( x ) dx
x3

x0

3h
I= [ f (x0 ) + 3 f (x1 ) + 3 f (x2 ) + f (x3 )]
8

• Simpson’s 3/8 rule is generally used in


concert with Simpson’s 1/3 rule when the
number of segments is odd.

Estimated Error:
Simpson’s 3/8th Rule
Example 9.
Problem Statement.

3h
I= [ f (x0 ) + 3 f (x1 ) + 3 f (x2 ) + f (x3 )]
8
Simpson’s 3/8th Rule
Example 9. (cont…)
Simpson’s 3/8th Rule
Example 9. (cont…)
Numerical Integration Methods
Basis of the Gauss–Legendre Method
(Gaussian Quadrature)
Previously, the Trapezoidal Rule was developed by the method of
undetermined coefficients. The result of that development is summarized
below
b

ò f ( x)dx » c f (a) + c
a
1 2 f (b)

b-a b-a
= f (a) + f (b)
2 2
The two-point Gauss Quadrature Rule is an extension of the Trapezoidal
Rule approximation where the arguments of the function are not
predetermined as a and b but as unknowns x1 and x2. In the two-point
Gauss Quadrature Rule, the integral is approximated as
b
I = ò f ( x )dx » c1 f ( x1 ) + c 2 f ( x 2 )
a
Numerical Integration Methods
Basis of the Gauss–Legendre Method
(Gaussian Quadrature)

The four unknowns x1, x2, c1 and c2 are found by assuming that the formula
gives exact results for integrating a general third order polynomial,
f ( x ) = a0 + a1 x + a2 x 2 + a3 x 3 .
Hence

( )dx
b b
2 3
ò f ( x )dx = a +
ò 0 1 a x + a 2 x + a 3 x
a a
b
é x x2
x ù 3 4
= êa0 x + a1 + a2 + a3 ú
ë 2 3 4 ûa
æ b2 - a2 ö æ b3 - a3 ö æ b4 - a4 ö
= a0 (b - a ) + a1 çç ÷÷ + a 2 çç ÷÷ + a3 çç ÷÷
è 2 ø è 3 ø è 4 ø
Numerical Integration Methods
Basis of the Gauss–Legendre Method
(Gaussian Quadrature)
It follows that

( ) ( )
b
2 3 2 3
ò f ( x )dx = c1 a0 + a1 x1 + a 2 x1 + a3 x1 + c2 a0 + a1 x2 + a 2 x2 + a3 x2
a

Equating Equations the two previous two expressions yield

æ b2 - a2 ö æ b3 - a3 ö æ b4 - a4 ö
a0 (b - a ) + a1 çç ÷÷ + a 2 çç ÷÷ + a3 çç ÷÷
è 2 ø è 3 ø è 4 ø

( ) (
2 3
= c1 a0 + a1 x1 + a2 x1 + a3 x1 + c2 a0 + a1 x2 + a2 x2 + a3 x2
2 3
)
= a (c + c ) + a (c x + c x ) + a (c x ) ( )
2 2 3 3
0 1 2 1 1 1 2 2 2 1 1 + c2 x2 + a3 c1 x1 + c2 x2
Numerical Integration Methods
Basis of the Gauss–Legendre Method
(Gaussian Quadrature)
Since the constants a0, a1, a2, a3 are arbitrary

b - a = c1 + c2 b2 - a2
= c1 x1 + c2 x2
2
b3 - a3 2 2 b4 - a4 3 3
= c1 x1 + c2 x2 = c1 x1 + c2 x2
3 4
The previous four simultaneous nonlinear Equations have only one
acceptable solution,

æ b - a öæ 1 ö b + a æ b - a öæ 1 ö b + a
x1 = ç ÷ç - ÷ + x2 = ç ÷ç ÷ +
è 2 øè 3ø 2 è 2 øè 3 ø 2

b-a b-a
c1 = c2 =
2 2
Numerical Integration Methods
Basis of the Gauss–Legendre Method
(Gaussian Quadrature)

Hence Two-Point Gaussian Quadrature Rule

ò f ( x)dx » c1 f (x1 ) + c2 f (x2 )


a

b-a æb-a æ 1 ö b+aö b-a æb-a æ 1 ö b+aö


= f çç ç- ÷ + ÷÷ + f çç ç ÷+ ÷÷
2 è 2 è 3ø 2 ø 2 è 2 è 3ø 2 ø
Numerical Integration Methods
Higher Point Gaussian Quadrature Formulas
b

ò f ( x)dx » c f ( x ) + c
a
1 1 2 f ( x2 ) + c3 f ( x3 )

is called the three-point Gauss Quadrature Rule.


The coefficients c1, c2, and c3, and the functional arguments x1, x2, and x3
are calculated by assuming the formula gives exact expressions for
integrating a fifth order polynomial

ò (a + a1 x + a 2 x 2 + a3 x 3 + a 4 x 4 + a5 x 5 )dx
b
0
a

General n-point rules would approximate the integral


b
ò f ( x )dx » c1 f ( x1 ) + c 2 f ( x 2 ) + . . . . . . . + c n f ( x n )
a
Numerical Integration Methods
Arguments and Weighing Factors for n-point Gauss
Quadrature Formulas

Table 1: Weighting factors c and function


arguments x used in Gauss Quadrature Formulas.
In handbooks, coefficients and
Points Weights Gauss Points
arguments given for n-point or or
Gauss Quadrature Rule are Weighting Function
Factors (c) Arguments (x)
given for integrals [Coefficients] [roots]
2 c1 = 1.000000000 x1 = -0.577350269
1 n c2 = 1.000000000 x2 = 0.577350269
ò g( x )dx @ å ci g( xi ) 3 c1 = 0.555555556 x1 = -0.774596669
-1 i =1 c2 = 0.888888889 x2 = 0.000000000
c3 = 0.555555556 x3 = 0.774596669
as shown in Table 1. 4 c1 = 0.347854845 x1 = -0.861136312
c2 = 0.652145155 x2 = -0.339981044
c3 = 0.652145155 x3 = 0.339981044
c4 = 0.347854845 x4 = 0.861136312
Arguments and Weighing Factors for n-point Gauss
Quadrature Formulas
Table 1 (cont.) : Weighting factors c and function arguments x used in
Gauss Quadrature Formulas.
Points Weighting Function
Factors (c) Arguments (x)

5 c1 = 0.236926885 x1 = -0.906179846
c2 = 0.478628670 x2 = -0.538469310
c3 = 0.568888889 x3 = 0.000000000
c4 = 0.478628670 x4 = 0.538469310
c5 = 0.236926885 x5 = 0.906179846

6 c1 = 0.171324492 x1 = -0.932469514
c2 = 0.360761573 x2 = -0.661209386
c3 = 0.467913935 x3 = -0.2386191860
c4 = 0.467913935 x4 = 0.2386191860
c5 = 0.360761573 x5 = 0.661209386
c6 = 0.171324492 x6 = 0.932469514
Arguments and Weighing Factors for n-point
Gauss Quadrature Formulas
1
So if the table is given for ò g( x )dx integrals, how does one solve
b -1

ò f ( x )dx ? The answer lies in that any integral with limits of [a , b]


a
can be converted into an integral with limits [- 1, 1] Let

x = mt + c
If x = a , then t = -1
Such that:
If x = b , then t= 1

b-a
m=
2
Arguments and Weighing Factors for n-point
Gauss Quadrature Formulas

Then b+a Hence


c=
2

b-a b+a b-a


x= t+ dx = dt
2 2 2

Substituting our values of x, and dx into the integral gives us

b 1
æb-a b+aöb-a
ò
a
f ( x )dx = ò f ç
-1 è
2
t+ ÷
2 ø 2
dt
Numerical Integration Methods
Gauss–Legendre Method (Gaussian Quadrature)
Example 10.

a) Use two-point Gauss Quadrature Rule to approximate the distance

covered by a rocket from t=8 to t=30 as given by

30
æ é 140000 ù ö
x = ò ç 2000 ln ê ú - 9.8t ÷dt
8è ë140000 - 2100t û ø

b) Find the true error, Et for part (a).

c) Also, find the absolute relative true error, Îa for part (a).
Gauss–Legendre Method (Gaussian Quadrature)
Problem 10 (Cont…)
Solution
First, change the limits of integration from [8,30] to [-1,1]
by previous relations as follows
30
30 - 8 1 æ 30 - 8 30 + 8 ö
ò f ( t )dt = ò fç x+ ÷dx
8 2 -1 è 2 2 ø
1
= 11 ò f (11x + 19)dx
-1
Next, get weighting factors and function argument values from Table 1
for the two point rule, c1 = 1.000000000
x1 = -0.577350269
c 2 = 1.000000000

x 2 = 0.577350269
Gauss–Legendre Method (Gaussian Quadrature)
Problem 10 (Cont…)

Now we can use the Gauss Quadrature formula


1
11 ò f (11x + 19)dx » 11c1 f (11x1 + 19) + 11c2 f (11x2 + 19)
-1

= 11 f (11( -0.5773503 ) + 19) + 11 f (11( 0.5773503 ) + 19)


= 11 f ( 12.64915 ) + 11 f ( 25.35085 )
= 11( 296.8317 ) + 11( 708.4811)
= 11058.44 m
since
é 140000 ù
f ( 12.64915 ) = 2000 ln ê ú - 9.8( 12.64915 )
ë140000 - 2100( 12.64915 )û
= 296.8317
Gauss–Legendre Method (Gaussian Quadrature)
Problem 1 (Cont…)
é 140000 ù
f ( 25.35085 ) = 2000 ln ê ú - 9.8( 25.35085 )
ë140000 - 2100( 25.35085 )û
= 708.4811
b) The true error,Et , is
Et = True Value - Approximate Value
= 11061.34 - 11058.44
= 2.9000 m
c) The absolute relative true error, Ît , is (Exact value = 11061.34m)
11061.34 - 11058.44
Ît = ´100%
11061.34
= 0.0262%
Gauss–Legendre Method (Gaussian Quadrature)
Problem 11.
b
For an integral ò f ( x )dx , derive the one-point Gaussian Quadrature
a
Rule.
Solution. The one-point Gaussian Quadrature Rule is
b
ò f ( x )dx » c1 f ( x1 )
a
The two unknowns x1, and c1 are found by assuming that the formula gives
exact results for integrating a general first order polynomial,
f ( x ) = a0 + a1 x.
b b

ò f ( x)dx = ò (a
a a
0 + a1 x )dx
b
é x ù 2
æ b2 - a 2 ö
= êa0 x + a1 ú = a0 (b - a ) + a1 çç ÷÷
ë 2 ûa è 2 ø
Gauss–Legendre Method (Gaussian Quadrature)
Problem 11 (Cont…)

It follows that b

ò f ( x)dx = c (a
a
1 0 + a1 x1 )
Equating Equations, the two previous two expressions yield

æ b2 - a 2 ö
a0 (b - a ) + a1 çç ÷÷ = c1 (a0 + a1 x1 ) = a0 (c1 ) + a1 (c1 x1 )
è 2 ø
Since the constants a0, and a1 are arbitrary
b - a = c1
b2 - a 2
= c1 x1
2
b+a
giving c1 = b - a and x1 =
2
Gauss–Legendre Method (Gaussian Quadrature)
Problem 11 (Cont…)

Hence One-Point Gaussian Quadrature Rule

b
æb+aö
ò f ( x )dx » c1 f (x1 ) = (b - a ) f ç ÷
a è 2 ø
Problems Set:
Example 1
Problems Set:
Example 1 (Cont…)
Problems Set:

Example 1
Problems Set:
Example 2.
Figure given below shows data traffic on the link from the United States to SWITCH, the
Swiss academic and research network, on February 10, 1998. D(t) is the data throughput,
measured in megabits per second Mb/s. Use Simpson’s Rule to estimate the total amount of
data transmitted on the link from midnight to noon on that day.

Solution Because we want the units to be consistent and D(t) is measured in megabits
per second, we convert the units for t from hours to seconds. If we let Astd be the
amount of data (in megabits) transmitted by time t, where t is measured in seconds,
Then
Problems Set:

Example 2 (Cont….)
the total amount of data transmitted by noon
Problems Set:

Example 2 (Cont….)
Problems Set:
Example 3.

Solution.

Trapezoidal rule
f (a ) + f (b ) f (- 1) + f (1)
T ( f ,2) = (b - a ) = [1 - (-1)]
2 2
Problems Set:
Example 3 (Cont….)

Simpson’s rule
Problems Set:
Example 4.

Solution.
Using three-point Gauss Legendre rule
b

ò f ( x)dx » c f ( x ) + c
a
1 1 2 f ( x2 ) + c3 f ( x3 )
Exercise:
1.

2.

Hint: Use Newton Cotes formulas


Exercise:
3.

4.

5.
Exercise:

6.

7.
Exercise:

7.
Exercise:

8.

Potrebbero piacerti anche