Professional Documents
Culture Documents
Chapter 12-b
Integral Calculus - Extra
Isaac Newton
Thomas Simpson
BONUS
Introduction to Numerical
Integration
Ch 12 - Integral Calculus
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
11
13
15
f ( x )dx
f ( xi )
i=0
= c0 f ( x0 ) + c1 f ( x1 ) + LL + cn f ( xn )
f(x)
x0
x1
xn-1
xn
4
Ch 12 - Integral Calculus
f(x)dx
f ( xi )
i =1
Ch 12 - Integral Calculus
Newton-Cotes Formula
The weights are derived from the Lagrange polynomials L(x).
They depend only on the xi's; not on the function .
Li ( x ) =
( x x 0 )...( x x i 1 )( x x i +1 )...( x x n )
( x i x 0 )...( x i x i 1 )( x i x i +1 )...( x i x n )
Trapezoid Rule
Straight-line approximation
The trapezoid rule approximates the region under the graph
of the function f(x) as a trapezoid and calculating its area.
f ( x ) dx
f ( xi ) = c0 f ( x0 ) + c1 f ( x1 )
i=0
h
[ f ( x 0 ) + f ( x 1 )]
2
f(x)
Approximate
integral by the
trapezoids area.
L(x)
x0
x1
Ch 12 - Integral Calculus
f ( x) f ( x0 ) L0 ( x) + f ( x1 ) L1 ( x) + ... + f ( xn ) Ln ( x)
For the case, n=2, with the interval (x1-x0):
L( x) =
let
x x1
x x0
f ( x0 ) +
f ( x1 )
x 0 x1
x1 x 0
a = x 0 , b = x1, =
x = a
x = b
xa
dx
, d =
; h=ba
ba
h
= 0
L ( ) = (1 ) f ( a ) + ( ) f ( b )
=1
9
f ( x ) dx
L ( x ) dx = h L ( ) d
0
= f ( a ) h (1 ) d + f (b ) h d
0
= f ( a ) h (
) + f (b ) h
0
2 1
=
0
h
[ f ( a ) + f (b ) ]
2
10
Ch 12 - Integral Calculus
xe 2 x dx
4
xe
2x
1
x
dx = e 2 x e 2 x
4
2
0
1
1
= e 2 x ( 2 x 1 ) = 5216 . 926477
4
0
Graph
11
xe 2 x dx
40
[ f ( 0 ) + f ( 4 )] = 2( 0 + 4 e 8 ) = 23847 .66
2
5216 .926 23847 .66
= 357 .12 %
=
5216 .926
xe 2 x dx
12
Ch 12 - Integral Calculus
f ( x )dx
f ( xi ) = c0 f ( x0 ) + c1 f ( x1 ) + c2 f ( x2 )
i =0
h
[ f ( x 0 ) + 4 f ( x 1 ) + f ( x 2 )]
3
f(x)
x0
L(x)
x1
x2 13 x
L( x ) =
+
( x x 0 )( x x 1 )
f ( x2 )
( x 2 x 0 )( x 2 x 1 )
a+b
2
x
x
ba
dx
1
h=
, =
, d =
2
h
h
x
=
x
x
=
x
1 = 0
x = x = 1
2
let
x0 = a , x2 = b, x1 =
L( ) =
( 1 )
2
f ( x0 ) + ( 1 2 ) f ( x 1 ) +
( + 1 )
2
f ( x2 )
14
Ch 12 - Integral Calculus
h
2
f(x)dx h L ( )d = f(x 0 )
1
( 1 )d
+ f(x 1 )h ( 1 2 )d + f(x 2 )
0
h
2
( + 1 )d
1
h 3
2
3
) + f(x 1 )h (
)
= f(x 0 ) (
2
3
2
3
1
1
1
h 3
2
)
+ f(x 2 ) (
+
2
3
2
1
f(x)dx =
h
[ f(x
3
) + 4f(x
) + f(x
)]
15
Simpsons 3/8-Rule
Approximate by a cubic polynomial
3h
[ f ( x 0 ) + 3 f ( x 1 ) + 3 f ( x 2 ) + f ( x 3 )]
8
L(x)
x0
f(x)
x1
x2
x3 16 x
Ch 12 - Integral Calculus
Simpsons 3/8-Rule
Lagrange interpolation
L( x ) =
( x x 1 )( x x 2 )( x x 3 )
f ( x0 )
( x 0 x 1 )( x 0 x 2 )( x 0 x 3 )
( x x 0 )( x x 2 )( x x 3 )
f ( x1 )
( x 1 x 0 )( x 1 x 2 )( x 1 x 3 )
( x x 0 )( x x 1 )( x x 3 )
f ( x2 )
( x 2 x 0 )( x 2 x 1 )( x 2 x 3 )
( x x 0 )( x x 1 )( x x 2 )
f ( x3 )
( x 3 x 0 )( x 3 x 1 )( x 3 x 2 )
f(x)dx
L(x)dx ;
h=
b-a
3
3h
[ f ( x 0 ) + 3 f ( x 1 ) + 3 f ( x 2 ) + f ( x 3 )]
8
17
xe 2 x dx
4
0
xe 2 xdx
h
3
[f
(0) + 4 f (2 ) + f (4) ]
2
0 + 4 ( 2 e 4 ) + 4 e 8 = 8 2 4 0 .4 1 1
3
5 2 1 6 .9 2 6 8 2 4 0 .4 1 1
=
= 5 7 .9 6 %
5 2 1 6 .9 2 6
=
18
Ch 12 - Integral Calculus
xe 2 x dx
xe 2 x dx
3h
4
8
f (0) + 3 f ( ) + 3 f ( ) + f (4)
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
=
Midpoint Rule
Newton-Cotes Open Formula
f ( x )dx ( b a ) f ( x m )
= (b a )f(
where [a,b].
a+b
( b a )3
)+
f ( )
2
24
f(x)
The midpoint
rule amounts to
compute the
area of the
rectangle
xm
Note: This rule does not make any use of the end points.
x
20
Ch 12 - Integral Calculus
f ( x )dx
3
ba
[ f ( x 1 ) + f ( x 2 )] + ( b a ) f ( )
2
108
f(x)
x0
x1
x2
x3 21 x
ba
[2 f ( x 1 ) f ( x 2 ) + 2 f ( x 3 )]
3
7 ( b a )5
+
f ( )
23040
f ( x )dx
f(x)
x0
x1
x2
x3
x422 x
Ch 12 - Integral Calculus
23
Three segments
11
13
15
Four segments
11
13
15
13
15
Many segments
24
0
3
11
13
15
11
Ch 12 - Integral Calculus
f(x)dx =
x1
x0
f(x)dx +
x2
x1
f(x)dx + L L +
xn
xn 1
f(x)dx
h
[ f(x 0 ) + f(x 1 )] + h [ f(x 1 ) + f(x 2 )] + L + h [ f(x n 1 ) + f(x n )]
2
2
2
h
= [ f(x 0 ) + 2 f(x 1 ) + L + 2f(x i ) + L + 2 f ( x n 1 ) + f ( x n )]
2
=
f(x)
h=
ba
n
x0
x1
x2
x3
x425 x
I = xe 2 x dx
0
h
[ f ( 0 ) + f ( 4 )] = 23847.66
= 357.12%
2
h
n = 2 , h = 2 I = [ f ( 0 ) + 2 f ( 2 ) + f ( 4 )] = 12142.23 = 132.75%
2
h
n = 4,h = 1 I = [ f ( 0 ) + 2 f ( 1 ) + 2 f ( 2 )
2
+ 2 f ( 3 ) + f ( 4 )] = 7288.79
= 39.71%
h
n = 8 , h = 0.5 I = [ f ( 0 ) + 2 f ( 0.5 ) + 2 f ( 1 )
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%
h
n = 16 , h = 0.25 I = [ f ( 0 ) + 2 f ( 0.25 ) + 2 f ( 0.5 ) + L
2
+ 2 f ( 3.5 ) + 2 f ( 3.75 ) + f ( 4 )]
= 5355.95
= 2.66%
n = 1,h = 4 I =
26
Ch 12 - Integral Calculus
f ( x) dx +
f ( x) dx +
3.5
f ( x)dx +
f ( x) dx
3. 5
h1
[ f (0) + f (2)] + h2 [ f (2) + f (3)]
2
2
h
h
+ 3 [ f (3) + f (3.5)] + 4 [ f (3.5) + f ( 4)]
2
2
2
1
0.5 6
= 0 + 2e 4 + 2e 4 + 3e 6 +
3e + 3.5e 7
2
2
2
0.5
+
3.5e 7 + 4e8 = 5971.58
= 14.45%
2
=
] [
27
h=
ba
n
f(x)
...
x0 h x1 h x2 h x3 h
x4
xn-2 xn-1
xn28 x
Ch 12 - Integral Calculus
Using n = 4, h = 1
h
[ f ( 0 ) + 4 f ( 1 ) + 2 f ( 2 ) + 4 f ( 3 ) + f ( 4 )]
3
1
= 0 + 4 ( e 2 ) + 2( 2 e 4 ) + 4 ( 3 e 6 ) + 4 e 8
3
= 5670.975 = 8.70%
I=
29
I = xe 2 x dx
0
f ( x)dx + f ( x)dx
h1
[ f (0) + 4 f (1.5) + f (3)]
3
h
+ 2 [ f (3) + 4 f (3.5) + f (4)]
3
1.5
0.5 6
=
0 + 4(1.5e 3 ) + 3e 6 +
3e + 4(3.5e 7 ) + 4e 8
3
3
= 5413.23 = 3.76%
]
30
Ch 12 - Integral Calculus
Gaussian Quadratures
Newton-Cotes Formulae
- Nodes: Use evenly-spaced functional values
- Weights: Derived from an approximation required to be equal for
a polynomial of order lower or equal to the degree of the
polynomials used to approximate the function. Given nodes, best!
- Problem: Can explode for large n (Runges phenomenon)
Q: Can we use more efficient weights and nodes? Yes!
Gaussian Quadratures
- Gaussian quadrature sets the nodes and the weights in such a way
that the approximation is exact when f(.) is a low order polynomial.
Best choice for both, nodes and weights!
31
Gaussian Quadratures
In fact, Gaussian quadrature is more general than simple integration,
it computes an approximation to the weighted integral:
b
f(x)c(x)dx
ci f ( xi )
i =1
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 for nodes and weights
- With n nodes, delivers exact answer if f is (2n-1)th-order polynomial,
if f is close to a (2n-1)th-order.
32
Ch 12 - Integral Calculus
Gaussian Quadratures
The Gauss-Legendre quadrature rule is in general stated as:
1
f(x)dx
f ( xi )
i =1
the ci's are called the weights, the xi's are called the quadrature nodes.
The approximation error term, , is called the truncation error of
integration.
The goal is to get an exact answer if f is a (2n-1)th-order
polynomial. (With n=5, we get an exact answer f is a 9th-order
polynomial).
For Gauss-Legendre quadrature, the nodes are chosen to be zeros
of certain Legendre polynomials. They are not trivial to compute. 33
f(x)dx =
1dx = 2 =
1
1
i =1
x 2 dx = 2 / 3 =
i =1
xdx = 0 = c
c1
c
i
2
i
i =1
x j dx =
c
i
j
i
i =1
34
Ch 12 - Integral Calculus
= x
=1
1
1
1dx = 2 = c 1 + c 2
= x2
= x
3
xdx = 0 = c 1 x 1 + c 2 x 2
x 2 dx =
2
= c 1 x 12 + c 2 x 22
3
x 3 dx = 0 = c 1 x 13 + c 2 x 23
c 1 = 1
c = 1
2
1
x1 =
3
x2 = 3
35
x = 1 t = b
t1
1
f (t )dt = f (
1
t2
ba
b+a ba
ba n
x+
)(
)dx
ci f ( xi )
2
2
2
2 i =1
36
Ch 12 - Integral Calculus
f ( x )dx c i f ( x i ) = c 1 f ( x 1 ) + c 2 f ( x 2 ) + L + c n f ( x n )
i =1
n = 2:
f(x)dx
= c1f(x 1 ) + c 2 f(x 2 )
x1
x2
-1
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 (c371,
c2, x1, x2) such that it yields exact integral for f(x) = x0, x1, x2, x3.
Case n = 2
=x
= x2
1dx = 2 = c + c
xdx = 0 = c x + c x
2
x dx = = c x + c x
3
=1
= x3
I=
1
1
1
1
1
1
1 1
2 2
2
1 1
2
2 2
x 3 dx = 0 = c1 x13 + c2 x23
f ( x )dx = f (
1
3
c1 = 1
c 2 = 1
1
x1 =
3
1
x2 =
3
)+ f (
1
3
38
Ch 12 - Integral Calculus
Case n = 3 :
-1
f ( x )dx = c1 f ( x1 ) + c 2 f ( x2 ) + c3 f ( x3 )
x1
x2
x3
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).
39
f = 1 xdx = 2 = c1 + c2 + c3
1
1
f = x xdx = 0 = c1 x1 + c2 x2 + c3 x3
1
1
f = x 2 x 2 dx =
1
2
= c1 x12 + c2 x22 + c3 x32
3
1
1
f = x 4 x 4 dx =
1
2
= c1 x14 + c2 x24 + c3 x34
5
c1 = 5 / 9
c = 8 / 9
2
c3 = 5 / 9
x1 = 3 / 5
x2 = 0
x3 = 3 / 5
40
Ch 12 - Integral Calculus
I=
5
3 8
5
3
f ( ) + f (0) + f ( )
9
5 9
9
5
f ( x)dx =
41
I =
te 2 t dt = 5216 .926477
Coordinate transformation
t=
I =
ba
b+a
x+
= 2 x + 2 ; dt = 2dx
2
2
te 2 t dt =
( 4 x + 4 ) e 4 x + 4 dx =
f ( x ) dx
1
1
4 4 3
4 4+ 3
I = f ( x) dx = f ( ) + f ( ) = (4
)e
+ (4 +
)e
1
3
3
3
3
= 9.167657324 + 3468.376279 = 3477.543936 ( = 33.34%)
1
42
Ch 12 - Integral Calculus
5
8
5
f ( 0.6 ) + f (0) + f ( 0.6 )
1
9
9
9
5
8
5
4 0. 6
4
= (4 4 0.6 )e
+ ( 4 ) e + ( 4 + 4 0 . 6 ) e 4 + 0. 6
9
9
9
5
8
5
= (2.221191545) + (218.3926001) + (8589.142689)
9
9
9
= 4967.106689
( = 4.79%)
I=
f ( x)dx =
43
I=
1.64
x2
2
dx = .44949742
Coordinate transformation
t=
I=
ba
b+a
x+
= .82 x + .82 = .82(1 + x); dt = .82dx
2
2
1
2
1.64
t2
2
dt =
.82
2
1
1 [.82 (1+ x )]2
e 2
dx
1
.82
2
f ( x)dx
44
Ch 12 - Integral Calculus
2
2
3
3
2
I=
.82
f ( x) dx =
)]2
.82
2
f ( x ) dx =
.82 5
8
5
f ( 0 .6 ) + f ( 0 ) + f ( 0 .6 )
9
9
2 9
1
1
1
2
2
2
.82 5 2 [.82 (1 0.6 )]
8 2 [.82 (1 0 )]
5 2 [.82 (1+ 0.6 )]
e
=
+ e
+ e
9
9
2 9
= .32713267 * (0.5461465 9 + 0.63509351 + 0.19271450 )
= 0.44946544 ( = 0 .007 %)
45
Multidimensional Integrals
So far, we concentrated on one-dimensional integrals. To
compute integrals in multiple dimensions, one approach is to phrase
the multiple integral as repeated one-dimensional integrals.
But, eventually, we run into the so-called curse of dimensionality. Four
or more dimensions are complicated and, often, imprecise.
There are two methods that work well:
1.Monte Carlo: Based on repeated function evaluations, not
repeated integrations using one-dimensional methods.
Popular algorithm: Markov chain Monte Carlo (MCMC), which
include the Metropolis-Hastings algorithm and Gibbs sampling.
2. Sparse grids: Based on a one dimensional quadrature rule, but
uses a recursive combination of univariate results.
46
Ch 12 - Integral Calculus