CHAPTER 21
21.1 (a) Analytical solution:
(
1
)
[
0
.
5
]
44
0
.
5
2(4)0
0
.
5
2(0)3
.
500168
0 2 4 0 2=
+
=
+
−
−
=
−
− − − −∫
e
xdx
x
e
xe
e
(b) Trapezoidal rule (n = 1):
999329
.
1
2
999665
.
0
0
)
0
4
(
−
+
=
=
I
%
88
.
42
%
100
500168
.
3
999329
.
1
500168
.
3
−
×
=
=
tε
(c) Trapezoidal rule (n = 2):
%
35
.
15
963033
.
2
4
999665
.
0
)
981684
.
0
(
2
0
)
0
4
(
−
+
+
=
=
=
tI
ε
Trapezoidal rule (n = 4):
%
47
.
4
343703
.
3
8
999665
.
0
)
997521
.
0
981684
.
0
864665
.
0
(
2
0
)
0
4
(
−
+
+
+
+
=
=
=
tI
ε
(d) Simpson’s 1/3 rule:
%
17
.
6
284268
.
3
6
999665
.
0
)
981684
.
0
(
4
0
)
0
4
(
−
+
+
=
=
=
tI
ε
(e) Simpson’s rule (n = 4):
%
84
.
0
470592
.
3
12
999665
.
0
)
981684
.
0
(
2
)
997521
.
0
864665
.
0
(
4
0
)
0
4
(
−
+
+
+
+
=
=
=
tI
ε
(f) Simpson’s 3/8 rule:
%
19
.
3
388365
.
3
8
999665
.
0
)
995172
.
0
930517
.
0
(
3
0
)
0
4
(
−
+
+
+
=
=
=
tI
ε
(g) Simpson’s rules (n = 5):
%
41
.
0
485876
.
3
378769
.
2
107107
.
1
8
999665
.
0
)
998338
.
0
99177
.
0
(
3
959238
.
0
)
6
.
1
4
(
6
959238
.
0
)
798103
.
0
(
4
0
)
0
6
.
1
(
=
=
+
=
+
+
+
−
+
+
+
−
=
tI
ε
21.2 (a) Analytical solution:
[
6
3
sin
]
6
(
/2
)
3
sin(
/2
)
0
12
.
42478
)
3cos
(6
0/2 /2 0+
=
+
=
+
−
=
∫
πx
dx
x
x
ππ
π
(b) Trapezoidal rule (n = 1):
78097
.
11
2
6
9
)
0
570796
.
1
(
−
+
=
=
I
100
%
5
.
182
%
42478
.
12
78097
.
11
42478
.
12
−
×
=
=
tε
(c) Trapezoidal rule (n = 2):
%
254
.
1
26896
.
12
4
6
)
12132
.
8
(
2
9
)
0
570796
.
1
(
−
+
+
=
=
=
tI
ε
Trapezoidal rule (n = 4):
%
311
.
0
38613
.
12
8
6
)
14805
.
7
12132
.
8
771639
.
8
(
2
9
)
0
570796
.
1
(
−
+
+
+
+
=
=
=
tI
ε
(d) Simpson’s 1/3 rule:
%
055
.
0
43162
.
12
6
6
)
12132
.
8
(
4
9
)
0
570796
.
1
(
−
+
+
=
=
=
tI
ε
(e) Simpson’s rule (n = 4):
%
0032
.
0
42518
.
12
12
6
)
12132
.
8
(
2
)
14805
.
7
771639
.
8
(
4
9
)
0
570796
.
1
(
−
+
+
+
+
=
=
=
tI
ε
(f) Simpson’s 3/8 rule:
%
024
.
0
42779
.
12
8
6
)
5
.
7
598076
.
8
(
3
9
)
0
570796
.
1
(
−
+
+
+
=
=
=
tI
ε
(g) Simpson’s rules (n = 5):
%
002
.
0
42503
.
12
891665
.
6
533364
.
5
8
6
)
927051
.
6
763356
.
7
(
3
427051
.
8
)
628319
.
0
570796
.
1
(
6
)
0
628319
.
0
(
=
=
+
=
+
+
+
−
+
+
+
−
=
tI
ε
21.3 (a) Analytical solution:
1104
3
2
)
2
4
1
(
4 2 6 4 2 4 2 5 3=
+
−
−
=
+
−
−
− −∫
x
x
x
dx
x
x
x
x
(b) Trapezoidal rule (n = 1):
5280
2
1789
29
))
2
(
4
(
−
−
−
+
=
=
I
100
%
378
.
26
%
1104
5280
1104
=
×
−
=
tε
(c) Trapezoidal rule (n = 2):
%
59
.
138
2634
4
1789
)
2
(
2
29
))
2
(
4
(
−
−
−
+
−
+
=
=
=
tI
ε
Trapezoidal rule (n = 4):
%
398
.
37
875
.
1516
8
1789
)
3125
.
131
2
9375
.
1
(
2
29
))
2
(
4
(
−
−
−
+
−
+
+
=
=
=
tI
ε
(d) Simpson’s 1/3 rule (n = 2):
%
7
.
58
1752
6
1789
)
2
(
4
29
))
2
(
4
(
−
−
−
+
−
+
=
=
=
tI
ε
(e) Simpson’s 3/8 rule:
%
087
.
26
1392
8
1789
)
31
1
(
3
29
))
2
(
4
(
−
−
−
+
+
+
=
=
=
tI
ε
(f) Boole’s rule (n = 5):
%
0
1104
90
)
1789
(
7
)
3125
.
131
(
32
)
2
(
12
)
9375
.
1
(
32
)
29
(
7
))
2
(
4
(
−
−
−
+
+
−
+
+
=
=
=
tI
ε
21.4 Analytical solution:
33333
.
8
4
4
3
)
2
(
2 1 3 2 1 2=
−
+
=
+
∫
x
x
x
dx
/x
x
Trapezoidal rule (n = 1):
9
2
9
9
)
1
2
(
−
+
=
The results are summarized below:
n
Integral
ε
t1
9
8%
2
8.513889
2.167%
3
8.415185
0.982%
4
8.379725
0.557%
21.5 Analytical solution:
2056
)
3
4
(
16
1
)
3
4
(
5 3 4 5 3 3=
−
=
−
− −∫
x
dx
x
Simpson’s rule (n = 4):
%
0
2056
12
4913
)
1
(
2
)
729
343
(
4
3375
))
3
(
5
(
−
−
−
+
−
+
+
+
=
=
=
tI
ε
Simpson’s rules (n = 5):
%
0
2056
598
.
5218
6
.
3162
8
4913
)
016
.
1191
088
.
74
(
3
648
.
10
)
2
.
0
5
(
6
648
.
10
)
056
.
636
(
4
3375
))
3
(
2
.
0
(
=
=
+
−
=
+
+
+
−
−
+
−
−
+
−
−
−
=
tI
ε
Because Simpson’s rules are perfect for cubics, both versions yield the exact result for this
cubic polynomial.
21.6 Analytical solution:
[
(
22
2
)
]
3098
.
42768
3 0 2=
−
+
=
∫
x
e
xdx
x
x
e
xTrapezoidal rule (n = 4):
%
062
.
14
2684
.
112
8
7698
.
180
)
03166
.
48
0838
.
10
190813
.
1
(
2
0
)
0
3
(
−
+
+
+
+
=
=
=
tI
ε
Simpson’s rule (n = 4):
%
046
.
1
45683
.
99
12
7698
.
180
)
0838
.
10
(
2
)
03166
.
48
190813
.
1
(
4
0
)
0
3
(
−
+
+
+
+
=
=
=
tI
ε
21.7 Analytical solution:
2301
.
517
14
14
ln
2
1
14
5 . 1 5 . 0 2 1.5 0.5 2=
=
∫
xdx
x(a) Trapezoidal rule (n = 1):
1379
2
2744
14
)
5
.
0
5
.
1
(
−
+
=
=
I
100
%
166
.
612
%
2301
.
517
1379
2301
.
517
=
×
−
=
tε
(b) Simpson’s 1/3 rule (n = 2):
%
134
.
14
3333
.
590
6
2744
)
196
(
4
14
)
5
.
0
5
.
1
(
−
+
+
=
=
=
tI
ε
(c) Simpson’s 3/8 rule:
%
798
.
6
3916
.
552
8
2744
)
3879
.
472
323
.
81
(
3
14
)
5
.
0
5
.
1
(
−
+
+
+
=
=
=
tI
ε
(d) Boole’s rule:
%
5397
.
0
0215
.
20
5
90
)
2744
(
7
)
3648
.
733
(
32
)
196
(
12
)
3832
.
52
(
32
)
14
(
7
)
5
.
0
5
.
1
(
−
+
+
+
+
=
=
=
tI
ε
(e) Midpoint method:
%
106
.
62
196
196
)
5
.
0
5
.
1
(
−
=
=
=
tI
ε
(f) 3-segment-2-point open integration formula:
%
473
.
46
8554
.
276
2
3879
.
472
323
.
81
)
5
.
0
5
.
1
(
−
+
=
=
=
tI
ε
(g) 4-segment-3-point open integration formula:
%
355
.
11
4987
.
458
3
)
3648
.
733
(
2
196
)
3832
.
52
(
2
)
5
.
0
5
.
1
(
−
−
+
=
=
=
tI
ε
21.8 Analytical solution:
(
5
3
cos
)
[
5
3
sin
]
3015
.
42336
3 0+
=
+
=
∫
x
dx
x
x
(a) Trapezoidal rule (n = 1):
04503
.
15
2
030023
.
2
8
)
0
3
(
−
+
=
=
I
100
%
2
.
453
%
42336
.
15
04503
.
15
42336
.
15
=
×
−
=
tε
(b) Simpson’s 1/3 rule (n = 2):
%
104
.
0
43943
.
15
6
030023
.
2
)
212212
.
5
(
4
8
)
0
3
(
−
+
+
=
=
=
tI
ε
(c) Simpson’s 3/8 rule:
%
045
.
0
43028
.
15
8
030023
.
2
)
751559
.
3
620907
.
6
(
3
8
)
0
3
(
−
+
+
+
=
=
=
tI
ε
(d) Simpson’s rules (n = 5):
%
014
.
0
42126
.
15
62304
.
6
79822
.
8
8
030023
.
2
)
787819
.
2
318394
.
4
(
3
087073
.
6
)
2
.
1
3
(
6
087073
.
6
)
476007
.
7
(
4
8
)
0
2
.
1
(
=
=
+
=
+
+
+
−
+
+
+
−
=
tI
ε
(e) Boole’s rule:
%
0014
.
0
42314
.
15
90
)
030023
.
2
(
7
)
115479
.
3
(
32
)
212212
.
5
(
12
)
195067
.
7
(
32
)
8
(
7
)
0
3
(
=
=
+
+
+
+
−
=
tI
ε
(f) Midpoint method:
%
383
.
1
63663
.
15
212212
.
5
)
0
3
(
−
=
=
=
tI
ε
(g) 3-segment-2-point open integration formula:
%
877
.
0
5587
.
15
2
751559
.
3
620907
.
6
)
0
3
(
−
+
=
=
=
tI
ε
(h) 4-segment-3-point open integration formula:
%
094
.
0
40888
.
15
3
)
115479
.
3
(
2
212212
.
5
)
195067
.
7
(
2
)
0
3
(
−
−
+
=
=
=
tI
ε
21.9 Analytical solution:
t d d t d d
t
m
gc
c
m
dt
t
m
gc
c
gm
t
z
0 0tanh
ln
cosh
)
(
=
=
∫
9262
.
333
)
10
(
1
.
68
)
25
.
0
(
8
.
9
cosh
ln
25
.
0
1
.
68
)
10
(
10 0=
=
z
Thus, the result to 3 significant digits is 334. Here are results for various multiple-segment
trapezoidal rules:
n
I
1
246.9593
2
314.4026
3
325.4835
4
329.216
5
330.9225
6
331.8443
7
332.3984
8
332.7573
9
333.0031
10
333.1788
11
333.3087
12
333.4074
13
333.4842
14
333.5452
Thus, a 14-segment application gives the result to 4 significant digits.
21.10
(a) Trapezoidal rule (n = 5):
15
.
2
10
1
)
5
5
.
3
4
8
(
2
1
)
0
5
.
0
(
−
+
+
+
+
+
=
=
I
(b) Simpson’s rules (n = 5):
377083
.
2
14375
.
1
233333
.
1
8
1
)
5
5
.
3
(
3
4
)
2
.
0
5
.
0
(
6
4
)
8
(
4
1
)
0
2
.
0
(
−
+
+
+
−
+
+
+
=
+
=
=
I
21.11
(a) Trapezoidal rule (n = 6):
65
12
20
)
3
5
2
10
5
(
2
35
))
2
(
10
(
−
−
+
−
+
+
+
+
=
=
I
(b) Simpson’s rules (n = 6):
66667
.
56
18
20
)
5
10
(
2
)
3
2
5
(
4
35
))
2
(
10
(
−
−
+
+
+
+
−
+
+
=
=
I
21.12 (a) A graph suggests that the mean value is about 80.
y = -0.075x4+ 2x3- 14x2+ 45x - 46 0 50 100 150 200 250 300 0 2 4 6 8 10 12 80
(b) Analytical solution:
[
]
81
.
89333
8
1467
.
655
2
10
015
.
0
5
.
0
6667
.
4
5
.
22
46
2
10
075
.
0
2
14
45
46
10 2 5 4 3 2 10 2 4 3 2=
=
−
−
+
−
+
−
=
−
−
+
−
+
−
∫
x
x
x
x
x
dx
x
x
x
x
(c) Numerical solution:
2292
.
654
046
.
601
18315
.
53
8
254
)
1645
.
156
14368
.
81
(
3
81888
.
35
)
2
.
5
10
(
6
81888
.
35
)
27488
.
15
(
4
8
.
2
)
2
2
.
5
(
=
+
=
+
+
+
−
+
+
+
−
=
I
%
14
.
0
%
100
89333
.
81
81.77865
89333
.
81
81.77865
2
10
2292
.
654
Average
=
×
−
=
=
−
=
tε
21.13 (a) Analytical solution:
[
1
.
33333
]
0
.
54209
(
1
.
33333
)
0
.
79124
2
1.5 00.6 0.6 0 5 . 1=
−
−=
−
−
−
=
−∫
e
xdx
e
x(b) Trapezoidal rule
79284
.
0
2
8131
.
0
9808
.
0
)
475
.
0
6
.
0
(
2
9808
.
0
1831
.
1
)
35
.
0
475
.
0
(
2
1831
.
1
3746
.
1
)
25
.
0
35
.
0
(
2
3746
.
1
597
.
1
)
15
.
0
25
.
0
(
2
597
.
1
8555
.
1
)
05
.
0
15
.
0
(
2
8555
.
1
2
)
0
05
.
0
(
=
+
−
+
+
−
+
+
−
+
+
−
+
+
−
+
+
−
=
I
%
2022
.
0
%
100
79124
.
0
79284
.
0
79124
.
0
−
×
=
=
tε
(c) Trapezoidal/Simpson’s rules
791282
.
0
6
8131
.
0
)
9808
.
0
(
4
1831
.
1
)
35
.
0
6
.
0
(
8
1831
.
1
)
3746
.
1
597
.
1
(
3
8555
.
1
)
05
.
0
35
.
0
(
2
8555
.
1
2
)
0
05
.
0
(
=
+
+
−
+
+
+
+
−
+
+
−
=
I
%
0052
.
0
%
100
79124
.
0
791282
.
0
79124
.
0
−
×
=
=
tε
21.14 (a) Analytical solution:
dy
x
y
x
y
x
dy
dx
xy
y
x
2
2
3
)
2
(
2 0 1 1 2 3 2 3 1 1 2 0 3 2 2∫
∫ ∫
− −
+
−
=
+
−
666667
.
2
2
1
3
4
3
8
2
4
3
8
1 1 4 3 1 1 3 2=
−
+
=
+
−
=
− −∫
y
y
dy
y
y
y
(b) Sweeping across the x dimension:
y = –1:
3
4
0
)
2
(
2
2
)
0
2
(
−
−
+
−
+
=
−
=
I
y = 0:
3
4
4
)
1
(
2
0
)
0
2
(
−
+
+
=
=
I
y = 1:
1
4
4
)
0
(
2
2
)
0
2
(
−
−
+
+
=
=
I
2
4
1
)
3
(
2
3
))
1
(
1
(
−
−
−
+
+
=
=
I
%
25
%
100
666667
.
2
2
666667
.
2
−
×
=
=
tε
(c) Sweeping across the x dimension:
y = –1:
33333
.
3
6
0
)
2
(
4
2
)
0
2
(
−
−
+
−
+
=
−
=
I
y = 0:
666667
.
2
6
4
)
1
(
4
0
)
0
2
(
−
+
+
=
=
I
y = 1:
666667
.
0
6
4
)
0
(
4
2
)
0
2
(
−
−
+
+
=
=
I
These values can then be integrated along the y dimension:
%
0
666667
.
2
6
666667
.
0
)
666667
.
2
(
4
33333
.
3
))
1
(
1
(
−
−
−
+
+
=
=
=
tI
ε
21.15 (a) Analytical solution:
dz
dy
yzx
x
dz
dy
dx
yz
x
3
4
)
3
(
1 3 4 2 2 2 0 2 2 2 0 1 3 3 − − − −
−
=
−
∫ ∫
∫ ∫ ∫
[
y
y
z
]
dz
z
dz
dz
dy
yz
20
6
40
24
12
20
2 2 2 0 2 2 2 2 2 2 0−
−
=
−
−
=
−
−
=
∫ ∫
∫
∫
− − −[
−
40
−
12
2]
22=
−
160
=
z
z
−(b) For z = –2, sweeping across the x dimension:
z = –2;
y
= 0:
20
6
1
)
1
(
4
27
))
3
(
1
(
−
−
−
+
−
+
=
−
=
I
z = –2;
y
= 1:
4
6
7
)
5
(
4
21
))
3
(
1
(
−
−
−
+
+
=
=
I
z = –2;
y
= 2:
28
6
13
)
11
(
4
15
))
3
(
1
(
−
−
−
+
+
=
=
I
8
6
28
)
4
(
4
20
)
0
2
(
−
−
+
+
=
=
I
For z = 0, similar calculations yield
z = 0;
y
= 0:
I = –20
z = 0;
y
= 1:
I = –20
z = 0;
y
= 2:
I = –20
These values can then be integrated along the y dimension:
40
6
20
)
20
(
4
20
)
0
2
(
−
−
+
−
−
=
−
=
I
For z = 2, similar calculations yield
z = 2;
y
= 0:
I = –20
z = 2;
y
= 1:
I = –44
z = 2;
y
= 2:
I = –68
These values can then be integrated along the y dimension:
88
6
68
)
44
(
4
20
)
0
2
(
−
−
+
−
−
=
−
=
I
Finally, these results can be integrated along the z dimension,
%
0
160
6
88
)
40
(
4
8
))
2
(
2
(
−
−
+
−
−
=
−
t=
=
ε
I
21.16 Here is a VBA program that is set up to duplicate the computation performed in Example
21.2.
Option Explicit Sub TestTrapm()
Dim n As Integer, i As Integer
Dim a As Double, b As Double, h As Double Dim x(100) As Double, f(100) As Double 'Enter data and integration parameters a = 0
b = 0.8 n = 2
h = (b - a) / n
'generate data from function x(0) = a
f(0) = fx(a) For i = 1 To n
x(i) = x(i - 1) + h f(i) = fx(x(i))
Next i
'invoke function to determine and display integral MsgBox "The integral is " & Trapm(h, n, f)
End Sub
Function Trapm(h, n, f)
Dim i As Integer, sum As Double sum = f(0)
For i = 1 To n - 1 sum = sum + 2 * f(i) Next i sum = sum + f(n) Trapm = h * sum / 2 End Function Function fx(x) fx = 0.2 + 25 * x - 200 * x ^ 2 + 675 * x ^ 3 - 900 * x ^ 4 + 400 * x ^ 5 End Function
21.17 Here is a VBA program that is set up to duplicate the computation performed in Example
21.5.
Option Explicit Sub TestSimpm()
Dim n As Integer, i As Integer
Dim a As Double, b As Double, h As Double Dim x(100) As Double, f(100) As Double 'Enter data and integration parameters a = 0
b = 0.8 n = 4
h = (b - a) / n
'generate data from function x(0) = a f(0) = fx(a) For i = 1 To n x(i) = x(i - 1) + h f(i) = fx(x(i)) Next i
'invoke function to determine and display integral MsgBox "The integral is " & Simp13m(h, n, f) End Sub
Function Simp13m(h, n, f) Dim i As Integer
Dim sum As Double sum = f(0)
For i = 1 To n - 2 Step 2
sum = sum + 4 * f(i) + 2 * f(i + 1) Next i sum = sum + 4 * f(n - 1) + f(n) Simp13m = h * sum / 3 End Function Function fx(x) fx = 0.2 + 25 * x - 200 * x ^ 2 + 675 * x ^ 3 - 900 * x ^ 4 + 400 * x ^ 5 End Function
21.8.
Option Explicit Sub TestUneven()
Dim n As Integer, i As Integer Dim label As String
Dim a As Double, b As Double, h As Double Dim x(100) As Double, f(100) As Double 'Enter data Sheets("Sheet1").Select Range("a6").Select n = ActiveCell.Row Selection.End(xlDown).Select n = ActiveCell.Row - n 'Input data from sheet Range("a6").Select For i = 0 To n x(i) = ActiveCell.Value ActiveCell.Offset(0, 1).Select f(i) = ActiveCell.Value ActiveCell.Offset(1, -1).Select Next i
'invoke function to determine and display integral MsgBox "The integral is " & Uneven(n, x, f)
End Sub
Function Uneven(n, x, f) Dim k As Integer, j As Integer
Dim h As Double, sum As Double, hf As Double h = x(1) - x(0) k = 1 sum = 0# For j = 1 To n hf = x(j + 1) - x(j) If Abs(h - hf) < 0.000001 Then If k = 3 Then
sum = sum + Simp13(h, f(j - 3), f(j - 2), f(j - 1)) k = k - 1 Else k = k + 1 End If Else If k = 1 Then
sum = sum + Trap(h, f(j - 1), f(j)) Else
If k = 2 Then
sum = sum + Simp13(h, f(j - 2), f(j - 1), f(j)) Else
sum = sum + Simp38(h, f(j - 3), f(j - 2), f(j - 1), f(j)) End If k = 1 End If End If h = hf Next j Uneven = sum End Function Function Trap(h, f0, f1)
Trap = h * (f0 + f1) / 2 End Function Function Simp13(h, f0, f1, f2) Simp13 = 2 * h * (f0 + 4 * f1 + f2) / 6 End Function Function Simp38(h, f0, f1, f2, f3) Simp38 = 3 * h * (f0 + 3 * (f1 + f2) + f3) / 8 End Function Function fx(x) fx = 0.2 + 25 * x - 200 * x ^ 2 + 675 * x ^ 3 - 900 * x ^ 4 + 400 * x ^ 5 End Function