Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views21 pages

Numerical Integration

Uploaded by

mwambingadaniel1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views21 pages

Numerical Integration

Uploaded by

mwambingadaniel1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Numerical Integrals

Using the Trapezoidal Rule and Simpson’s Rule

Mathematics is not about numbers, equations,


computations, or algorithms: it is about
understanding. “Ah, if we could only do the all the
integrals . . . But we can’t.”
— Beta Mathematica

s
or
t
Tu
i ty
fin
In

Infinity Tutors
Trapezoidal Rule
Suppose we need to approximate the integral
Z b
f (x) dx
a

using the Trapezoidal Rule with n subdivisions. Then:


Z b
hh  i
f (x) dx ≈ Tn = f (x0 ) + f (xn ) + 2 f (x1 ) + f (x2 ) + . . . + f (xn−1 )
a 2

where:
b−a
h= , xi = a + ih, for i = 0, 1, 2, . . . , n

s
n

or
Also,
x0 = a, xn = b

t
Computation Table:
Tu
i xi f (xi )
0
1
2
.. .. ..
ty

. . .
n−1
n
i
fin

Activity 1

Use Trapezoidal Rule to approximate the following integrals with the given n.
In

Z 1
2
(a). e4x dx, n = 7
0
Z 30    
140000
(b). 2000 ln − 9.8t dt, n=5
8 140000 − 2100t
Z 4
(c). x sin x dx, n=5
0
Z 4 √
(d). xex dx, n=7
0
Z 3
(e). ln x dx, n=6
1

2
Z 2
(f). xe−x dx, n=8
0
(
Z π sin x
(g). f (x)dx, where f (x) = x , x>0
; n=6
0 1, x=0

s
t or
Tu
i ty
fin
In

3
Simpson’s Rule
Suppose we need to approximate the integral
Z b
f (x) dx
a

using Simpson’s Rule with n subdivisions (note: n must be even). Then:


Z b
hh    i
f (x) dx ≈ Sn = f (x0 )+f (xn )+4 f (x1 )+f (x3 )+. . .+f (xn−1 ) +2 f (x2 )+f (x4 )+. . .+f (xn−2 )
a 3

where:
b−a
h= , xi = a + ih, for i = 0, 1, 2, . . . , n

s
n

or
Also,
x0 = a, xn = b

t
Computation Table:
Tu
i xi f (xi )
0
1
2
ty

.. .. ..
. . .
n−1
n
i
fin

Activity 2

Use Simpson’s Rule to approximate the following integrals with the given n.
In

Z 1
2
(a). e4x dx, n = 6
0
Z 30    
140000
(b). 2000 ln − 9.8t dt, n=8
8 140000 − 2100t
Z 4
(c). x sin x dx, n=8
0
Z 4 √
(d). xex dx, n=6
0
Z 3
(e). ln x dx, n=6
1

4
Z 2
(f). xe−x dx, n=8
0
(
Z π sin x
(g). f (x)dx, where f (x) = x , x>0
; n=6
0 1, x=0

s
t or
Tu
i ty
fin
In

5
Suggested Solutions for Activity 1
(a). We want to approximate the integral:
Z 1
2
e4x dx
0

using the Trapezoidal Rule with n = 7 subdivisions.


Here we have:

a = x0 = 0,
b = x7 = 1,
n = 7,

s
2
f (x) = e4x .

or
Now,
b−a 1−0 1

t
h= = =
n 7 7
Tu
and  
1 i
xi = a + ih = 0 + i = , for i = 0, 1, 2, . . . , 7.
7 7

Thus, we tabulate the data as follows:


ty

2
i xi f (xi ) = e4(xi )
0 0 1.00000000000
i

1
fin

1 7 1.08505714419
2
2 7 1.38615068230
3
3 7 2.08484367736
4
4 7 3.69183066048
In

5
5 7 7.69688981037
6
6 7 18.89269822665
7 1 54.59815003314

Therefore,
Z 1
2
e4x dx ≈ T7
0
h
= [f (x0 ) + f (x7 ) + 2 (f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ) + f (x4 ) + f (x5 ) + f (x6 ))]
2
1
7
= [1 + 54.59815003314 + 2 (1.08505714419 + 1.38615068230 + 2.08484367736
2
+ 3.69183066048 + 7.69688981037 + 18.89269822665)] = 8.94807788827 .

6
(b). We want to approximate the integral:
Z 30    
140000
2000 ln − 9.8t dt
8 140000 − 2100t
using the Trapezoidal Rule with n = 5 subdivisions.
Here we have:
a = t0 = 8,
b = t5 = 30,
n = 5,
 
140000
f (t) = 2000 ln − 9.8t.
140000 − 2100t

s
Now,
b−a 30 − 8

or
22
h= = =
n 5 5
and  
22

t
ti = a + ih = 8 + i , for i = 0, 1, 2, 3, 4, 5.
5
Tu
Thus, we tabulate the data as follows:

i ti f (ti )
0 8 177.26674301977
ty

1 8 + 225 = 5
62
290.06982595919
2 44
8 + 5 = 84 5 416.06460201532
3 8 + 66
5 = 5
106
557.69124227735
i

4 8 + 88
5 = 5
128
718.13663089723
fin

110 150
5 8 + 5 = 5 = 30 901.67400151124

Therefore,
Z 30
In

f (t) dt ≈ T5
8
h
= [f (t0 ) + f (t5 ) + 2 (f (t1 ) + f (t2 ) + f (t3 ) + f (t4 ))]
2
22
5
= [177.26674301977 + 901.67400151124 + 2(290.06982595919 + 416.06460201532
2
+ 557.69124227735 + 718.13663089723)]
11
= [1078.94074453101 + 2(1981.96230014909)]
5
11
= [1078.94074453101 + 3963.92460029818]
5
11
= × 5042.86534482919
5
= 11094.30376302425

7
(c). We want to approximate the integral:
Z 4
x sin x dx
0

using the Trapezoidal Rule with n = 5 subdivisions.


Here we have:
a = x0 = 0,
b = x5 = 4,
n = 5,
f (x) = x sin x.

s
Now,
b−a 4−0 4

or
h= = =
n 5 5
and  
4 4i
xi = a + ih = 0 + i = , for i = 0, 1, 2, 3, 4, 5.

t
5 5
Tu
Thus, we tabulate the data as follows:

i xi f (xi ) = xi sin xi
0 0 0.00000000000
4
ty

1 5 0.57388487272
8
2 5 1.59931776487
12
3 5 1.62111163332
16
i

4 5 -0.18679725897
fin

5 4 -3.02720998123

Therefore,
Z 4
In

x sin x dx ≈ T5
0
h
= [f (x0 ) + f (x5 ) + 2 (f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ))]
2
4
5
= [0 + (−3.02720998123) + 2(0.57388487272 + 1.59931776487
2
+ 1.62111163332 − 0.18679725897)]
2
= [−3.02720998123 + 2(3.60751701294)]
5
2
= [−3.02720998123 + 7.21503402588]
5
2
= × 4.18782404465
5
= 1.67512961706

8
(d). We want to approximate the integral:
Z 4 √
x ex dx
0

using the Trapezoidal Rule with n = 7 subdivisions.


Here we have:

a = x0 = 0,
b = x7 = 4,
n = 7,

f (x) = x ex .

s
Now,

or
b−a 4−0 4
h= = =
n 7 7

t
and  
4 4i
xi = a + ih = 0 + i
7
Tu= ,
7
for i = 0, 1, 2, . . . , 7.

Thus, we tabulate the data as follows:


i xi f (xi ) = xi exi
ty

0 0 0.00000000000
4
1 7 1.33859516201
8
2 3.35222008798
i

7
12
3 7.27020118627
fin

7
16
4 7 14.86565579667
20
5 7 29.43115830362
24
6 7 57.09081634954
In

7 4 109.19630006629

9
Therefore,
Z 4
√ x
xe dx ≈ T7
0
h
= [f (x0 ) + f (x7 ) + 2(f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ) + f (x5 ) + f (x6 ))]
2
4
7
= [0 + 109.19630006629 + 2(1.33859516201 + 3.35222008798 + 7.27020118627
2
+ 14.86565579667 + 29.43115830362 + 57.09081634954)]
2
= [109.19630006629 + 2(113.34864688509)]
7
2
= [109.19630006629 + 226.69729377018]
7

s
2
= × 335.89359383647

or
7
= 95.96959823956

t
(e). We want to approximate the integral:
Z 3
Tu
ln x dx
1
using the Trapezoidal Rule with n = 6 subdivisions.
Here we have:
ty

a = x0 = 1,
b = x6 = 3,
i

n = 6,
fin

f (x) = ln x.

Now,
b−a 3−1 1
h= = =
In

n 6 3
and  
1 3+i
xi = a + ih = 1 + i = , for i = 0, 1, 2, . . . , 6.
3 3
Thus, we tabulate the data as follows:

i xi f (xi ) = ln xi
3
0 3 =1 0.00000000000
4
1 3 0.28768207245
5
2 3 0.51082562377
6
3 3 =2 0.69314718056
7
4 3 0.84729786039
8
5 3 0.98082925301
9
6 3 =3 1.09861228867

10
Therefore,
Z 3
ln x dx ≈ T6
1
h
= [f (x0 ) + f (x6 ) + 2(f (x1 ) + f (x2 ) + f (x3 ); +f (x4 ) + f (x5 ))]
2
1
3
= [0 + 1.09861228867 + 2(0.28768207245 + 0.51082562377 + 0.69314718056
2
+ 0.84729786039 + 0.98082925301)]
1
= [1.09861228867 + 2(3.31978199018)]
6
1
= [1.09861228867 + 6.63956398036]

s
6
1

or
= × 7.73817626903
6
= 1.28969604484

(f). We want to approximate the integral:

t
Tu
Z 2
xe−x dx
0

using the Trapezoidal Rule with n = 8 subdivisions.


ty

Here we have:

a = x0 = 0,
i

b = x8 = 2,
fin

n = 8,
f (x) = xe−x .
In

Now,
b−a 2−0 1
h= = =
n 8 4
and  
1 i
xi = a + ih = 0 + i = , for i = 0, 1, 2, . . . , 8.
4 4

Thus, we tabulate the data as follows:

11
i xi f (xi ) = xi e−xi
0 0 0.00000000000
1
1 4 0.19470019577
1
2 2 0.30326532986
3
3 4 0.35427491456
4 1 0.36787944117
5
5 4 0.35813099608
3
6 2 0.33469524022
7
7 4 0.30410440104
8 2 0.27067056647

Therefore,

s
Z 2
xe−x dx ≈ T8

or
0
h
= [f (x0 ) + f (x8 ) + 2 (f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ) + f (x5 ) + f (x6 ) + f (x7 ))]
2

t
1
4
=
2
Tu
[0.00000000000 + 0.27067056647 + 2(0.19470019577 + 0.30326532986 + 0.35427491456
+ 0.36787944117 + 0.35813099608 + 0.33469524022 + 0.30410440104)]
1
= [0.27067056647 + 2(2.21605051870)]
8
1
ty

= [0.27067056647 + 4.43210103740]
8
1
= × 4.70277160387
8
i
fin

= 0.58809645048

(g). We want to approximate the integral:


(
π
In

Z sin x
f (x) dx, where f (x) = x , x>0
0 1, x=0

using the Trapezoidal Rule with n = 6 subdivisions.


Here we have:
a = x0 = 0,
b = x6 = π,
n = 6,
sin x
f (x) = , with f (0) = 1.
x
Now,
b−a π−0 π
h= = =
n 6 6

12
and
π
xi = a + ih = i · , for i = 0, 1, 2, . . . , 6.
6
Thus, we tabulate the data as follows:

sin xi
i xi f (xi ) =
xi
0 0 1.00000000000
π
1 6 0.95492965855
π
2 3 0.82699334313
π
3 2 0.63661977237

4 3 0.41349667157

5 0.19098593171

s
6
6 π 0.00000000000

or
Therefore,

t
Z π
f (x) dx ≈ T6
0
Tu
h
= [f (x0 ) + f (x6 ) + 2 (f (x1 ) + f (x2 ) + f (x3 ) + f (x4 ) + f (x5 ))]
2
π
6
= [1.00000000000 + 0.00000000000 + 2(0.95492965855 + 0.82699334313 + 0.63661977237
2
ty

+ 0.41349667157 + 0.19098593171)]
π
= [1.00000000000 + 2(3.02202537733)]
12
i

π
fin

= [1.00000000000 + 6.04405075466]
12
π
= · 7.04405075466
12
= 1.84431223665
In

13
Suggested Solutions for Activity 2
(a). We want to approximate the integral:
Z 1
2
e4x dx
0

using the Simpson’s Rule with n = 6 subdivisions.


Here we have:

a = x0 = 0,
b = x6 = 1,
n = 6,

s
2
f (x) = e4x .

or
Now,
b−a 1−0 1

t
h= = =
n 6 6
Tu
and
1 i
xi = a + ih = i · = , for i = 0, 1, 2, . . . , 6.
6 6
Thus, we tabulate the data as follows:
ty

2
i xi f (xi ) = e4xi
0 0 1.00000000000
i

1
1 1.11751906874
fin

6
1
2 3 1.55962349761
1
3 2 2.71828182846
2
4 3 5.91669359066
5
In

5 6 16.08324067206
6 1 54.59815003314

14
Therefore,
Z 1
2
e4x dx ≈ S6
0
h
= [f (x0 ) + f (x6 ) + 4(f (x1 ) + f (x3 ) + f (x5 )) + 2(f (x2 ) + f (x4 ))]
3
1
6
= [1.00000000000 + 54.59815003314 + 4(1.11751906874 + 2.71828182846 + 16.08324067206)
3
+ 2(1.55962349761 + 5.91669359066)]
1
= [55.59815003314 + 4(19.91904156926) + 2(7.47631708827)]
18
1
= [55.59815003314 + 79.67616627704 + 14.95263417654]

s
18
1

or
= · 150.22695048672
18
= 8.34594169371

(b). We want to approximate the integral:

t
Tu
Z 30    
140000
2000 ln − 9.8t dt
8 140000 − 2100t

using the Simpson’s Rule with n = 8 subdivisions.


ty

Here we have:

a = t0 = 8,
i

b = t8 = 30,
fin

n = 8,
 
140000
f (t) = 2000 ln − 9.8t.
140000 − 2100t
In

Now,
b−a 22 11 11 32 + 11i
h= = = , ti = a + i · h = 8 + i · =
n 8 4 4 4

Thus, we tabulate the data as follows:

15
i ti f (ti )
0 8 177.26674301977
43
1 4 246.33518139249
27
2 2 320.24688864628
65
3 4 399.51653927417
4 19 484.74547257626
87
5 4 576.64231351786
49
6 2 676.05011676092
109
7 4 783.98267835199
8 30 901.67400151124

Therefore,

s
Z 30
f (t) dt ≈ S8

or
8
h  
= f (t0 ) + f (t8 ) + 4 f (t1 ) + f (t3 ) + f (t5 ) + f (t7 ) + 2 f (t2 ) + f (t4 ) + f (t6 )
3

t
11
4
=
3
Tu
[177.26674301977 + 901.67400151124
+ 4(246.33518139249 + 399.51653927417 + 576.64231351786 + 783.98267835199)
+ 2(320.24688864628 + 484.74547257626 + 676.05011676092)]
11
= [1078.94074453101 + 4 × 2006.47671253651 + 2 × 1481.04247898346]
ty

12
11
= [1078.94074453101 + 8025.90685014604 + 2962.08495796692]
12
11
i

= × 12066.93255264397
fin

12
= 11061.35483809031

(c). We want to approximate the integral:


In

Z 4
x sin x dx
0

using the Simpson’s Rule with n = 8 subdivisions.


Here we have:
a = x0 = 0,
b = x8 = 4,
n = 8,
f (x) = x sin x.

Now,
b−a 4−0 1 1 i
h= = = , xi = a + ih = 0 + i · =
n 8 2 2 2

16
Thus, we tabulate the data as follows:

i xi f (xi )
0 0 0.00000000000
1
1 2 0.23971276930
2 1 0.84147098481
3
3 2 1.49624247991
4 2 1.81859485365
5
5 2 1.49618036026
6 3 0.42336002418
7
7 2 -1.22774129691
8 4 -3.02720998123

s
Therefore,

or
Z 4
x sin x dx ≈ S8
0

t
h
= [f (x0 ) + f (x8 ) + 4 (f (x1 ) + f (x3 ) + f (x5 ) + f (x7 )) + 2 (f (x2 ) + f (x4 ) + f (x6 ))]
3
Tu
1h
= 2 0 + (−3.02720998123) + 4(0.23971276930
3
+ 1.49624247991 + 1.49618036026 − 1.22774129691)
i
ty

+ 2(0.84147098481 + 1.81859485365 + 0.42336002418)


1h i
= − 3.02720998123 + 4(2.00439431256) + 2(3.08342586264)
6
i

1h i
fin

= − 3.02720998123 + 8.01757725024 + 6.16685172528


6
1
= × 11.15721899429
6
In

= 1.85953649904

(d). We want to approximate the integral:


Z 4
√ x
xe dx
0

using the Simpson’s Rule with n = 6 subdivisions.


Here we have:

a = x0 = 0,
b = x6 = 4,
n = 6,

f (x) = x ex .

17
Now,
b−a 4 2 2
h= = = , xi = a + ih = i ·
n 6 3 3
Thus, we tabulate the data as follows:

i xi f (xi )
0 0 0.00000000000
2
1 3 1.59031818508
4
2 3 4.38055036042
3 2 10.44970334824
8
4 3 23.50190056938
10
5 3 51.17851092752

s
6 4 109.19630006629

or
Therefore,
Z 4
√ x

t
xe dx ≈ S6
0
Tu
h
= [f (x0 ) + f (x6 ) + 4 (f (x1 ) + f (x3 ) + f (x5 )) + 2 (f (x2 ) + f (x4 ))]
3
2h
= 3 0 + 109.19630006629 + 4(1.59031818508 + 10.44970334824 + 51.17851092752)
3 i
ty

+ 2(4.38055036042 + 23.50190056938)
2
= [109.19630006629 + 4(63.21853246084) + 2(27.88245092980)]
9
i

2
fin

= [109.19630006629 + 252.87412984336 + 55.76490185960]


9
2
= × 417.83533176925
9
In

= 92.85229594872

(e). We want to approximate the integral:


Z 3
ln x dx
1

using the Simpson’s Rule with n = 6 subdivisions.


Here we have:

a = x0 = 1,
b = x6 = 3,
n = 6,
f (x) = ln x.

18
Now,
b−a 3−1 2 1 i 3+i
h= = = = , xi = a + ih = 1 + =
n 6 6 3 3 3

Thus, we tabulate the data as follows:

i xi f (xi )
3
0 3 0.00000000000
4
1 3 0.28768207245
5
2 3 0.51082562377
3 2 0.69314718056
7
4 0.84729786039

s
3
8
5 3 0.98082925301

or
6 3 1.09861228867

Therefore,

t
Z 3
ln x dx ≈ S6
Tu
1
h
= [f (x0 ) + f (x6 ) + 4 (f (x1 ) + f (x3 ) + f (x5 )) + 2 (f (x2 ) + f (x4 ))]
3
1
3
= [0 + 1.09861228867 + 4(0.28768207245 + 0.69314718056 + 0.98082925301) + 2(0.51082562
ty

3
1
= [1.09861228867 + 4(1.96165850602) + 2(1.35812348416)]
9
i

1
= [1.09861228867 + 7.84663402408 + 2.71624696832]
fin

9
1
= × 11.66149328107
9
= 1.29572147567
In

(f). We want to approximate the integral:


Z 2
xe−x dx
0

using the Simpson’s Rule with n = 8 subdivisions.


Here we have:

a = x0 = 0,
b = x8 = 2,
n = 8,
f (x) = xe−x .

19
Now,
b−a 2−0 1 1 i
h= = = , xi = a + ih = i · =
n 8 4 4 4
Thus, we tabulate the data as follows:

i xi f (xi )
0 0 0.00000000000
1
1 4 0.19470019577
1
2 2 0.30326532986
3
3 4 0.35427491456
4 1 0.36787944117
5
5 4 0.35813099608

s
3
6 2 0.33469524022

or
7
7 4 0.30410440104
8 2 0.27067056647

t
Therefore,
Z 2
Tu
xe−x dx ≈ S8
0
h
= [f (x0 ) + f (x8 ) + 4 (f (x1 ) + f (x3 ) + f (x5 ) + f (x7 )) + 2 (f (x2 ) + f (x4 ) + f (x6 ))]
3
ty

1
4
= [0 + 0.27067056647 + 4(0.19470019577 + 0.35427491456 + 0.35813099608 + 0.304104401
3
+2(0.30326532986 + 0.36787944117 + 0.33469524022)]
i

1
fin

= [0.27067056647 + 4(1.21121050745) + 2(1.00584001125)]


12
1
= [0.27067056647 + 4.84484202980 + 2.01168002250]
12
1
In

= × 7.12719361877
12
= 0.59393271823

(g). We want to approximate the integral:


(
Z π sin x
f (x) dx, where f (x) = x , x>0
0 1, x=0

using the Simpson’s Rule with n = 6 subdivisions.

20
Here we have:

a = x0 = 0,
b = x6 = π,
n = 6,
(
sin x
f (x) = x , x>0
.
1, x=0

Now,
b−a π iπ
h= = , xi = a + ih =
n 6 6

s
Thus, we tabulate the data as follows:

or
i xi f (xi )
0 0 1.00000000000

t
π
1 6 0.95492965855
2
Tu
π
3 0.82699334313
π
3 2 0.63661977237

4 3 0.41349667157

5 6 0.19098593171
6 π 0.00000000000
ty

Therefore,
Z π
i

f (x) dx ≈ S6
fin

0
h
= [f (x0 ) + f (x6 ) + 4 (f (x1 ) + f (x3 ) + f (x5 )) + 2 (f (x2 ) + f (x4 ))]
3
π
In

6
= [1.00000000000 + 0.00000000000 + 4 (0.95492965855 + 0.63661977237 + 0.19098593171)
3
+ 2 (0.82699334313 + 0.41349667157)]
π
= [1 + 4(1.78253536263) + 2(1.24049001470)]
18
π
= [1 + 7.13014145052 + 2.48098002940]
18
π
= × 10.61112147992
18
= 1.85199007154

21

You might also like