Sie sind auf Seite 1von 72

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 1

Numerical Integration
and
Richardson Extrapolation
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 2
Numerical Integration
Basics: What does an integral represent?
b
a
(x)dx AREA ] =
}
d b
c a
g(x, y)dxdy VOLUME =
} }
Basic definition of an integral:
b
n
k
n
k 1
a
(x) dx lim f (x ) x

=
] = A

}
a
b
==> sum of Height x Width
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 3


Numerical Integration
Objective:
Evaluate:

without doing it analytically. Why?
1. The integrand is too complicated to integrate analytically:


2. The integrand is not precisely defined by an equation,
i.e., we are given a set of data, [x
i
, (x
i
)], i = 0,...,n
b
a
I (x) dx = ]
}
( )
2
0.5x
0
2 cos 1 x
e dx
1 0.5x
+ +
+
}
All methods are applicable to integrands that are functions.
Some are applicable to tabulated values.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 4


Numerical Integration
1.9
2
2.1
2.2
2.3
2.4
2.5
2.6
0 0.5 1 1.5 2
2
0.5x
0
2 cos(1 x)
e dx
1 0.5x
+ +
+
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 5


Numerical Integration
Some Applications:

Crane operator interested in determining the total work

Estimating the cross-sectional area of a river

Computing the modulus of toughness of a material

Calculating the total acreage of a lot
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 6


Numerical Integration -- Key concepts
1. Integration is a summing process.
Thus, virtually all numerical
approximations can be
represented by
b
n
i i t
i 0
a
I (x) dx w f (x ) E
=
= ] = +

}
w
i
= weights
x
i
= sampling points
E
t
= truncation error
2. Closed & Open forms:
Closed forms include the end points a & b.
Open forms do not.
a
b
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 7
Newton-Cotes Integration
To evaluate :

1. Divide [x
o
,x
n
] into n segments (n > 1)
2. Within each segment, approximate (x) by an m
th
-order
polynomial,
p
m
(x) = a
0
+a
1
x + a
2
x
2
+ + a
m
x
m

The polynomial order need not be the same for all segments.
Then:
n
o
x
x
(x) dx ]
}
n 1 2 n
1 2 n
o 0 1 n 1
x x x x
m m m
x x x x
(x)dx p (x) dx p (x)dx p (x)dx

] = + + +
} } } }
the m
i
's may be the same or different.
Integrate each polynomial exactly.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 8


Newton-Cotes Integration
Order m of polynomial p
m
(x) determines Newton-Cotes formula:
m Polynomial Formula Error
1 linear Trapezoid O(h
2
)
2 quadratic Simpson's 1/3 O(h
4
)
3 cubic Simpson's 3/8 O(h
4
)
4 quartic Boole's Rule O(h
6
)
5 quintic Boole's Rule O(h
6
)

Gaussian Quadrature formulas O(h
2n
)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 9
Trapezoidal Rule to Evaluate:


For each segment let (x) ~ p
1
(x) = a
0
+ a
1
x

a. Determine a
0
+ a
1
x from NDD Polynomial
n
0
x
x
f (x)dx
}
i i 1
1 i-1 i 1
i i 1
f (x ) f (x )
p (x) = f(x ) + (x x )
x x


i
i 1
x
i i 1
1 i i 1
x
f (x ) f (x )
p (x)dx (x x )
2

+
=
}
b. Integrate:
AREA Trapezoid = Base * Avg-Height
x
i-1

x
i

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 10
Numerical Integration

c. Truncation error:





Integrates a linear function correctly: f "() = 0.

Easily derived by considering Taylor Series.

i
i 1
x
3
i i 1
i i 1 i i 1
x
f (x ) f (x ) 1
(x)dx (x x ) (x x ) f "( )
2 12



+
] =
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 11
Numerical Integration
x
0
x
n

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 12


Composite Trapezoidal Rule:
For multiple segments, sum the areas from all segments:
n
o
x
n
i i 1
i i 1 ti
i 1
x
f (x ) f (x )
(x) dx (x x ) E
2


=
+
(
] = +
(

}
n 0
i i 1
x x
(x x ) h
n


= =
( )
( ) ( ) ( )
n 1
0 i n
i 1
n 0
f x 2 f x f x
I x x
2n

=
| |
| + +
|
\ .
~

where E
ti
is the truncation error in the i
th
interval.
If data are evenly spaced:
( ) ( ) ( )
n 1
0 i n
i 1
1 1
h f x f x f x
2 2

=
(
( ~ + +
(

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 13


Composite Trapezoidal Error:
n
i
i 1
"( ) nf "( )
=
] ~

so the truncation error is:


2 3
n 0
t
(x x )h nh
E " "
12 12

= ] = ]
Note: If n is doubled, h h/2, and E
t
E
t
/4
NOTE: C&C notation for the composite error is different
h = (x
n
-x
0
)/n = (b-a)/n

3 3
t
2
nh (b a)
E " "
12
12n

= ] = ]
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 14
Numerical Integration
Improving the estimate of the integral
fit Lagrange polynomials to three points (a pair of segments)
integrate those polynomials to obtain a general formula
the resulting function must correctly integrate quadratics
x
0

x
n

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 15


For each pair of segments use Lagrange Interpolating Polynomial:
Simpson's 1/3 Rule: Evaluate
n
0
x
x
f (x)dx
}
i i 1 i 1 i 1
2 i 1 i
i 1 i i 1 i 1 i i 1 i i 1
i 1 i
i 1
i 1 i 1 i 1 i
(x x )(x x ) (x x )(x x )
p (x) f (x ) f (x )
(x x )(x x ) (x x )(x x )
(x x )(x x )
f (x )
(x x )(x x )
+ +

+ +

+
+ +

= +


+

If points are evenly spaced, integrating yields:
i 1
i 1
x
i 1 i i 1
2 i 1 i 1
x
f (x ) 4f (x ) f (x )
p (x)dx (x x )
6
+

+
+
+ +
=
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 16
Simpson's 1/3 Rule Alternate derivation
Choose weights: e
0
f(-1) + e
1
f(0) + e
2
f(1)

so that over [ -1, +1]:
Thus, e
0
= e
2
and

e
0
+ e
2
= 2/3 e
0
= e
2
= 1/3
and e
1
= 4/3
1
0 1 2
1
1dx 2 (1) (1) (1)
+

= = e + e + e
}
1
0 1 2
1
x dx 0 ( 1) (0) ( 1)
+

= = e + e + e +
}
1
2 2 2
0 1 2
1
2
x dx ( 1) (0) ( 1)
3
+

= = e + e + e +
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 17
Simpson's 1/3 Rule:
General Formula:
Can integrate a cubic polynomial exactly: f
(4)
= 0.
( ) ( ) ( )
i 1
i 1
x
i 1 i i 1
2 i 1 i 1
x
f x 4f x f x
p (x)dx (x x )
6
+

+
+
+ +
=
}
Simpson's 1/3 Rule Truncation Error
i 1 i 1
i 1 i 1
x x
(4) 4
2 2 0
x x
1
f (x) dx p (x) dx (x x ) f ( )h
180
+ +

=
} }
(4) 5
1
f ( )h
90

Note: Because (x
2
x
0
) = 2h, the error term becomes:
(as reported in C&C, p. 604, Table 21.2)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 18
Derivation of error in Simpson's 1/3 Rule
Let: x = -h, 0, +h
h h
2
0 0 0
h h
x
I f (x) dx f x f f dx
2

| |
' ''
= = + + +
|
|
\ .
} }
Both have only odd terms.
IS = Truncation Error
3 5
[4]
0 0
2h 2h
2hf 0 f 0 f
6 5!
''
= + + + + +
| |
h
S f ( h) 4f (0) f ( h)
3
= + + +
2 4
[4]
0 0
h 2h 2h
6f 0 f 0 f
3 2 4!
(
''
= + + + + +
(
(

3 5
[4]
0 0
2h 2h
2hf 0 f 0 f
6 3(4!)
''
= + + + + +
4
[4] 6 5 (4)
(2h)h 1
f 2h O(h ) h f ( )
180 90
= + =
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 19


Composite Simpson's 1/3 Rule
If we split a large interval into several subintervals each representing
a pair of segments, then the integral can be expressed as:
( )
n
0
x
n 1
i 1 i i 1
i 1 i 1 ti
i 1,3,5
x
f (x ) 4f (x ) f (x )
I f (x) dx x x E
6

+
+
=
+ +
(
= = +
(

}
Combining terms and assuming evenly spaced intervals with
x
i
x
i-1
= (x
n
x
0
)/n = h, we have:
n 1 n 2
0 i j n
i 1,3,5 j 2,4,6
h
I f (x ) 4 f (x ) 2 f (x ) f (x )
3

= =
(
(
~ + + +
(


ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 20


Composite Simpson's 1/3 Rule Error
It can be shown that:
Error is of order h
4

If n is doubled, h h/2, E
t
E
t
/16
(4) (4)
i
f ( ) nf ~

4
(4) 4
n 0
t
(x x )h
E f (h )
180

= = O
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 21
Simpson's 3/8 Rule
a. For each triple of segments:

f(x) ~ p
3
(x) = a
0
+ a
1
x + a
2
x
2
+ a
3
x
3


b. For evenly spaced points:
3
0
x
0 1 2 3
3 3 0
x
f (x ) 3f (x ) 3f (x ) f (x )
p (x)dx (x x )
8
+ + +
=
}
3 3
0 0
x x
4 (4)
3 3 0
x x
1
f (x)dx p (x)dx (x x )h f ( )
80
=
} }
4 (4)
t 3 0
1
E (x x )h f ( )
80
=
c. Error:
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 22


NOTES:
1. Truncation errors for composite Simpson's 1/3 Rule
and Simpson's 3/8 Rule are, respectively:
so that Simpson's 1/3 Rule is slightly more accurate and easier
to compute, but of the same order as Simpson's 3/8 rule.


2. Simpson's 3/8 Rule requires multiples of three segments.

Simpson's 1/3 Rule requires multiples of two segments.
4 (4) 4 (4)
n 0 n 0
(x x ) (x x )
h f vs. h f
180 80


ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 23


Example:
n Trap. Simp. 1/3 Simp. 3/8
1 1.05191
2 1.00499* 0.98935
3 1.00187* 0.99561
4 1.00099 0.99965*
6 1.00042 0.99994* 0.99985
8 1.00023 0.99998*
9 1.00019 0.99998*
12 1.00011 1.00000* 1.00000*
15 1.00008 1.00000*
16 1.00006 1.00000*
32 1.00001
64 1.00000
Asterisk (*) denotes the more accurate answer for each n.
2
1.5
x
0.2
I c e dx 1.00000

= =
}
(c = 1.517858)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 24
Newton-Cotes Integration Other Cases:
1. NC formulas can be derived for any number
of segments and spacings.
Just integrate Lagrange Polynomials to get the
weight on each value of the function:
f(x
i
), i = 0,n
The formula can be open or closed.
2. Can always use multiple-applications of Trapezoid Rule.
Can use Simpson's Rules when adjacent segments have equal h's.

3. Integrate interpolating spline
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 25


C&C Table 21.2: Closed N-C Formulae


C&C Table 21.4: Open N-C Formulae
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 26


RICHARDSON EXTRAPOLATION

General and important idea!
Given two numerical estimates obtained with different
h's, compute a higher order estimate.

Applicable to a variety of step-dependent
approximations, including:
Integration
Differentiation
ODE's
PDE's
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 27


Richardson Extrapolation: Given two estimates obtained with
different h's, compute a higher order estimate:
Scheme: Starting with a step size h
1
, the exact value is:
A = A(h
1
) + O(h
1
n
)
Suppose we reduce the step size to h
2
, then:
A = A(h
2
) + O(h
2
n
)
Multiplying the second equation by r = (h
1
/h
2
)
n
and subtracting the
first equation yields [where the bracketed error terms tend to cancel]:
(r-1) A = r A(h
2
) A(h
1
) + [r O(h
2
n
) O(h
1
n
)]
( ) ( )
n
1
m 2
1
2
2
1
1
n
h
h
O(h )
h
1
h
A h h A
| |

|
\ .
= +
| |

|
\ .
A m > n+1
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 28


Richardson Extrapolation Example Numerical Differentiation:
( ) ( )
n n
1 1
1
2
2
2
h h
D 1
h
D h
h
h D
( (
| | | |
( (
=
| |
( (
\ . \ .

Apply to O(h
2
) 1
st
centered FDD:
0 0
f (x h) f (x h)
f (x) D(h)
2h
+
'
~ =
Substituting h
2
= h and h
1
=2h, Richardson Extrapolation yields:
f '(x) = 1/3 [ 4 D(h) D(2h) ] + O (h
4
)
1
4
2 2 1
1
(f f )
4h
1
4 O(
1
(f f ) h
2
)
h 3

(
= +
(

4
2 1 1 2
( f 8f 8f f )
O(h )
12h

+ +
= +
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 29


Richardson Extrapolation Example Numerical Integration:
Suppose we use the Trapezoid Rule to integrate.
If we use step size 2h:
I = T(2h) + O (4h
2
)
To improve the result, estimate using a reduced step size h:
I = T(h) + O (h
2
)
Combining the above two equations to eliminate error of order
h
2
yields:
2
4
2
T(2h 2 T(h)
I O(h )
2 1
)
= +

( ) ( ) ( )
( )
n
m
1
1
n
2
2 1
r
h
I O(h ) r 2
T
h
r
h
1
T h
= + = =

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 30




Richardson Extrapolation Example Numerical Integration:
x: 0 h 2h
f : f
0
f
1
f
2

Using Trapezoid rule with two step sizes, then applying Rich Ext:
I = T(h) + O (h
2
) I = T(2h) + O (4h
2
)
2
4
2
T(2h 2 T(h)
I O(h )
2 1
)
= +

1
T(h) = h
2
i i
f f
+
+
( )
( ) ( ) ( ) { } ( )
2 0
2 0 0 1 2
2 1 1 0
2 1 1 0
(
1
I 4
3
h h
4
3 3
2
( ) ( )
(h)
2
h)
2 2
2
f
f f f f
f f f f
f
f f f f f
+ (
(



= =
`

)
= =
+ + +
(
(

+ +

+ + + +
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 31


Richardson Extrapolation Example Numerical Integration:
NOTES:

1. Greater weight is placed on the more accurate estimate
2. Weighting coefficients sum to unity, i.e., (4-1)/3 = 1
3. Result is actually Simpson's 1/3 rule:
| |
i 1 i i 1
h
I f (x ) 4f (x ) f (x )
3
+
= + +
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 32


Romberg Integration: Systematic application of Richardson
Extrapolation with successive halving of the h: h
i+1
= h
i
/2
Benefit:
Get a high order Newton-Cotes formula easily.
Can watch convergence.
General formula:
j,k 1 j 1,k 1
k 1
j,k
k 1
4
I
I
4 1
I
+

=
j 1,k 1
j
j
1,
,
1
1
k
k
k
1
I
I
1
I
4
+

= +
where: j = level of subdivision
k = level of integration O(h
2k
)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 33


Romberg Integration
j 1,k 1 j,k 1
j,k j 1,k 1
k 1
I I
I I
4 1
+
+

= +
where: j = level of subdivision
k = level of integration O(h
2k
)
j
#
segs.
n
k = 1
O(h
2
)
Trap
k = 2
O(h
4
)
Simp 1/3
k = 3
O(h
6
)
Boole
k = 4
O(h
8
)
k = 5
O(h
10
)
1 1 I
1,1
I
1,2
I
1,3

2 2 I
2,1
I
2,2

3 4 I
3,1

4 8
5 16

k 1
1
4 1


= 1/3 1/15 1/63 1/255
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 34


Example 1: Romberg Integration




Trap Trap Simpson Boole
n O(h
2
) O(h
4
) O(h
6
) O(h
8
)
1 1.0519096 0.9893489 1.0003403 0.9999970
2 1.0049891 0.9996533 1.0000024 1.0000000
4 1.0009873 0.9999806 1.0000000 1.0000000
8 1.0002322 0.9999988 1.0000000 1.0000000
16 1.0000572 0.9999999 1.0000000
32 1.0000142 1.0000000
64 1.0000036
2
1.5
x
0.2
I c e dx 1.0000000

= =
}
(c = 1.517858)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 35


Example 2: Romberg Integration
1
a
0
I (a+1)x dx @ a = 6 =
}


Trap

Trapezoid

Simps. 1/3

Boole







n

O(h
2
)

O(h
4
)

O(h
6
)

O(h
8
)

O(h
10
)



1

3.500000

1.239583

1.002604

1.000000

1.000000



2

1.804688

1.017415

1.000041 1.000000





4

1.214233

1.001127

1.000001







8

1.054403

1.000071







16

1.013654







ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 36
Example 2: Romberg Integration
1
a
0
I (a+1)x dx @ a = 1.5 =
}


Trap

Trapezoid

Simp 1/3

Boole







n

O(h
2
)

O(h
4
)

O(h
6
)

O(h
8
)

O(h
10
)



1

1.250000

1.005922

1.000757

1.000124

1.000022



2

1.066942

1.001080

1.000134

1.000022





4

1.017545

1.000193

1.000024







8

1.004531

1.000034









16

1.001159









ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 37
GAUSS QUADRATURE
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 38


GAUSS QUADRATURE
Requires: f(x) must be known explicitly so we can pick x
i



Approach:

where: e
i
= weighting factors
x
i
= sampling points
R
n
= truncation error
1
n 1
i i n
i 0
1
(x) dx w (x ) R
+

=

] = ] +

}
Pick points & weights cleverly to integrate a polynomial of
order (2n - 1) exactly.
For n = 2 Gauss Quadrature will be accurate for cubics.
Trapezoidal Rule is accurate for linear functions.
For n = 3 Exact result for polynomials is of order up to and
including 5.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 39


GAUSS QUADRATURE: Example
With 3 points we want exact results for polynomials of order 5
over the interval [ 1, +1].
1
0 1 2
1
1dx 2 1 1 1
+

= = e + e + e
}
1
0 0 1 1 2 2
1
x dx 0 x x x
+

= = e + e + e
}
1
2 2 2 2
0 0 1 1 2 2
1
2
x dx x x x
3
+

= = e + e + e
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 40
GAUSS QUADRATURE: Example
With 3 points we want exact results for polynomials of order 5
over the interval [ 1, +1].
1
3 3 3 3
0 0 1 1 2 2
1
x dx 0 x x x
+

= = e + e + e
}
1
4 4 4 4
0 0 1 1 2 2
1
2
x dx x x x
5
+

= = e + e + e
}
1
5 5 5 5
0 0 1 1 2 2
1
x dx 0 x x x
+

= = e + e + e
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 41
GAUSS QUADRATURE: Example
With these six equations there are six unknowns.
3 unknown weights:
e
0
, e
1
, e
2

and 3 unknown sampling points.
x
0
, x
1
, x
2

Solving six equations for six unknowns:
e
0
= 0.555555556 x
0
= 0.774596669
e
1
= 0.888888889 x
1
= 0.000000000
e
2
= 0.555555556 x
2
= +0.774596669
which can be used in: I ~ e
0
f(x
0
) + e
1
f(x
1
) + e
2
f(x
2
)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 42
GAUSS QUADRATURE: Example
Points Weighting Factors Function Args. Trunc. Err.
2 c
0
= 1.0000000 x
0
= -0.577350269 f
(4)
()
c
1
= 1.0000000 x
1
= 0.577350269
3 c
0
= 0.5555556 x
0
= -0.774596669 f
(6)
()
c
1
= 0.8888889 x
1
= 0.0
c
2
= 0.5555556 x
2
= 0.774596669
4 c
0
= 0.3478548 x
0
= -0.861136312 f
(8)
()
c
1
= 0.6521452 x
1
= -0.339981044
c
2
= 0.6521452 x
2
= 0.339981044
c
3
= 0.3478548 x
2
= 0.861136312
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 43
GAUSS QUADRATURE
Gauss Quadrature Truncation Error:
In general, n sampling points will provide an exact solution for
a 2n1 order polynomial.
3 pts. exact solution for a 5
th
order polynomial.

With n = # sampling points:

Because (b-a) = h, The error with the composite Gauss rule is
O (h
2n
) globally with n = # of pts.
This shows a superiority of order over the Newton-Cotes formulas.

Higher order does not always mean higher accuracy.
( )
( )
4
2n 1
(2n)
n
3
[2(b- a)] n!
R f
(2n 1)[(2n)!]
+
=
+
GAUSS QUADRATURE: Example
-1
1
0
Trapezoid Rule
-0.58
0.58
0
Gauss Quadrature
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 44
GAUSS QUADRATURE
Generalizing to an arbitrary interval:
For integration over the interval [a,b] instead of [1,+1]
Given:
1
n 1
i i n
i 0
1
(x) dx w (x ) R
+

=

] = ] +

}
Assume that x is linearly related to another variable, y, so that:
y(x) = a
0
+ a
1
x
Let y = a when x = 1 (lower bound)
and y = b when x = +1 (upper bound)
Then: a = a
0
+ a
1
(1) and b = a
0
+ a
1
(+1)
Solving simultaneously yields:
a
0
= (b+a)/2 and a
1
= (ba)/2
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 45
GAUSS QUADRATURE
1 1
y(x) (b a) (b a)x
2 2
= + +
1
dy (b a)dx
2
=
( ) ( )
b 1
a 1
b a b a x
b a
(y) dy dx
2 2
+

| | +

] =
|
\ .
} }
f
n 1
i i
i 0
b a
(y[x ] )
2

| |
~ e ]
|
\ .

x
i
are the tabulated Gauss points, Table 22.1 in C&C
y(x) = a
0
+ a
1
x
a
0
= (b+a)/2 and a
1
= (ba)/2
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 46
GAUSS QUADRATURE: example
Evaluate using 3-pt Gauss Quadrature:


1. Change of variables:
}
2
1.5
y
0.2
e dy
(1.5 0.2) (1.5 0.2) x
y
2
+ +
=
1.5 0.2
dy dx 0.65 dx
2

= =
0.65x 0.85 = +
| |
2
1.5 1
2
0.65x 0.85
y
0.2 1
e dy 0.65 e dx
+
+

=
} }
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 47
GAUSS QUADRATURE: example
2. With
| |
2
1.5 1
2
0.65x 0.85
y
0.2 1
e dy 0.65 e dx
+
+

=
} }
| | | | | |
2 2 2
0 1 2
0.65x 0.85 0.65x 0.85 0.65x 0.85
0 1 2
I 0.65 e e e
+ + +
~ e +e +e
`
)
where: e
0
= 0.555555556 x
0
= 0.774596669
e
1
= 0.888888889 x
1
= 0.000000000
e
2
= 0.555555556 x
2
= + 0.774596669
I
true
= 0.65882
I
gauss
= 0.65860, e
t
= 0.03%
Note: with 3 points, I
trap
= 0.66211, e
t
= 0.50%
i.e., 2 segments: I
Simp.1/3
= 0.65181, e
t
= 1.06%
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 48
GAUSS QUADRATURE:
1
0
cdy
2 cos( y/ 2) + t
}
n p Romberg Gauss Quad
1 2 1.08253170 0.99955157
2 3 1.00066008 1.00000812
4 5 0.99999114 1.00000000
8 9 0.99999987 1.00000000

n p Romberg Gauss Quad
1 2 O(h
2
) O(h
4
)
2 3 O(h
4
) O(h
6
)
4 5 O(h
6
) O(h
10
)
8 9 O(h
8
) O(h
18
)
n = number of panels
p = number of points
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 49
Gaussian Quadrature Special Integrals
Gauss-Legendre
1
1
A(x)dx
+

}
2
x
e f (x)dx
+

}
Gauss-Hermite
Gauss-Laguerre log-weighted
Gauss-Chebyshev
x
0
e f (x)dx
+

}
1
0
ln(x)f (x)dx
+
}
1
2
1
f (x)
dx
1 x


}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 50
Advantages & Disadvantages of Gaussian Quadrature

A1) With n points, we obtain a formula that integrates high order
polynomials accurately: 1, x, x
2
, . . . , x
2n-1


Excellent for well behaved functions!

A2) Special formulas are available and can be derived for
special weighting functions,
and
infinite and semi-infinite intervals
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 51
Advantages & Disadvantages of Gaussian Quadrature
D1) Errors depend upon f
(2n)
():
> only dependable if high order derivatives are well
behaved.
D2) When composite Gaussian formulas are applied (Gauss
Quadrature applied to separate panels), endpoints
cannot be reused as they are with Trapezoid, Simpson
& Romberg.
D3) With an adaptive strategy that selectively subdivides
intervals where the truncation error may be large,
cannot reuse points.
Gauss also fails to estimate local error with the same
function values.
D4) It is inconvenient to remember special points and weights.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 52
Integration when the Integrand contains a singularity
If the derivative goes to infinity, it is possible that the error will
also go to infinity.
Need to control error near the singularity:
Can divide integration region to isolate singularity, then ----
1
0
f (x)
I dx problem at x = 0
x
=
}
1. Try to subtract out the singularity and numerically
integrate only the remainder.
2. Change of variables for the part of the interval near
the singularity.
3. Integrate by parts
4. Use special Gaussian Quadrature formulas
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 53
Integration of an Unbounded / Irregular Integrand
Approach #1a: Try to subtract out the singularity, numerically
integrate only the remainder and treat the singularity separately.
u
0
Consider x f (x) dx
}
where f(x) is continuously
differentiable at x = 0.
Subtract out the singularity
and integrate numerically:
u
0
[f(x) - f(0)] x dx
}
1.5
u
0
u
1.5
[f(x) - f(0)] x dx f (0) = +
}
1.5
u
0
u
1.5
f (0) x dx f (0) =
}
Integrate the singularity separately
Add the singularity back in:
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 54
Integration of an Unbounded / Irregular Integrand
Approach #1b: Include the first derivative at the singularity
u
0
[f (x) - f (0) - xf '(0)] x dx
}
Subtract out the singularity
and integrate numerically:
Integrate the singularity separately
Add the singularity back in:
| |
1.5 2.5
u
0
u u
1.5 2.5
f (0) xf (0) x dx f (0) f (0)
' '
+ = +
}
1.5 2.5
u
0
u u
1.5 2.5
I [f(x) - f(0)- xf (0)] x dx f (0) f (0)
' '
= + +
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 55
Integration of an Unbounded / Irregular Integrand
Approach #2: Try a change of variables for
a part of the interval near the singularity.
u
a
0
x f (x) dx
}
Let x = y
2
, dx = 2ydy ==> x
a
f(x)dx = 2y
2a+1
f(y
2
)dy
Now, with 0 < then 0 < 2a+1 so the singularity is eliminated.
This does not entirely solve the problem, but makes it less
severe.)
Integrate numerically near the problem (using Trapezoid or
Simpson rule). For x =1/2:
u u u
2 2 2
0 0 0
f (x) x dx f (y ) y(2y)dy 2 f (y ) y dy = =
} } }
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 56
Approach #4: Use Gauss Quadrature for the special singular
function.
Approach #3: Integrate by parts.
a a 1 a 1
x f(x)dx x f(x) x f (x)dx
+ +
'
=
} }
Integration of an Unbounded / Irregular Integrand (cont'd)
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 57
Integration with infinite upper and/or lower limits
Approach #1: Use Gauss Quadrature for the special interval.
Approach #2: Transform the variables on the outer portion of
the interval. (Beware of singularities at what
was infinity.)
For any function which approaches zero at least as fast as 1/x
2
as
x approaches infinity, perform change of variables:
x = 1/t; dx = -dt/t
2

b t 1/ a
2
x a t 1/ b
1 1
f (x)dx f f dt
t t
=
= =
| | | |
=
| |
\ . \ .
} }
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 58
which is valid for ab > 0.
(A)
For integration limits that pass through zero, implement the
integration in two (or three) steps:
b a b
a
f (x) dx f (x) dx f (x) dx


= +
} } }
where a > 0
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 59
The first integral may be evaluated using equation (A)
and the second may be evaluated using a closed form
Newton-Cotes formula or Gaussian Quadrature.
Integration with infinite upper and/or lower limits
With a change of variables: x = 1/t; dx = -dt/t
2
we have:
2 2
0 b
1 2t x 2
2
1/ a a
1 1
I e dt e dx
2 t


(
(
= +
(
t

} }
Consider the cumulative normal distribution, which is an
integral of the normal distribution (C&C Ex. 22.6)
2
b
x 2
1
I e dx
2

=
t
}
2
b
x 2
1
I e dx
2

=
t
}
2 2
a b
x 2 x 2
a
1 1
e dx e dx
2 2



= +
t t
} }
Decompose as follows:
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 60
Integration with infinite upper and/or lower limits
2 2
0 b
1 2t x 2
2
1/ a a
1 1
I e dt e dx
2 t


(
(
= +
(
t

} }
The first integral is singular at t = 0. Use the extended midpoint
rule with h = (x
n
- x
0
)/n:
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 61
Where the weight is always h and the function is evaluated at the
midpoint between each pair of the n equally-spaced samples.
n
0
0 0 n n
x
x
x x x x
h 3h 3h h
f (x)dx h f ( ) f ( ) f ( ) f ( )
2 2 2 2
+ +
(
= + + + +
(

}
Choosing: a = 2, n=4, and h = [0 - (-1/a)]/n = 1/an = 1/8
Integration with infinite upper and/or lower limits
2
0
1 2t
3h 3h 1 h 1 h
a 2 a 2 2 2 2
1/ a
1
e dt h f ( ) f ( ) f (0 ) f (0 )
t

(
= + + + + + +

}
2 2
0 b
1 2t x 2
2
1/ a a
1 1
I e dt e dx
2 t


(
(
= +
(
t

} }
( )
2
0
1 2t
7 5 3 1 1 1
2 16 16 16 16 16 2
1/ a
1 1
e dt f f ( ) f ( ) f ( )
8
t

(
= + = + + +
}
| |
1
0.3833 0.061184 1.89E 05 0 0.0556
8
= + + + =
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 62
Using the extended midpoint rule for the first integral:
Integration with infinite upper and/or lower limits
With a = 2, b = 1, and n = 6, then h = (1-(-2))/6 = 1/2
| |
2
b
(b a)
x 2
f (a) 4f (a h) 2f (a 2h) 2f (b 2h) 4f (b h) f (b)
3n
a
e dx

+ + + + + + +

=
}
2 2
0 b
1 2t x 2
2
1/ a a
1 1
I e dt e dx
2 t


(
(
= +
(
t

} }
Using the Simpson's 1/3 rule for the second integral:
( ) ( )
| |
4
1
6
0.1353 0.3247 0.8825 0.8825 2 0.6065 1 0.60625 2.0523 = + + + + + + =
( )
2
b
x 2
1 1
I e dx 0.0556 2.0523 0.8409
2 2

= ~ + =
t t
}
Therefore,
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 63
Multiple Integrals
Use Newton-Cotes or Gaussian quadrature
formulas in each dimension.
b d
a c
I f (x, y) dxdy =
}}
( )
( )
b d b
n
j j
j 1
a c a
I x, y dy dx (x) x, y dx
=
(
(
= ] ~ e
(


} } }
f
( )
m n
i ij i j
i 1 j 1
f x , y u
= =
~ e

( )
m n
i ij i j
i 1 j 1
f x , y u
= =
~ e

If d = d(x) or c = c(x), then values of e
ij
will depend upon x
i
.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 64
Another Idea:
Monte Carlo methods for multivariate integration
Randomly select points from within the range of
integration
Average function values used.
Sampling error is where n random points are
generated.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 65
/ n o
Truncation
Error
Analysis
Roundoff
Errors
Analysis
Linear
Systems of
Equations
Root-Finding
and
Optimization
Interpolation:
Polynomial
and Spline
Numerical
Integration
Numerical
Differentiation
Solution
Initial Value
ODEs
Solution
of PDEs
Boundary
Value
ODEs
Multivariate problems yield
linear systems of equations
Require solution of
linear systems of equations.
Least-Squares
Approximation Nonlinear
problems
Statistics &
Probability
Key relationships
among topics in
Numerical Analysis
Jery R. Stedinger
Cornell University, March 1998
Approximation
of functions
Computer skills
to efficiently
implement
algorithms
Many formulas based upon
polynomial interpolants
Optimization requires finding
roots of f(x
i
) = 0.
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 66
3 ft
Mast
support
cables
Mast
z = 30 ft
z = 0 ft
wind
Wind forces exerted per foot of mast as a function
of distance above the deck of the boat
Compute the effective force on the mast of a racing sailboat
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 67
z = 30 ft
z = 0 ft
Compute the tensile force T in the left mast support cable.
Assumptions:
1. The right support cable is completely slack
2. The mast joins the deck in a manner that transmits horizontal
and vertical forces but no moments
3. The mast remains vertical
3 ft
F = 1480.6 lb
d = 13.05 ft
u = tan
-1(
3/30)
Procedure:
1. Convert the distributed force, f, to an
equivalent total force, F.
2. Calculate its effective above the deck.

The total force exerted on the mast can
be expressed as:
30
2z / 30
0
z
F 200 e dz
5 z

| |
=
|
+
\ .
}
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 68
Compute the tensile force T in the left mast support cable.
Procedure:
1. Convert the distributed force, f, to an
equivalent total force, F.
2. Calculate its effect above the deck.
30
2z / 30
0
z
F 200 e dz
5 z

| |
=
|
+
\ .
}
Use a 3-point Gauss Quadrature formula to perform the integral:
1. Change of variables:
(0 30) (30 0) x
z 15 15x
2
+ +
= = +
dz 15dx =
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 69
Compute the tensile force T in the left mast support cable.
30 1
2z / 30 2(15 15x) / 30
0 1
z 15 15x
F 200 e dz 200 e *15dx
5 z 5 15 15x
+

+
| | | |
= =
| |
+ + +
\ . \ .
} }
where: e
0
= 0.555555556 x
0
= 0.774596669
e
1
= 0.888888889 x
1
= 0.000000000
e
2
= 0.555555556 x
2
= +0.774596669
1
(1 x)
1
15 15x
3000 e dx
20 15x
+

+
| |
=
|
+
\ .
}
0 1
(1 x ) (1 x )
0 1
0 1
0 1
15 15x 15 15x
F 3000 e e
20 15x 20 15x
+ +

| | | |
+ +
= e +e

| |
+ +
\ . \ .

2
(1 x )
2
2
2
15 15x
e
20 15x
+
(
| |
+
+e
(
|
+
\ .

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 70
Compute the tensile force T in the left mast support cable.
30
2z / 30
0
z
F 200 e dz
5 z

| |
=
|
+
\ .
}
F = 3000 [ 0.178891 + 0.245253 + 0.0793 = 1510.3 lb


With a 5-point Gauss Quadrature formula:

F = 3000 [ 0.0.047378 + 0.175173 + 0.156962 + 0.084465 + 0.029977 = 1481.9 lb
0 1
(1 x ) (1 x )
0 1
0 1
0 1
15 15x 15 15x
F 3000 e e
20 15x 20 15x
+ +

| | | |
+ +
= e +e

| |
+ +
\ . \ .

2
(1 x )
2
2
2
15 15x
e
20 15x
+
(
| |
+
+e
(
|
+
\ .

ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 71
Compute the tensile force T in the left mast support cable.
z = 30 ft
z = 0 ft
3 ft
F = 1480.6 lb
d = 13.05 ft
u = tan
-1(
3/30)
Trapezoid rule (60 segments): 1479.7
Simpson's 1/3 rule (30 segments): 1480.5
5-point Gauss quadrature: 1481.9
Exact: 1480.6
ENGRD 241 / CEE 241: Engineering Computation Numerical Integration 72

Das könnte Ihnen auch gefallen