Numerical Integration
Numerical Integration
1
Computational Science vs. Calculus
2
1. Differentiation
f(x)
f xi x
y
f xi
x x
Mathematical definition of
y f xi x f xi derivative - rate of change of a
x x dependent variable with respect to
an independent variable
3
2. Integration
• The inverse process of differentiation
• Mathematically, it is the total value or summation
of f(x)dx over a range of x. In fact the integration
symbol is actually a stylized capital S intended to
signify the connection between integration and
summation.
4
f(x)
x
b
I f x dx
a
5
Mathematical Background
d d x
dx
sin x ?
dx
e ? udv ?
u du ?
n
d d x
cos x ? a ?
a dx ?
dx dx bx
d d n
tan x ? x ? dx
dx dx
x ?
d
ln x ?
dx ?
ax
dx e
if u and v are functions of x
d n d
u ? (uv ) ?
dx dx
6
Urban area River cross-section Windblow on rocket
7
Example: numerical integration
Numerical Solution
8
Numerical Integration
Idea is to do integral in small parts, like the way we presented
integration: a summation.
Numerical methods just try to make it faster and more
accurate.
12
10
0
3 5 7 9 11 13 15 9
Basic Numerical Integration
Idea: Weighted sum of function values to approximate integral
n
f ( x )dx c i f ( x i )
b
a
i 0
f(x) c 0 f ( x 0 ) c 1 f ( x 1 ) c n f ( x n )
x0 x1 xn-1 xn x
10
Physics Example: Velocity & Acceleration
11
Overview
• Newton-Cotes Integration Formulas
– Trapezoidal rule
– Simpson’s Rules
– Unequal Segments
– Open Integration
• Integration of Equations
– Romberg Integration
– Gauss Quadrature
– Improper Integrals
12
Quadrature & integration
• Quadrature has become a synonym for numerical integration
– Primarily in one dimension, higher dimensional evaluation is
sometimes dubbed cubature
• All quadrature methods rely upon the interpolation of the
integral function f using a class of functions
– e.g. polynomials
– Utilizing the known closed form integral of the interpolated function
allows simple calculation of the weights
• Different functions will require different quadrature
algorithms
– Singular functions may require specialized Gaussian quadrature, or
changes of variables
– Oscillating functions require simpler methods, e.g. trapezoidal rule
13
Basic Numerical Integration
• We want to find integration of functions of various forms of the
equation known as the Newton-Cotes integration formulas.
• Newton-Cotes formula
Assume the value of f(x) defined on [a,b] is known at equally
spaced points xi (i=0,1,...,n), where x0 =a, and xn =b. Then,
b n
f(x)dx c f ( x )
a i 1
i i
16
Newton-Cotes Integration
b b
I f x dx f n x dx
a a
17
Newton-Cotes Integration Formulas
b b
• Based on the strategy of replacing a
I f ( x)dx f n ( x)dx
complicated function or tabulated data
a a
with an approximating function that is
easy to integrate: f n ( x) a0 a1 x an x n
18
a first order polynomial a second order polynomial
5 5
4 4
3 3
f(x)
f(x)
2 2
1 1
0 0
0 5 10 0 5 10
x x
19
a first order polynomial a second order polynomial
5 5
4 4
3 3
f(x)
f(x)
2 2
1 1
0 0
0 5 10 0 5 10
x x
3
f(x)
2
0
0 1 2 3 4 5 6 7 8 9 10
x
21
5
3
f(x)
2
0
0 1 2 3 4 5 6 7 8 9 10
x
22
Newton-Cotes Formulas
• Closed form - data is at the beginning and end
of the limits of integration
• Open form - integration limits extend beyond
the range of data.
5 5
4 4
3 3
f(x)
2 f(x) 2
1 1
0 0
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
x x
23
Trapezoidal Rule
• First of the Newton-Cotes closed integration
formulas
• Corresponds to the case where the
polynomial is a first order
b b
I f x dx f 1 x dx
a a
f n x a0 a1 x
24
Trapezoidal Rule
b b
I f x dx f 1 x dx
a a
f n x a0 a1 x
25
Trapezoidal Rule
b b
I f x dx f 1 x dx
a a
b
f b f a
f a x a dx
a
ba
26
Trapezoidal Rule
f a f b
I b a
2
Recall the formula for computing the area of a
trapezoid:
height
27
base
Trapezoidal Rule
f a f b
I b a
2
The concept is the same but the trapezoid is
on its side.
base
height
height
height width
base
28
Error of the Trapezoidal Rule
1
Et f ' ' b a
3
12
where a b
This indicates that if the function being integrated is linear, the trapezoidal
rule will be exact.
Otherwise, for section with second and higher order derivatives (that is with
curvature) error can occur.
29
Example Single Application of the Trapezoidal Rule
f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5
f (a ) f (b)
Trapezoida l Rule : I (b a )
2
0.2 0.232
0.8 0.1728
2
which represents an error of :
31
Multiple Application of the Trapezoidal Rule
32
Multiple Application of the Trapezoidal Rule
x1 x2 xn
f x0 f x1 f x1 f x2 f xn 1 f xn
Ih h h
2 2 2
33
Multiple Application of the Trapezoidal Rule
f x0 f x1 f x1 f x2 f xn 1 f xn
I h h h
2 2 2
n 1
f x0 2 f xi f xn
I b a i 1
2n
}
2n
}
width
}
average height
Note that the interior points are given twice the weight
of the two end points
b a 3
Ea 2
f ''
12 n
35
Example
Evaluate the following integral using the trapezoidal rule and h
= 0.1
1.6 30
I e
x2
dx 25
1 20
f(x)
15
ba
h 10
n 5
0
0 0.3 0.6 0.9 1 .2 1 .5 1 .8
x
n 1
f x0 2 f xi f xn
I b a i 1
2n
36
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.
37
Simpson’s 1/3 Rule
I f x dx f 2 x dx
a a
f n x a0 a1 x a2 x 2
38
Simpson’s 1/3 Rule
• Designate a and b as x0 and x2, and estimate f2(x) as a second
order Lagrange polynomial.
• 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:
b b
I f x dx f x dx
a a
2
x x1 x x2
x2
f x0 .......dx
x 0 0
x x1 x0 x2
39
Simpson’s 1/3 Rule
• After integration and algebraic manipulation, we get
the following equations
h
I f x0 4 f x1 f x2
3
f x0 4 f x1 f x2
b a
6
}
}
width average height
40
Error
12
where a b
2880
41
Composite Simpson’s 1/3 rule
• 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:
xn x2 x4 xn
I x0
fn x dx x0
fn x dx x2
fn x dx x n2
fn x dx
h h h
I
3
f 0
x 4 f 1 2 f x2 4 f x3 f x4
x f x
3
3
f xn2 4 f xn1 f xn
n1 n2
h
I f x0 4 f xi 2 f xi f xn
3
i1
i, odd
j2
j, even
42
Multiple Application of Simpson’s 1/3 Rule
x1 x2 xn
3n
Ea
b a
5
f 4
180n 4
43
n 1 n2
f x0 4 f x 2 f x f x
i j n
3n
The odd points represent the middle term for each
application. Hence carry the weight 4.
The even points are common to adjacent
applications and are counted twice.
i=1 (odd) i=2 (even)
weight of 4 weight of 2
f(x)
x 44
Simpson’s 3/8 Rule
• Corresponds to the case where the function is a
third order polynomial
b b
I f x dx f 3 x dx
a a
f n x a0 a1 x a2 x a3 x
2 3
45
Composite Simpson’s 3/8 Rule
• We assume that within any three consecutive subintervals of
width h, the interpolating polynomial φ(x) approximating f(x)
is of degree 3.
3h
I ( y0 yn ) 3( y1 y2 y4 y5 yn 1 ) 2( y3 y6 yn 3 )
8
46
Simpson’s 1/3
and 3/8 rules
applied in
tandem to
handle multiple
applications with
odd numbers of
intervals.
47
48
Integration of Unequal Segments
2n
f x0 f x1 f x1 f x2 f xn 1 f xn
I h h h
2 2 2
49
Integration of Unequal Segments
• We should also consider alternately using higher
order equations if we can find data in
consecutively even segments
trapezoidal
rule
50
Integration of Unequal Segments
• We should also consider alternately using higher
order equations if we can find data in consecutively
even segments
1/3
trapezoidal rule
rule
51
Integration of Unequal Segments
• We should also consider alternately using higher
order equations if we can find data in consecutively
even segments
1/3
trapezoidal rule
rule 3/8
rule
52
Integration of Unequal Segments
• We should also consider alternately using higher
order equations if we can find data in consecutively
even segments
trapezoidal
1/3 rule
trapezoidal rule
rule 3/8
rule
53
Integration with Unequal Segments
Using Trapezoidal Rule
f ( x0 ) f ( x1 ) f ( x1 ) f ( x2 ) f ( xn 1 ) f ( xn )
I h1 h2 hn
2 2 2
Example
1.309 0.2 1.305 1.309 0.363 3.181 0.232 2.363
I 0.12 0.10 0.06 0.10
2 2 2 2
0.0905 0.1307 0.12975 1.594
which represents a relative error x f(x) x f(x)
of e = 2.8% 0.0 0.2 0.44 2.842
0.40 2.456
54
Example
Integrate the following using the trapezoidal rule, Simpson’s
1/3 Rule, a multiple application of the trapezoidal rule with
n=2 and Simpson’s 3/8 Rule. Compare results with the
analytical solution.
1 4000
1 2000
4 1 0000
dx
2x
xe f(x) 8000
6000
4000
0
2000
0
0 1 2 3 4
x
55
Solution
• Exact solution
4
0
xe 2 x dx
4
4 x 2x 1 2x
dx e e
2x
xe
0
2 4 0
1
1 2x
e ( 2 x 1 ) 5216.926477
4 0
56
• Trapezoidal Rule: Approximation Error
ε = -(b – a)3/(12) f’’’(η) (η is a number between a and b).
Let’s take η =2. Then
ε = -43/12*[2*exp(2*2)+2*exp(2*2)+4*(2)*exp(2*2)] =-
3494.282
• Trapezoidal Rule
4 0
f ( 0 ) f ( 4 ) 2( 0 4e 8 ) 23847.66
4
I xe dx
2x
0 2
5216.926 23847.66
357.12%
5216.926
57
Solution: Simpson’s Rules
4
• Evaluate the Integral
0
xe 2 x dx
• Simpson’s 1/3-Rule
h
f (0) 4 f (2) f (4)
4
I 0
xe 2 x dx
3
2
0 4(2e 4 ) 4e8
8240.411
3
5216.926 8240.411
57.96%
5216.926
• Simpson’s 3/8-Rule
4 3h 4 8
I xe 2 x dx f (0) 3 f ( ) 3 f ( ) f (4)
0 8 3 3
3(4/3)
0 3(19.18922) 3(552.33933) 11923.832 6819.209
8
5216.926 6819.209
30.71%
5216.926
58
• Simpson’s 1/3-Rule: Approximation Error
ε = -(b – a)5/(2880) f (4)(η) (η is a number between a and b).
Since f (4)(η) >0, the error is negative (overshooting).
Let’s take η=2.5. Then,
ε = -45/(2880) [ exp(2*2.5)*[16*(2.5)+32] =-3799.3769
59
Παραδείγματα & Ασκήσεις
60
Simpson Rule
• Approximating the function to be integrated by a
quadratic polynomial leads to the basic Simpon Rule:
61
Simpson Rule – Example
62
Simpson Rule – Example
63
Exercise
• Determine exact area A for following integral:
2
A 4 x3dx
0
4 x4 4 2
A x (2)4 (0) 4 16
4 0
64
Trapezoidal Rule
• Given the data in the following table use the
trapezoid rule to estimate the integral from x = 1.8 to
x = 3.4. The data in the table are for ex and the true
value is 23.9144.
x f(x) x f(x)
1,6 4,953 2,8 16,445
1,8 6,05 3,0 20,086
2,0 7,389 3,2 24,533
2,2 9,025 3,4 29,964
2,4 11,023 3,6 36,598
2,6 13,464 3,8 44,701
65
Example
6
Estimate 0 f ( x)dx given f ( x) is defined by
x 0 1 2 3 4 5 6
y -1 -0.5 0 1 3 1 0
6 6
5 5
4 4
3 3
2 2
1 1
0 0
3 5 7 9 11 13 15 3 5 7 9 11 13 15
7
Four segments 7
Many segments
6 6
5 5
4 4
3 3
2 2
1 1
0 0
67
3 5 7 9 11 13 15 3 5 7 9 11 13 15
Composite Trapezoid Rule
• Use the Trapezoid Rule in n intervals. Then, add them together.
b x1 x2 xn
a
f(x)dx
x0
f(x)dx
x1
f(x)dx
xn 1
f(x)dx
h
f(x 0 ) f(x 1 ) h f(x 1 ) f(x 2 ) h f(x n1 ) f(x n )
2 2 2
f(x 0 ) 2 f(x 1 ) 2f(x i ) 2 f ( x n 1 ) f ( x n )
h
2
f(x)
ba
h
n
x0 h x1 h x2 h x3 h x4 x
68
Composite Trapezoid Rule
4
• Evaluate the integral I xe 2 x dx
0
n 1, h 4 I
h
f ( 0 ) f ( 4 ) 23847.66 357.12%
2
n 2 , h 2 I f ( 0 ) 2 f ( 2 ) f ( 4 ) 12142.23 132.75%
h
2
n 4 ,h 1 I f ( 0 ) 2 f ( 1 ) 2 f ( 2 )
h
2
2 f ( 3 ) f ( 4 ) 7288.79 39.71%
n 8 , h 0.5 I f ( 0 ) 2 f ( 0.5 ) 2 f ( 1 )
h
2
2 f ( 1.5 ) 2 f ( 2 ) 2 f ( 2.5 ) 2 f ( 3 )
2 f ( 3.5 ) f ( 4 ) 5764.76 10.50%
n 16 , h 0.25 I f ( 0 ) 2 f ( 0.25 ) 2 f ( 0.5 )
h
2
2 f ( 3.5 ) 2 f ( 3.75 ) f ( 4 )
5355.95 2.66% 69
Composite Trapezoid Rule with Unequal Segments
4
• Evaluate the integral
0
I xe 2 x dx
Use the following hi‘s: {h1=2, h2=1, h3=0.5, h4=0.5}
2 3 3.5 4
I f ( x)dx f ( x)dx f ( x)dx f ( x)dx
0 2 3 3.5
ba
h
n
f(x)
…...
x0 h x1 h x2 h x3 h x4 xn-2 xn-1 xn x
71
Composite Simpson’s Rule
4
• Evaluate the integral I xe 2 x dx
0
• Using n = 2, h = 2
I f ( 0 ) 4 f ( 2 ) f ( 4 )
h
3
2
0 4( 2e 4 ) 4 e 8 8240.411 57.96%
3
• Using n = 4, h = 1
I f ( 0 ) 4 f ( 1 ) 2 f ( 2 ) 4 f ( 3 ) f ( 4 )
h
3
1
0 4 ( e 2 ) 2( 2 e 4 ) 4 ( 3e 6 ) 4 e 8
3
5670.975 8.70%
72
Composite Simpson’s Rule with Unequal Segments
4
• Evaluate the integral I xe 2 x dx
0
Using h1 = 1.5, h2 = 0.5
3 4
I f ( x)dx f ( x)dx
0 3
• For the special case where the interval is halved (h2=h1/2), this becomes:
4 1
I I(h2 ) I(h1 )
3 3
74
Richardson Extrapolation
• Example
– Use Richardson extrapolation to evaluate the integral of
f(x) = 0.2 + 25x – 200x2 + 675x3 – 900x4 + 400x5 from a = 0 to b = 0.8
– Single and composite application of the trapezoidal rule:
Segments h Integral t
1 0.8 0.1728 89.5%
2 0.4 1.0688 34.9%
4 0.2 1.4848 9.5%
– The estimates for one and two segments can be combined
4 1 Et = 1.640533-1.367467=0.273067
I (1.0688) (0.1728) 1.367467 ( = 16.6%)
3 3 t
• For the cases where there are two O(h4) estimates and the
interval is halved (hm=hl/2), an improved O(h6) estimate may
be formed using:
16 1
I I m Il
15 15
• For the cases where there are two O(h6) estimates and the
interval is halved (hm=hl/2), an improved O(h8) estimate may
be formedusing:
64 1
I I m Il
63 63
76
The Romberg Integration Algorithm
• Note that the weighting factors for the Richardson
extrapolation add up to 1 and that as accuracy increases, the
approximation using the smaller step size is given greater
weight.
In general, 4 k1 I j1,k1 I j,k1
I j,k
4 k1 1
where ij+1,k-1 and ij,k-1 are the more and less accurate integrals,
and i is the new approximation. k is the level
respectively, j,k
A0 4 A1 A0
B1
A1 3 16 B2 B1
4 A2 A1 C1
B2 15
A2 3
16 B3 B2
4 A3 A2 C2
A3 B3 15
3
79
The values for Romberg’s Method of integration can be arranged in a triangular
matrix.
0 1 2 3 4 5 The best
0 A0 possible
1 A1 B1 estimate in
2 A2 B2 C1 each row is the
right most
3 A3 B3 C2 D1
entry:
4 A4 B4 C3 D2 E1
A0,B1,C1,D1,E1,F
5 A5 B5 C4 D3 E2 F1
1
Since we will run out of letters after 26 rows we express this with R(i,j).
0 1 2 3 4 5 The best
0 R(0,0) possible
1 R(1,0) R(1,1)
estimate in
each row is the
2 R(2,0) R(2,1) R(2,2)
right most
3 R(3,0) R(3,1) R(3,2) R(3,3) entry:
4 R(4,0) R(4,1) R(4,2) R(4,3) R(4,4)
R(i,i)
5 R(5,0) R(5,1) R(5,2) R(5,3) R(5,4) R(5,5)
80
The R(i,j) can be 0 1 2 3 4 5
obtained in the
following way: 0 R(0,0)
1 R(1,0) R(1,1)
R(i,0) is always the
2 R(2,0) R(2,1) R(2,2)
trapezoid method
applied with a partition 3 R(3,0) R(3,1) R(3,2) R(3,3)
size of 2j i. 4 R(4,0) R(4,1) R(4,2) R(4,3) R(4,4)
4 Ri, j 1 Ri 1, j 1
Ri, j 5 R(5,0) R(5,1) R(5,2) R(5,3) R(5,4) R(5,5)
4 1
j
For the rest of them a triangular pattern exists as how you fill in the other entries.
4 R(1,0) R(0,0)
R(1,1)
4 1
4 R(2,0) R(1,0) 42 R(2,1) R(1,1)
R(2,1) R(2,2)
4 1 42 1
4 R(3,0) R(2,0) 42 R(3,1) R(2,1) 43 R(3,2) R(2,2)
R(3,1) R(3,2) R(3,3)
4 1 42 1 43 1
4 R(4,0) R(3,0) 42 R(4,1) R(3,1) 43 R(4,2) R(3,2)
R(4,1) R(4,2) R(4,3)
4 1 42 1 43 1
4 R(5,0) R(4,0) 4 2 R(5,1) R(4,1) 43 R(5,2) R(4,2)
R(5,1) R(5,2) R(5,3)
4 1 42 1 43 1 81
• The chart below shows the process by which lower
level integrations are combined to produce more
accurate estimates:
82
Example: i xi yi=f(xi)
0 0 0
Apply Romberg Extrapolation to the data to the right to
1 ½ 1
get the best possible estimate for: 2
0
f ( x) dx 2 1 4
4 1112 4 2 32 323
R(2,0) 1
2
0 2 1 2 4 2 9 16 11
2 0
4 R(2,1) 3 32
3
R(2,2) 2
3
4 1
323
84
Romberg Integration
4 k I j 1 ,k I j ,k
I j ,k ; k 1, 2, 3,
4 1
k
k 0 k 1 k 2 k 3 k 4
O(h 2 ) O(h 4 ) O(h 6 ) O(h8 ) O(h10 )
h I 0, 0 I 0,1 I 0, 2 I 0,3 I 0, 4
h/2 I1, 0 I1,1 I1, 2 I1,3
h/4 I 2, 0 I 2,1 I 2, 2
h/8 I 3, 0 I 3,1
h / 16 I 4, 0
4 I j 1, 0 I j , 0 16 I j 1,1 I j ,1 64 I j 1, 2 I j , 2 256 I j 1,3 I j ,3
3 15 63 255
85
Romberg Integration
4
I xe dx 5216.926477
2x
0
k 0 k 1 k 2 k 3 k 4
O(h 2 ) O(h 4 ) O(h 6 ) O(h8 ) O(h10 )
h4 23847.7 8240.41 5499.68 5224.84 5216.95
h2 12142.2 5670.98 5229.14 5217.01
h 1 7288.79 5256.75 5217.20
h 0.5 5764.76 5219.68
h 0.25 5355.95
2.66% 0.0527% 0.0053% 0.00168% 0.00050%
86
Romberg Integration: preliminaries
• The starting point for Romberg integration is the composite
trapezoid rule which we may write in the following form
h n 1
h2
f ( x) dx f (a) f (b) 2 f ( xi ) [ f ' (a) f ' (b)]
b
I
a 2 i 1 12
k=2 1
R2,1 [ R1,1 sin( )]
2 2 2
k=3 1 3
R3,1 [ R2,1 [sin( ) sin( )]] 1.8962
2 2 4 4
R1,1
Obtain from Construct Romberg Table
a single R2,1 R2,2
composite
trapezoidal R3,1 R3,2 R3,3 I=Rn,n + O(hn2n)
integration
R4,1 R4,2 R4,3 R4,4
I=Rn,1 + O(hn2) 90
Consider previous example
0 sin x dx 2
0.00000000
1.57079633 2.09439511
91
• The table below shows computation of the
following integral:
92
Gauss Quadrature
93
Gaussian Quadratures
• Newton-Cotes Formulae
– use evenly-spaced functional values
• Gaussian Quadratures
– Select functional values at non-uniformly distributed points
to achieve higher accuracy. The values are not
predetermined, but unknowns to be determined.
– Change of variables => the interval of integration is [-1,1].
– Gauss-Legendre formulae
– Rule is stated as
1 n
f(x)dx c
1 i 1
i f ( xi )
94
95
Gauss-Legendre Formulas
• The Gauss-Legendre formulas seem to optimize estimates to
integrals for functions over intervals from -1 to 1.
• Integrals over other intervals require a change in variables to
set the limits from -1 to 1.
• The integral estimates are of the form:
I c0 f x0 c1 f x1 cn1 f xn1
where the ci and xi are calculated to ensure that the method
exactly integrates up to (2n-1)th order polynomials over the
interval
from -1 to 1.
96
Gaussian Quadratures
• The Gauss-Legendre quadrature formula is stated as
1 n
f(x)dx c
1 i 1
i f ( xi )
the ci's are called the weights, the xi's are called the quadrature
nodes. The approximation error term, ε, is called the truncation
error for integration.
97
Change of Interval for Gaussian Quadrature
• Coordinate transformation from [a,b] to [-1,1]
This can be done by an affine transformation on t and a
change of variables.
ba ba
t x
2 2
ba
dt dx
2
x 1 t a
x 1 t b
a t1 t2 b
ba ba ba ba n
b 1
a
f (t )dt f (
1 2
x
2
)(
2
)dx
2 i 1
ci f ( xi )
98
Gaussian Quadrature on [-1, 1]
• Gauss Quadrature General formulation:
n
f ( x )dx c i f ( x i ) c 1 f ( x 1 ) c 2 f ( x 2 ) c n f ( x n )
1
1
i 1
1
n 2: 1
f(x)dx
c1f(x1 ) c 2 f(x 2 )
-1 x1 x2 1
• For n=2, we have four unknowns (c1, c2, x1, x2). These are found by
assuming that the formula gives exact results for integrating a general 3rd
order polynomial. It can also be done by choosing (c1, c2, x1, x2) such that it
yields “exact integral” for f(x) = x0, x1, x2, x3.
99
Gaussian Quadrature on [-1, 1]
1
Case n 2 1
f(x)dx c1f(x 1 ) c 2 f(x 2 )
f 1
1 1dx 2 c 1 c 2 c 1 1
1
c 1
1
2
f x xdx 0 c 1 x 1 c 2 x 2 1
1
12 x1
f x x dx c 1 x 12 c 2 x 22
2 2
3
1
3 1
f 1
x x 3 dx 0 c 1 x 13 c 2 x 23
3 x2 3
1
1 1 1
I f ( x )dx f ( ) f ( )
1
3 3 100
Gaussian Quadrature on [-1, 1]
1
Case n 3 : 1
f ( x)dx c1 f ( x1 ) c2 f ( x2 ) c3 f ( x3 )
-1 x1 x2 x3 1
• Now, choose (c1, c2, c3, x1, x2, x3) such that the method yields “exact
integral” for f(x) = x0, x1, x2, x3,x4, x5. (Again, (c1, c2, c3, x1, x2, x3) are
calculated by assuming the formula gives exact expressions for
integrating a fifth order polynomial).
101
Gaussian Quadrature on [-1, 1]
1
f 1 xdx 2 c1 c2 c3
1
1
f x xdx 0 c1 x1 c2 x2 c3 x3
1 c1 5 / 9
1 c 8 / 9
2
f x x dx c1 x12 c2 x22 c3 x32
2 2 2
1
3 c3 5 / 9
x1 3 / 5
1
f x 3 x 3dx 0 c1 x13 c2 x23 c3 x33
1
x2 0
x3 3 / 5
1
2
f x x dx c1 x14 c2 x24 c3 x34
4 4
1
5
1
f x 5 x 5 dx 0 c1 x15 c2 x25 c3 x35
1 102
Gaussian Quadrature on [-1, 1]
• Approximation formula for n=3
1 5 3 8 5 3
I f ( x )dx f ( ) f (0 ) f ( )
1 9 5 9 9 5
103
Example (1): Gaussian Quadrature
4
Evaluate I te 2 t dt 5216.926477
0
Coordinate transformation
ba ba
t x 2 x 2 ; dt 2dx
2 2
4 1 1
4 x4
I te dt
2t
( 4 x 4 )e dx f ( x )dx
0 1 1
2
Evaluate 1
I e 2 dx .44949742
0
Coordinate transformation
ba ba
t x .82 x .82 .82 (1 x); dt .82 dx
2 2
t2 1
1.64 1 [.82(1 x )]2 1
2 2 2
1 .82 .82
I e 2 dt e 2 dx f ( x)dx
0 1 1
106
Example (2): Gaussian Quadrature
Two-point formula (n=2)
1 1 2 1 1
1 .82 1 1 .82 2 [. 82(1 )] [.82(1 )]2
.82
I f ( x)dx f ( ) f ( ) e 3
e 2 3
2 1 2 3 3
2
0.32713267 * (0.9417114 7 + 0.43323413 ) .44978962 ( 0.065 %)
109
Improper Integrals
• An improper integral is basically an integral that has
infinity as its limits or has a discontinuity within its
limits.
• Examples of improper integrals:
1
-1 x 2
x
e dx dx
0
110
• The improper integral of f over the interval [a,)
is defined to be
b
112