Lesson 7
Lesson 7
LESSON 7
z
NUMERICAL
INTEGRATION &
DIFFERENTIATION
TECHNIQUES
Friday, 25 November 2022
z
LEARNING OUTCOMES
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
NUMERICAL INTEGRATION
𝑏
𝐽 = 𝑥𝑑 𝑥 𝑓 𝑎
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
TRAPEZOIDAL RULE
where:
f0 = f(a)
f1 = f(a + h)
f2 = f(a + 2h) = f(b)
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
TRAPEZOIDAL RULE
In general,
𝑏 1
𝑓 𝑎 𝑥 𝑑𝑥 = ℎ 𝑓0 + 2 𝑓1 + 𝑓2 + ⋯ + 𝑓𝑁−1 + 𝑓𝑁
2
1
= ℎ[𝑓0 + 2 σ𝑁−1
𝑖=1 𝑓 𝑎 + 𝑖ℎ + 𝑓𝑁 ]
2
𝑏−𝑎
where: ℎ =
𝑁
𝑓0 = 𝑓 𝑎 , 𝑓1 = 𝑓 𝑎 + ℎ , … , 𝑓𝑁 = 𝑓 𝑎 + 𝑁ℎ = 𝑓(𝑏)
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 1
2
Using 4 subintervals, approximate 1 𝑙𝑛𝑥 𝑑𝑥 by trapezoidal rule.
Round-off to 6D. Calculate the error.
SOLUTION:
𝑏−𝑎 2−1
ℎ= = = 0.25
𝑁 4
n xn fn = ln xn
0 1 0
1 1.25 0.223144
2 1.5 0.405465
3 1.75 0.559616
4 2 0.693147
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 1
SOLUTION…
Since
𝑏 1
= 𝑥𝑑 𝑥 𝑓 𝑎2 ℎ [𝑓0 + 2 𝑓1 + 𝑓2 + ⋯ + 𝑓𝑁−1 + 𝑓𝑁 ]
2
1
න 𝑙𝑛𝑥 𝑑𝑥 = ℎ 𝑓0 + 2 𝑓1 + 𝑓2 + 𝑓3 + 𝑓4
1 2
1
= 0.25 [0 + 2 0.223144 + 0.405465 + 0.559616
2
+0.693147]
2
න 𝑙𝑛𝑥 𝑑𝑥 = 𝟎. 𝟑𝟖𝟑𝟕𝟎𝟎
1
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 1
SOLUTION…
1 𝑥2
Using trapezoidal rule with N = 10, compute 0 𝑒 𝑑𝑥.
Round-off to 6D.
SOLUTION:
𝑏−𝑎 1−0
ℎ= = = 0.1
𝑁 10
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 2
SOLUTION…
𝟐
n 𝒙𝒏 𝒙𝒏 𝟐 fn = 𝒆 𝒙 𝒏
0 0 0 1
1 0.1 0.01 1.010050
2 0.2 0.04 1.040811
3 0.3 0.09 1.094174
4 0.4 0.16 1.173511
5 0.5 0.25 1.284025
6 0.6 0.36 1.433329
7 0.7 0.49 1.632316
8 0.8 0.64 1.896481
9 0.9 0.81 2.247908
10 1 1 2.718282
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 2
SOLUTION…
𝑏 1
𝑓 𝑎 𝑥 𝑑𝑥 = ℎ [𝑓0 + 2 𝑓1 + 𝑓2 + ⋯ + 𝑓𝑁−1 + 𝑓𝑁 ]
2
1 2 1
0 𝑒 𝑥 𝑑𝑥 = 2 ℎ [𝑓0 + 2(𝑓1 + 𝑓2 + 𝑓3 + 𝑓4 + 𝑓5 + 𝑓6 + 𝑓7 + 𝑓8 + 𝑓9 )
+𝑓10 ]
1
= 0.1 [1 + 2 (1.010050 + 1.040811 + 1.094174
2
1 2
0 𝑒 𝑥 𝑑𝑥 = 𝟏. 𝟒𝟔𝟕𝟏𝟕𝟓
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
SIMPSON’S RULE
▪ based on passing a quadratic through three equally spaced points,
rather than passing a straight line through two points
3 𝑖 𝑜𝑑𝑑 =1 𝑓𝑖 + 2 σ𝑖 𝑒𝑣𝑒𝑛 =2 𝑓𝑖 + 𝑓𝑁 ]
𝑏−𝑎
where: ℎ =
𝑁
𝑓0 = 𝑓 𝑎 , 𝑓1 = 𝑓 𝑎 + ℎ , … , 𝑓𝑁 = 𝑓 𝑎 + 𝑁ℎ = 𝑓(𝑏)
z
EXAMPLE PROBLEM 3
2
Using 4 subintervals, approximate 1 𝑙𝑛𝑥 𝑑𝑥 by
Simpson’s rule. Round-off to 6D. Calculate the error.
SOLUTION:
𝑏−𝑎 2−1
ℎ= = = 0.25
𝑁 4
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 3
SOLUTION…
n xn fn = ln xn
0 1 0
1 1.25 0.223144
2 1.5 0.405465
3 1.75 0.559616
4 2 0.693147
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 3
SOLUTION…
𝑏 1
= 𝑥𝑑 𝑥 𝑓 𝑎 3
ℎ[𝑓0 + 4 𝑓1 + 𝑓3 + ⋯ + 𝑓𝑁−1 + 2(𝑓2 + 𝑓4 +
… + 𝑓𝑁−2 ) + 𝑓𝑁 ]
2 1
1 𝑙𝑛𝑥 𝑑𝑥 = 3 ℎ 𝑓0 + 4 𝑓1 + 𝑓3 + 2𝑓2 + 𝑓4
1
= 0.25 [0 + 4 0.223144 + 0.559616 + 2 0.405465
3
+0.693147]
2
1 𝑙𝑛𝑥 𝑑𝑥 = 𝟎. 𝟑𝟖𝟔𝟐𝟔𝟎
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 3
SOLUTION…
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 4
2
Using 8 subintervals, approximate 0 cosh 𝑥 𝑑𝑥 by
Simpson’s rule. Round-off to 6D.
SOLUTION:
𝑏−𝑎 2−0
ℎ= = = 0.25
𝑁 8
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 4
SOLUTION…
n xn fn = cosh xn
0 0 1
1 0.25 1.031413
2 0.5 1.127626
3 0.75 1.294683
4 1 1.543081
5 1.25 1.888424
6 1.5 2.352410
7 1.75 2.964188
8 2 3.762196
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 4
SOLUTION…
𝑏 1
𝑓 𝑎 𝑥 𝑑𝑥 = ℎ[𝑓0 + 4 𝑓1 + 𝑓3 + ⋯ + 𝑓𝑁−1 + 2(𝑓2 + 𝑓4 + ⋯ +
3
𝑓𝑁−2 ) + 𝑓𝑁 ]
2 1
0 cosh 𝑥 𝑑𝑥 = 3 ℎ 𝑓0 + 4 𝑓1 + 𝑓3 + 𝑓5 + 𝑓7 + 2(𝑓2 +𝑓4 + 𝑓6 ) + 𝑓8
1
= 0.25 [1 + 4 (1.031413 + 1.294683 + 1.888424 +
3
2.964188) + 2 (1.127626 + 1.543081 +
2.352410) + 3.762196]
1
= 0.25 [1 + 28.714832 + 10.046234 + 3.762196]
3
2
0 cosh 𝑥 𝑑𝑥 = 𝟑. 𝟔𝟐𝟔𝟗𝟑𝟗
z
NUMERICAL
DIFFERENTIATION
▪ the process of numerically approximating the derivative of a
given function at a given point
▪ there are times in which exact formulas are available but they
are very complicated to the point that an exact computation of
the derivative requires a lot of function evaluations
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
FIRST DERIVATIVE
APPROXIMATION
▪ approximates the slope of a
curve f at a particular point x
= x0 in terms of f(x0) and the
value of f at a point where x =
x0 + h
𝑓 𝑥0 +ℎ −𝑓(𝑥0 )
=
𝑥0 +ℎ−𝑥0
′
𝑓 𝑥0 + ℎ − 𝑓(𝑥0 )
𝑓 𝑥0 =
ℎ
𝑓 𝑥0 −𝑓 𝑥0 −ℎ
=
𝑥0 −(𝑥0 −ℎ)
𝑓 𝑥0 − 𝑓 𝑥0 − ℎ
𝑓 ′ 𝑥0 =
ℎ
𝑓 𝑥0 +ℎ −𝑓 𝑥0 −ℎ
=
𝑥0 +ℎ−(𝑥0 −ℎ)
𝑓 𝑥0 + ℎ − 𝑓 𝑥0 − ℎ
𝑓 ′ 𝑥0 =
2ℎ
z
EXAMPLE PROBLEM 5
𝜋
Approximate the derivative of cos x at 𝑥0 = for: (a) h = 0.1, (b) h =
3
0.01, (c) h = 0.001. Use forward difference and central difference
approximations. Round-off to 6D.
SOLUTION:
𝑓 𝑥0 +ℎ −𝑓(𝑥0 )
𝑓 ′ 𝑥0 =
ℎ
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 5
SOLUTION…
𝜋 𝜋
Since f(x) = cos x, f(x0) = cos x0 = cos , f(x0 + h) = cos (x0 + h) = cos +ℎ
3 3
𝜋 𝜋 𝜋 𝜋
𝜋 cos 3 +ℎ −cos 3 cos 3 +0.1 −cos 3 0.411044−0.5
(a) 𝑓′ = = =
3 ℎ 0.1 0.1
= −𝟎. 𝟖𝟖𝟗𝟓𝟔𝟎
𝜋 𝜋 𝜋 𝜋
𝜋 cos 3 +ℎ −cos 3 cos 3 +0.01 −cos 3 0.491315−0.5
(b) 𝑓′ = = =
3 ℎ 0.01 0.01
= −𝟎. 𝟖𝟔𝟖𝟓𝟎𝟎
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 5
SOLUTION…
𝜋 𝜋 𝜋 𝜋
𝜋 cos 3 +ℎ −cos 3 cos 3 +0.001 −cos 3 0.499134−0.5
(c) 𝑓′ = = =
3 ℎ 0.001 0.001
= −𝟎. 𝟖𝟔𝟔𝟎𝟎𝟎
𝑓 𝑥0 +ℎ −𝑓 𝑥0 −ℎ
𝑓 ′ 𝑥0 =
2ℎ
𝜋
Here, f(x0 + h) = cos (x0 + h) = cos + ℎ , f(x0 − h) = cos (x0 − h) =
3
𝜋
cos −ℎ
3
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 5
SOLUTION…
𝜋 𝜋 𝜋 𝜋
𝜋 cos 3 +ℎ −cos 3 −ℎ cos 3 +0.1 −cos 3 −0.1
(a) 𝑓′ = =
3 2ℎ 2(0.1)
0.411044 − 0.583960
= = −𝟎. 𝟖𝟔𝟒𝟓𝟖𝟎
0.2
𝜋 𝜋 𝜋 𝜋
𝜋 cos 3 +ℎ −cos 3 −ℎ cos 3 +0.01 −cos 3 −0.01
(b) 𝑓′ = =
3 2ℎ 2(0.01)
0.491315 − 0.508635
= = −𝟎. 𝟖𝟔𝟔𝟎𝟎𝟎
0.02
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 5
SOLUTION…
𝜋 𝜋 𝜋 𝜋
𝜋 cos +ℎ −cos −ℎ cos +0.001 −cos −0.001
(c) 𝑓′ = 3 3
= 3 3
3 2ℎ 2(0.001)
0.499134 − 0.500866
= = −𝟎. 𝟖𝟔𝟔𝟎𝟎𝟎
0.002
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 6
The distance x of a runner from a fixed point is measured in meters
at intervals of half a second. The Table shows the data obtained.
SOLUTION:
𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 𝑑𝑥
Velocity is given by the formula 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 = or 𝑥 ′ 𝑡 =
𝑡𝑖𝑚𝑒 𝑑𝑡
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 6
SOLUTION…
At t = 1.25 s:
but
𝑓 𝑥0 + ℎ − 𝑓(𝑥0 ) 𝑓 𝑥0 − 𝑓(𝑥0 − ℎ)
−
𝑓 ′′ 𝑥0 = ℎ ℎ
ℎ
𝑓 𝑥0 +ℎ −𝑓 𝑥0 −𝑓 𝑥0 +𝑓(𝑥0 −ℎ)
ℎ
=
ℎ
𝑓 𝑥0 + ℎ − 2 𝑓 𝑥0 + 𝑓(𝑥0 − ℎ)
𝑓 ′′ 𝑥0 =
ℎ2
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 7
The distance x of a runner from a fixed point is measured in meters
at intervals of half a second. The Table shows the data obtained.
SOLUTION:
𝑥 𝑡0 +ℎ −2 𝑥 𝑡0 +𝑥(𝑡0 −ℎ)
𝑥 ′′ 𝑡0 =
ℎ2
Presented by Engr. Romulo C. Cruz, Jr. Electrical Engineering Department College of Engineering & Architecture
z
EXAMPLE PROBLEM 7
SOLUTION…
𝑥 𝑡0 +ℎ −𝑥 𝑡0 −ℎ
𝑥 ′ 𝑡0 =
2ℎ
12.15−6.8
𝑥 ′ 1.5 = = 5.35 𝑚Τ
𝑠
2(0.5)
z
THANK YOU
FOR LISTENING!