You are on page 1of 20

MTH2212 – Computational Methods and

Statistics

Numerical Differentiation and Integration

Lecture 10:
Numerical Integration (II)
Objectives

 Simpson’s 3/8 Rule


 Integration with unequal segments
 Gauss Quadrature

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 2


Simpson’s 3/8 Rule

 3rd order polynomial is fit to 4 points and integrated to yield


3h ba
I  f ( x0 )  3 f ( x1 )  3 f ( x2 )  f ( x3 ) h
8 3
 Simpson’s 3/8 rule has an error of

(b  a)5 ( 4)
Et   f ()
6480

More accurate

 There is also a multiple segment version.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 3


Combination of Simpson’s 1/3 and 3/8 rules

 Can also use combinations of


Simpson’s 1/3 and 3/8 rules for
unevenly spaced data

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 4


Example 1

1. Use Simpson’s 3/8 rule to integrate:


f ( x)  0.2  25 x  200 x 2  675x 3  900 x 4  400 x 5

from a = 0 to b = 0.8

2. Use Simpson’s 1/3 and 3/8 rules to integrate the same


function for five segments.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 5


Example 1 – Solution

1. A single application of Simpson’s 3/8 rule requires 4


equally spaced points:

h = (0.8-0)/3 = 0.2667

f(0) = 0.2 f(0.2667) = 1.432724

f(0.5333) = 3.487177 f(0.8)=0.232

3(0.2667)
I  0.2  3(1.432724  3.487177)  0.232  1.51970
8

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 6


Example 1 – Solution

2. For five segments:

h = (0.8-0)/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)=3.181929 f(0.8) = 0.232

The integral for the first 2 segments (Simpson’s 1/3 rule):


(0.16)
I  0.2  4(1.296919)  1.743393  0.3803237
3
For the last 3 segments (Simpson’s 3/8 rule)
3(0.16)
I 1.743393  3(3.186015  3.181929)  0.232  1.264754
8
The total integral
I  0.3803237  1.264754  1.645077
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 7
Remarks – Trapezoidal & Simpson’s Rule

 Rather than applying trapezoidal rule with finer segments,


go to higher order polynomials
– Quadratic is used: Simpson’s 1/3
• Must be used with even number of segments
– Cubic is used: Simpson’s 3/8
• Odd number of segments
• Slightly more accurate than 1/3 but requires more points
 Simpson’s 1/3 is preferred since need fewer data points for
same order accuracy
 Therefore, for odd number of segments, use 1/3 rule for all
but the last 3 segments, then use 3/8 rule.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 8


Integration with unequal segments

 Experimental data is often


not equally spaced
 All the previous equations
were for equally spaced
data points
 If you have some equally
spaced points in the data
set, Fit with Simpson’s rules
 Fit the rest of the segments
with individual
Trapezoidal rules

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 9


Gauss Quadrature

 Gauss quadrature implements a


strategy of positioning two points
on a curve to define a straight line
that would balance the positive
and negative errors.

 The area evaluated under this


straight line provides a faster and
an improved estimate of the
integral compared to Trapezoid
and Simpson.

 Find position of these points using


Gauss-Legendre formulas

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 10


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 or a
straight line, such as y=1 and
y=x:

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 11


Method of Undetermined Coefficients

(ba ) / 2
c0  c1   1 dx
(b a ) / 2

ba b  a (ba ) / 2
 c0  c1   x dx
2 2 ( b  a ) / 2

c0  c1  b  a
ba ba Solve simultaneously
 c0  c1 0
2 2

ba
c0  c1 
2
ba ba Trapezoidal rule
I f (a)  f (b)
2 2
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 12
Two-Point Gauss-Legendre Formula

 The object of Gauss quadrature is to determine the equations of


the form
I ≈ c0 f(x0) + c1 f(x1)
 However, in contrast to trapezoidal rule that uses fixed end
points a and b, the function arguments x0 and x1 are not fixed end
points but unknowns.
 Thus, four unknowns to be evaluated require four conditions.
 First two conditions are obtained by assuming that the above
equation fits the integral of a constant and a linear function
exactly.
 The other two conditions are obtained by extending this
reasoning to a parabolic and a cubic functions.

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 13


Two-Point Gauss-Legendre Formula

1
c0 f ( x0 )  c1 f ( x1 )   1 dx  2
1
1
c0 f ( x0 )  c1 f ( x1 )   x dx  0
1
1
Solved simultaneously
2
c0 f ( x0 )  c1 f ( x1 )   x 2 dx 
1
3 Notice that the integration
1 limits are from -1 to 1. This
c0 f ( x0 )  c1 f ( x1 )   x 3 dx  0 was done for simplicity and
1 make the formulation as
1 1 general as possible.
c0  c1  1, x0   , x1 
3 3
Yields an integral
 1   1  estimate that is third
I  f  f 
 3  3  order accurate
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 14
Two-Point Gauss-Legendre Formula

 A simple change of variable is used to translate other limits


of integration into integration limits are from -1 to 1
x  a0 xd  a1
 If x=a and x=b correspond to xd=-1 and xd=1 respectively
ba
a   a0  a1 a0 
2
b  a0  a1 ==
ba
a1 
2
This yields to
(b  a ) xd  (b  a ) (b  a)
x dx  dxd
2 2

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 15


Example 2

Use two-point Gauss quadrature to integrate:


f ( x)  0.2  25 x  200 x 2  675x 3  900 x 4  400 x 5

from a = 0 to b = 0.8

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 16


Example 2 - Solution

 First, perform a variable change


x  0.4 xd  0.4 dx  0.4dxd
 Evaluate the integral
0.8
I  0 (0.2  25 x  200 x 2  675 x 3  900 x 4  400 x 5 )dx
1
 1 (0.2  25(0.4 xd  0.4)  200(0.4 xd  0.4) 2  675(0.4 xd  0.4)3
 900(0.4 xd  0.4) 4  400(0.4 xd  0.4)5 )0.4dx

 The right hand side is suitable for using Gauss quadrature


 1   1 
I  f  f   0.516741  1.305837  1.822578
 3  3
εt = 11.1%
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 17
Higher-Point Gauss Quadrature Formulas

 Higher-point formulas can be developed in the general


form
I ≈ c0 f(x0) + c1 f(x1)+…+ cn-1 f(xn-1)
 Requires function to be known, since unlikely to get data
points that match these locations in a data table
 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
Error for the Gauss-
Et  f ( 2 n  2)
( )
(2n  3) (2n  2)! Legendre formulas
3

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 18


Higher-Point Gauss Quadrature Formulas

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 19


Assignment # 4

 Computational Methods
 20.41, 24.44, 24.55
 Statistics
 4.45, 4.46, 4.53, 4.71, 4.74, 4.84 (new textbook)
OR
 4.43, 4.44, 4.49, 4.65, 4.71, 4.80 (old textbook)

Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 20

You might also like