Numerical Integration

advertisement
Contents
13 Numerical Integration
187
13.1 Midpoint Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
13.2 Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
13.3 Algorithm for Computing T2N from TN
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
13.4 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
13.5 Simpson’s Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
13.6 A Little Numerical Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
13.7 Algorithm for Computing SN and DN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
2
CONTENTS
Chapter 13
Numerical Integration
13.1
Midpoint Rule
Divide the interval [a, b] into N equal subintervals as shown in the diagram.
•
•
•
x1
a = x0
Each subinterval has length h =
b−a
N .
m0
•
x0
•
x2
xN −1
×
•
x1
b = xN
The midpoint of the subinterval [xi , xi+1 ] is mi =
mN −1
m1
×
•
•
x3
•
x2
•
xN −1
×
•
xN
Now we draw the graph of f
f
a
b
h
x
h
The signed area MN of the shaded rectangles is
MN = hf (m0 ) + hf (m1 ) + . . . + hf (mN −1 ) = h
N
−1
X
i=0
It is called the midpoint approximation to the definite integral
Z
a
b
f (x)dx.
f (mi ).
xi +xi+1
.
2
188
Numerical Integration
The error is given by the formula
b
Z
f (x)dx =
a
|
MN
+
{z
}
|
approximation
EN
{z
error
.
}
If B is a number such that |f 00 (z)| ≤ B for all z ∈ [a, b] then
|EN | ≤
Note:
(b − a)3 B
.
24N 2
The approximation and its accuracy depends on the number, N , of subintervals.
Example 1:
Approximate I =
Z
mation.
π
sin x dx by the midpoint rule with N = 4 and estimate the accuracy of this approxiπ
4
Solution:
Step size:
h=
π− π
4
4
Midpoints: m0 =
m1 =
m2 =
m3 =
π
4
π
4
π
4
π
4
=
+
+
+
+
3π
16 .
3π
11π
32 = 32 = 1.0799225
9π
17π
32 = 32 = 1.6689711
15π
23π
32 = 32 = 2.2580197
21π
29π
32 = 32 = 2.8470683.
Approximation:
M4
= h{sin(m0 ) + sin(m1 ) + sin(m2 ) + sin(m3 )}
M4
=
3π
16 (.88192127
=
3π
16 (2.9404011)
+ .99518473 + .77301046 + .29028468)
= 1.7320392
Error analysis:
f 0 (x) = cos x and f 00 (x) = − sin x
|f 00 (x)| = | sin x| ≤ 1
for all x ∈ R.
The bound on the error is given by
|E4 | ≤
so
|E4 | ≤
3π
16
3
There 1.7320392 − .0341 < I < 1.7320392 + .0341.
(b − a)3 B
24N 2
1
< .0340645.
24 · 16
13.1 Midpoint Rule
189
Observation:
Z π
π
∼
sin x dx = − cos(π) + cos
= 1.7071068 by the fundamental theorem. Therefore
π
4
4
|E4 | ∼
= .0249324 < .0341,
as predicted by our error analysis.
Example 2:
Approximate L =
2
Z
1
dx
by the midpoint rule within ±10−3 .
x
Solution:
In this problem we have first to decide how many subintervals to use; i.e. we have to decide what N to
choose. We use our formula for the error bound to compute N .
Since |EN | <
(b−a)3 B
24N 2
were need
(2−1)3 B
24N 2
< 10−3 to guarantee |EN | < 10−3 .
Now f (x) = x1 , f 0 (x) = − x12 , and f 00 (x) =
And |f 00 (z)| =
2
z3
2
x3 .
≤ 2 on [1, 2] allows us to pick B = 2. Therefore we need
N2
>
1×103
12
N
>
√
10
√ 10
12
2
24N 2
< 10−3 or
∼
= 9.129
Since we need N > 9.129 we pick N = 10. This gives h =
2−1
10
=
1
10 .
Midpoints:
1.05
M10 = h
M10 =
Note:
1
m0
+
1
m1
×
+ ... +
1
m9
1
10 (6.9283536)
Z
2
1
×
1.15
•
1.1
•
1
1.25
•
1.2
×
1.35
•
1.3
×
1.45
•
1.4
×
1.55
•
1.5
×
1.65
•
1.6
×
1.75
•
1.7
×
1.85
•
1.8
×
1.95
•
1.9
×
•
10
= .69283536.
dx
= ln 2 ∼
= .69314718.
x
ln 2 − M10 ∼
= .000312 < .001.
Problems
For the given function f , interval [a, b] and partition N compute MN , the midpoint approximation of
Z b
f (x)dx, and a bound on the error term.
a
1.
f (x) = x1 ,
[1.5, 3], and N = 6
190
Numerical Integration
2.
f (x) = sin x2 ,
3.
f (x) = e−x ,
4.
f (x) =
5.
√
[0, π], and N = 6
2
f (x) =
[0, .8],
1
1+x4 ,
√
[0, 1], and N = 4
6.
f (x) =
7.
f (x) =
sin 2x
cos2 2x ,
9.
[ π2 , π],
1 + cos2 x,
(
8.
sin x
x
if x 6= 0
,
if x = 0
1
[0, π6 ],
√
f (x) = arctan x,
√
x
and N = 6
[0, π2 ],
and
and N = 4
N =5
[9, 13], and N = 4
11.
[1, 4], and N = 4
p
f (x) = tan(x2 ), [0, π4 ], and N = 4
√
f (x) = 1 + x3 , [0, 2], and N = 2
12.
f (x) =
10.
f (x) = e
and N = 8
,
√ 1
,
1+x3
√
[0, 2], and N = 4
13.
f (x) =
x sin x,
14.
f (x) = x tan x,
15.
f (x) = ex ,
3
−x2
f (x) =
2e√
17.
f (x) =
e−x
x ,
18.
f (x) = e− sin x ,
19.
f (x) =
20.
f (x) =
21.
22.
2x
x+1 ,
√
,
and N = 10
[0.5, 3],
and N = 8
[0, π2 ],
[0, 1],
and N = 4
and N = 4
[0, 3],
1 + ex ,
and N = 4
[0, π4 ],
[0, 1],
16.
π
[0, π],
and N = 6
and N = 4
[0, 1], and N = 4
√
sin x, [0, π2 ], and N = 4
p
f (x) = 1 − 2 sin2 x, [0, π2 ], and N = 4
f (x) =
In the following problems find N so that the midpoint rule approximates the given
Z
with |EN | < given ε.
If N ≤ 10 use the midpoint rule to find the approximate value.
23.
Z
3
1.5
25.
Z
0
27.
Z
1
dx
,
x
ε = ±10
dx
,
1 + x4
ε = ±10−4
26.
ε = ±10−2
28.
4 √
e
x
−3
24.
29.
0
π
sin x2 dx,
ε = ±10−3
0
dx,
1
Z √ π2
√
Z
Z
π
p
1 + cos2 x dx,
π
2
Z
13
√
arctan x dx,
ε = ±10−3
ε = ±10−4
9
2
cos(x )dx,
ε = ±10
−2
30.
Z
0
π
2
p
1 + cos2 x dx, ε = ±10−2
13.2 Trapezoidal Rule
31.
1
Z
1
2
Z
√
0
35.
ε = ±10−2
1 + x3 dx
0
33.
p
2
Z
1
Z
32.
1
2
0
dx
,
1 − x2
ε = ±10−3
Z
34.
dx
,
1 + x2
ε = ±10−4
3
4−x dx,
ε = ±10−2
1
sin x
dx,
x
13.2
191
ε = ±10−2
Trapezoidal Rule
This is another way to approximate
Z
b
f (x)dx. Again divide [a, b] into N equal intervals of length h =
a
•
•
a = x0
•
x1
•
•
x2
xN −1
xN = b
The trapezoid approximation to the integral is given by
h
{f (a) + 2f (x1 ) + 2f (x2 ) + . . . + 2f (xN −1 ) + f (b)} .
2
TN =
We write
Z
b
f (x)dx =
a
TN
+
|
{z
} |
Trap. approximation
EN
{z
error
.
}
If B is chosen so that |f 00 (z)| ≤ B for all z ∈ [a, b] then
|EN | ≤
Note:
13.3
(b − a)3 B
.
12N 2
This is not the same as for the midpoint rule.
Algorithm for Computing T2N from TN
If we have computed TN we can get T2N as in the following example for
Z
3
f (x)dx:
0
N =2:
0
•
0
T2 =
N =4:
0
•
0
1
•
3/4
1
•
3/2
3
2
1
f (0) + f
2
2
•
3/2
2
•
3
(h = 3/2)
3
1
+ f (3) .
2
2
3
•
9/4
4
•
3
(h4 = 3/4)
b−a
N
.
192
Numerical Integration
T4
=
T4
=
T4
=
T4
=
0
•
0
N =8:
T8
=
T8
=
T8
=
T8
=
13.4
1
3
3
9
1
f (0) + f
+f
+f
+ f (3)
2
4
2
4
2
1
1
1
3
3
9
3
f (0) + f
+ f (3) + 3 f
+f
4
2
2
2
4
4
1
3
9
2T2 + 3 f
+f
.
(Look back at the formula for T2 )
4
4
4
3
9
1
T 2 + h4 f
+f
2
4
4
3
4
1
×
3/8
2
•
3/4
3
×
9/8
4
•
3/2
5
×
15/8
6
•
9/4
7
×
21/8
8
•
3
h8 =
3
8
1
3
3
9
3
15
9
21
1
f (0) + f
+f
+f
+ +f
+f
+f
+f
+ f (3)
2
8
4
8
2
8
4
8
2
1
1
3
3
9
1
3
f (0) + f
+f
+f
+ f (3) +
8
2
4
2
4
2
3
9
15
21
3 f
+f
+f
+f
8
8
8
8
1
3
9
15
21
4T4 + 3 f
+f
+f
+f
8
8
8
8
8
1
3
9
15
21
T 4 + h8 f
+f
+f
+f
2
8
8
8
8
3
8
Algorithm
I. Partition interval of integration into N intervals and compute the points x0 , x2 , . . . , xN of the partition.
II. Compute TN and record.
III. Compute midpoints, yi , of the partition to give a new partition with 2N intervals.
(of length h2N = (b − a)/2N ).
IV. Compute T2N = 21 TN +
b−a
2N
NP
−1
f (yi ), record and store.
i=0
V. Reset N to 2N and repeat steps III to V.
Example:
Z 3
1
For
sin
dx, compute T2 , T4 , and T8 .
x
1
13.4 Algorithm
193
Solution: (using a T.I. calculator)
•
5/4
p
1
3−1
2
Since h2 =
3−1
4
1
sin(1) + sin
2
=
÷ 2
+
3−1
8
p
2
36.
For
For
Z
37.
For
Z
4
÷ 2
Now
is in the display + ( sin
5
4
4
4
+ sin
+ sin
+ sin
) ÷ 4 = (1.0288421).
7
9
11
1
2 T4
=
3
ex dx compute T2 , T4 , T8 , and T16 .
1
38.
1
2
cos x dx compute T2 , T4 , T8 , and T16 .
0
39.
For
Z
For
Z
For
Z
For
Z
For
Z
For
Z
1
e−1/x dx compute T2 , T4 , T8 , and T16 .
0
40.
2
dx
compute T2 , T4 , T8 , and T16 .
x
1
41.
1
2
e−x dx compute T2 , T4 , and T8 .
0
42.
1
3
(x2 + 1) 2 dx compute T2 , T4 , and T8 .
0
43.
7
1
(1 + x) 3 dx compute T2 , T4 , and T8 .
0
44.
0
π
2
p
3
Now 12 T2 is in the display.
2
2
( sin
+ sin
) ÷ 2 = (1.035773).
3
5
1
sin
dx compute T16 .
x
1
•
11/4
1
1
1
+
sin
= (1.0637584).
2
2
3
Problems
3
×
5/2
= 14 ,
T8
Z
•
9/4
= 12 ,
T4
Since h8 =
•
7/4
= 1,
T2 =
Since h4 =
×
3/2
p
1 − 2 sin2 x dx compute T2 , T4 , and T8 .
194
Numerical Integration
45.
For
π
2
Z
√
sin x dx compute T2 , T4 , and T8 .
0
46.
For
1
Z
0
2x
dx compute T2 , T4 , and T8 .
x+1
For the integral
b
Z
f (x)dx find a suitable N and compute TN (if N ≤ 10) such that |EN | ≤ (given ε).
a
47.
Z
2
1
49.
Z
1
dx,
sin
x
ε ≤ .002
4x3 dx,
ε ≤ .06
48.
Z
1
50.
53.
1
p
1 + x3 dx,
3 √
e
ε ≤ .02
52.
Z
1
13.5
π
2
Z
Z
ε ≤ .007
p
1 + cos2 x dx, ε ≤ .02
13
√
arctan x dx,
ε ≤ .001
9
x
ε ≤ .05
dx,
54.
1
55.
dx
,
x
0
0
Z
2
1
0
51.
Z
Z √π/2
cos(x2 )dx,
ε ≤ .01
0
2
sin x
dx,
x
ε ≤ .01
56.
Z
3
e−x dx,
ε ≤ .01
1
Simpson’s Rule
b
There is another way to approximate
Z
equal subintervals, each of length h =
a
b−a
N
•
a = x0
f (x) dx. For this rule partition [a, b] into an even number N of
to get a partition
•
•
x1
•
x2
xN −1
•
b = xN
Then the Simpson’s approximation is given by
SN
=
b−a
[f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + · · · + 2f (xN −2 ) + 4f (xN −1 ) + f (xN )] .
3N
Simpson’s Rule can be remembered as
b−a
[(ends) + 4(odds) + 2(evens)] .
3N
Thus
Z
b
f (x)dx = SN + EN .
a
If B is chosen so that |f (4) (z)| ≤ B for all z ∈ [a, b] then
|EN | ≤
(b − a)5 B
.
180N 4
13.6 A Little Numerical Analysis
195
Problems
Use Simpson’s rule to estimate, with |EN | ≤ (given ε) the following integrals.
57.
Z
1.9
dx
,
x
1
59.
Z
2
1
61.
Z
ε = .001
58.
63.
sin x
dx,
x
ε = .001
65.
cos x dx,
ε = 1 × 10−6
60.
Z
Z
3 √
e
62.
Z
1
2
10
1
π
2
dx
,
x
ε = 5 × 10
−6
64.
Z
1
2
0
1
1+
1 + x2
x
√
0
0
67.
5−x dx,
ε = .001
dx,
ε = .001
1
1
2
e2
Z
3
1
0
Z
Z
12
dx,
ε = .05
66.
Z
1
cos x2 dx,
2
dx
, ε = 1 × 10−6
1 − x2
dx
,
1 + x2
ε = 1 × 10−7
dx
,
1+x
ε = 2 × 10−6
ε = .001
0
13.6
A Little Numerical Analysis
Sometimes we cannot use the error formula to estimate the error. In these circumstances we compute the
sequence
T2 , T4 , T8 , . . . , TN , T2N , . . .
of trapezoidal approximations, and stop when the difference DN = T2N − TN gets small. We do it this way
for two reasons:
1. There is a good algorithm to compute T2N using TN .
2. If we know TN and T2N we can get the Simpson’s approximation by the formula
SN =
13.7
4T2N − TN
T2N − TN
DN
= T2N +
= T2N +
.
3
3
3
Algorithm for Computing SN and DN
I. Partition the interval of integration [a, b] into N subintervals as described on page 191.
II. Calculate TN ; store and print.
III. Compute midpoints, yi , of your partition.
IV. Compute
b−a
2N {f (y0 )
+ f (y1 ) + · · · + f (yN −1 )} = A.
V. Compute T2N = 12 TN + A; store and print.
VI. Compute DN = T2N − TN and print.
VII. Compute SN = T2N +
DN
3
.
196
Numerical Integration
Problems
68.
For
π
4
Z
cos x dx, compute T16 , D8 , and S8 and compare T16 and S8 with the exact value of this integral.
0
In problems 69 to 82 do the following.
For N = 2, 4 and the given integral calculate TN , T2N , DN , and SN . (Include the partition, your method,
and a summary of the results in your solution.)
69.
Z
5
1
71.
Z
73.
Z
70.
sec x dx
72.
Z
74.
Z
π
4
cos x2 dx
77.
π
2
Z
9
4
0
81.
Z
2
dx
1 + x2
1 √
e
√
sin x dx
76.
Z
1
0
1
79.
1
x
dx
0
0
Z
ex dx
0
π
2
0
Z
1
0
0
75.
Z
dx
x
4
p
3+
x3
2x
dx
x+1
x dx
ln x
dx
78.
Z
9
Z
5
2
82.
Z
0
p
x3 − 1 dx
1
80.
dx
1 + x3
dx
ln x
π
4
x tan x dx
Download