Chapter 2 Numerical Methods Ppt
Chapter 2 Numerical Methods Ppt
(CENG-3081)
− b b 2 − 4 ac
x=
2a
f ( x) = ax 2 + bx + c = 0
-4
Objectives of Study
• Understand the graphical interpretation of a root
• Know the graphical interpretation of the false-
position method and why it is usually superior to
the bisection method
• Understand the difference between bracketing and
open methods for root location
• Understand the concepts of convergence and
divergence.
• Know why bracketing methods always converge,
whereas open methods may sometimes diverge
Objectives of Study Cont’d
• Realize that convergence of open methods is more
likely if the initial guess is close to the true root
• Know the fundamental difference between the false
position and secant methods and how it relates to
convergence
• Understand the problems posed by multiple roots
and the modification available to mitigate them
• Use the techniques presented to find the root of an
equation
Overview of Methods
• Bracketing methods
– Graphing method
– Bisection method
– False position
• Open methods
– Fixed point iteration
– Newton-Raphson
– Secant method
Graphical
(Limited Practical Value)
f(x) f(x)
consider lower and
upper bound same
sign, no roots or
x even # of roots x
f(x) f(x)
opposite sign,
odd # of roots
x x
Bisection Method
• Takes advantage of sign changing.
• 𝑓 𝑥𝑙 𝑓 𝑥𝑢 < 0 where the subscripts refer
to lower and upper bounds respectively.
• There is at least one real root
x x x
Bisection Method Algorithm
✓ Choose 𝑥𝑢 𝑎𝑛𝑑 𝑥𝑙 . Verify sign change
▪ 𝑓 𝑥𝑙 𝑓 𝑥𝑢 < 0
✓ Estimate root
𝑥𝑙 +𝑥𝑢
▪ 𝑥𝑟 =
2
✓ Determine if the estimate is in the lower or upper
subinterval
▪ 𝑓 𝑥𝑙 𝑓 𝑥𝑟 < 0 then 𝑥𝑢 = 𝑥𝑟 RETURN
▪ 𝑓 𝑥𝑙 𝑓 𝑥𝑟 > 0 then 𝑥𝑙 = 𝑥𝑟 RETURN
▪ 𝑓 𝑥𝑙 𝑓 𝑥𝑟 = 0 then root equals 𝑥𝑟 →COMPLETE
Termination Criteria and Error Estimates
𝑥𝑟 𝑛𝑒𝑤 − 𝑥𝑟 𝑜𝑙𝑑
𝜀𝑎 = 𝑛𝑒𝑤
100%
𝑥𝑟
Where 𝜀𝑎 = error in percent
𝑥𝑟 𝑛𝑒𝑤 = The root for the present iteration
𝑥𝑟 𝑜𝑙𝑑 = The root from the previous iteration
Example 1
10
6
f(x)
4 3.7 1 8282
0 -0.6321 2
-2
-2 -1 0 1 2
x
SOLUTION
10
6
f(x)
4 3.7 1 8282
2 1
0 -0.6321 2
-2
-2 -1 0 1 2
x
Solution Cont’d
1
f(x)
0
0.1 06531 -0.6321 2
-2
-1 0 1 2
x
−𝑥
𝑓 𝑥 =𝑒 −𝑥
′
Bisection Method (Solution Cont d)
𝑻𝒓𝒊𝒂𝒍 𝒙𝒍 𝒙𝒓 𝒙𝒖 𝒇(𝒙𝒍 ) 𝒇(𝒙𝒓 ) 𝒇(𝒙𝒍 )𝒇(𝒙𝒓 )
0 -1 0 1 3.718282 1 3.718282
1 0 0.5 1 1 0.106531 0.106531
2 0.5 0.75 1 0.106531 -0.27763 -0.02958
3 0.5 0.625 0.75 0.106531 -0.08974 -0.00956
4 0.5 0.5625 0.625 0.106531 0.007283 0.000776
5 0.5625 0.59375 0.625 0.007283 -0.0415 -0.0003
6 0.5625 0.578125 0.59375 0.007283 -0.01718 -0.00013
7 0.5625 0.570313 0.578125 0.007283 -0.00496 -3.6E-05
8 0.5625 0.566406 0.570313 0.007283 0.001155 8.41E-06
9 0.566406 0.568359 0.570313 0.001155 -0.00191 -2.2E-06
10 0.566406 0.567383 0.568359 0.001155 -0.00038 -4.3E-07
Solution Cont’d
After 10 trials,
𝒙𝒓 = 0.567383
𝒇 𝒙 = 𝒆−𝒙 − 𝒙
= −0.00038 ≅ 𝟎
𝜺𝒂 = 𝟎. 𝟏𝟕%
Example 2
Use the bisection method to determine the root of
the function:
𝒇 𝒙 = 𝒙𝟑 + 𝟒𝒙𝟐 − 𝟏𝟎,
𝒙𝒍 = 𝟏 & 𝒙𝒖 = 𝟐
𝒇 𝒙 = 𝒙𝟑 + 𝟒𝒙𝟐 − 𝟏𝟎,
Bisection Method, 𝒙𝒍 = 𝟏 & 𝒙𝒖 = 𝟐
𝑻𝒓𝒊𝒂𝒍 𝒙𝒍 𝒙𝒓 𝒙𝒖 𝒇(𝒙𝒍 ) 𝒇(𝒙𝒓 ) 𝒇(𝒙𝒍 )𝒇(𝒙𝒓 )
0 1 1.5 2 -5 2.375 -11.875
1 1 1.25 1.5 -5 -1.79688 8.984375
2 1.25 1.375 1.5 -1.79688 0.162109 -0.29129
3 1.25 1.3125 1.375 -1.79688 -0.84839 1.524448
4 1.3125 1.34375 1.375 -0.84839 -0.35098 0.29777
5 1.34375 1.359375 1.375 -0.35098 -0.09641 0.033838
6 1.359375 1.3671875 1.375 -0.09641 0.032356 -0.00312
7 1.359375 1.3632813 1.3671875 -0.09641 -0.03215 0.0031
8 1.3632813 1.3652344 1.3671875 -0.03215 7.2E-05 -2.3E-06
9 1.3632813 1.3642578 1.3652344 -0.03215 -0.01605 0.000516
10 1.3642578 1.3647461 1.3652344 -0.01605 -0.00799 0.000128
Solution Cont’d
After 10 trials,
𝒙𝒓 = 1.3647461
𝒇 𝒙 = 𝒙𝟑 + 𝟒𝒙𝟐 − 𝟏𝟎
= −0.00799 ≅ 𝟎
𝜺𝒂 = 𝟎. 𝟎𝟒%
False Position Method
• Even though bisection method is a perfectly
valid technique for determining roots
• “Brute-Force” approach of bisection method is
relatively inefficient
• Join points by a straight line
• Improves the estimate
• Replacing the curve by a straight line gives the
“false position”
Based on similar
triangles
Next estimate, 𝒙𝒓 𝑓(𝑥𝑢 )
𝑥𝑙 f ( xl ) f ( xu )
=
𝑥𝑢 xr − xl xr − xu
𝑓(𝑥𝑙 )
f ( xu )( xl − xu )
xr = xu −
f ( xl ) − f ( xu )
Example on False-Position Method
Find the root of 𝑓 𝑥 = 𝑥 − 4 2 𝑥 − 2 = 0
Using the Initial Guesses of 𝑥𝑙 = 1 & 𝑥𝑢 = 2.5, and a
pre-specified tolerance 𝜀𝑠 = 0.1%
Solution
Trial 𝒙𝒍 𝒙𝒖 𝒇(𝒙𝒍 ) 𝒇(𝒙𝒖 ) 𝒙𝒓 𝒇(𝒙𝒓 )
0 1 2.5 -9 1.125 2.333333 0.925926
1 2.333333 1 0.925926 -9 2.208955 0.670295
2 2.208955 1 0.670295 -9 2.125157 0.43993
3 2.125157 1 0.43993 -9 2.072721 0.270115
4 2.072721 1 0.270115 -9 2.041464 0.159049
5 2.041464 1 0.159049 -9 2.023378 0.09134
6 2.023378 1 0.09134 -9 2.013097 0.051702
7 2.013097 1 0.051702 -9 2.00731 0.029026
8 2.00731 1 0.029026 -9 2.004072 0.01622
9 2.004072 1 0.01622 -9 2.002265 0.009041
10 2.002265 1 0.009041 -9 2.00126 0.005032
𝒙𝒓 = 𝟐. 𝟎𝟎𝟏𝟐𝟔
𝜺𝒂 = 𝟎. 𝟎𝟓𝟎𝟑 < 𝟎. 𝟏% (𝜺𝒔 ) 𝑶𝒌!
Exercise on False-Position Method
Determine the root of the following equation
using the false position method starting with an
initial estimate of 𝑥𝑙 = 4.55 𝑎𝑛𝑑 𝑥𝑢 = 4.65
𝑓 𝑥 = 𝑥 3 − 98
30
20
10
f(x) 0
-1 0
-20
-30
-40
4 4.5 5
x
Pitfalls of False Position Method
f(x)=x1 0-1
30
25
20
15
f(x)
10
5
0
-5
0 0.5 1 1 .5
x
Group Assignment (5 Students )
xi
xi+1 x
f(xi)
Solution can “overshoot” the root and potentially diverge
f(x)
x2 x1
x0 x
Fixed-Point Iteration
• Open methods employ a formula to predict the root
• In fixed-point iteration, rearrange the function f(x)
so that x is on the left hand side of the equation
✓ For example, 𝑓 𝑥 = 𝑥 2 − 2𝑥 + 3 = 0
𝒙𝟐 +𝟑
▪𝒙 = 𝑜𝑟
𝟐
2 𝟑
▪ 𝑥 − 2𝑥 = −3 → 𝑥 𝑥 − 2 = −3 → 𝒙 =
𝟐−𝒙
– For the given rearranged function 𝑥 = 𝑔 𝑥 ,
– 𝐼𝑓 𝑔′(𝑥) ≤ 1, 𝑐𝑜𝑛𝑣𝑒𝑟𝑔𝑒𝑛𝑡, in the given set of interval
– 𝐼𝑓 𝑔′(𝑥) > 1, 𝑛𝑜𝑡 𝑐𝑜𝑛𝑣𝑒𝑟𝑔𝑒𝑛𝑡
Fixed-Point Iteration Cont’d
• In fixed point iteration, rearrange the function
f(x) so that x is on the left hand side of the
equation
▪ i.e. for f(x) = sin x = 0
▪ x = sin x + x
• Let x = g(x)
• New estimate based on
➢ x i+1 = g(xi)
EXAMPLE
• Consider f(x) = e-x -3x
• x=g(x) = e-x / 3 15
• Initial guess x = 0
10
Iter. x g(x) f(x) ea
0 0 0.333 -0.28347
1 0.333 0.239 0.071007 39.561% 5
2 0.239 0.263 -0.01842 9.016%
3 0.263 0.256 0.004737 2.395%
4 0.256 0.258 -0.00122 0.612% 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
5 0.258 0.258 0.000315 0.158%
6 0.258 0.258 -8.1E-05 0.041% -5
7 0.258 0.258 2.09E-05 0.010%
8 0.258 0.258 -5.4E-06 0.003%
9 0.258 0.258 1.39E-06 0.001% -10
Slope
f(xi)
dy
Slope = = f ' ( x)
dx
f ( xi ) − 0
f ' ( xi ) =
xi − xi +1
xi Re arrange
xi+1
f ( xi )
xi +1 = xi −
f ' ( xi )
EXAMPLE
Use the Newton Raphson method to determine the root of
f(x) = x2 - 11 using an initial guess of xi = 3
Solution
𝑓 𝑥 = 𝑥 2 − 11
𝑓 ′ 𝑥 = 2𝑥
𝑥𝑖 = 3
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′(𝑥𝑛 )
100
80
Iter. 𝒙𝒊 𝒙𝒊+𝟏 𝒇(𝒙) 𝜺𝒂
f(x) = x2 - 11
60
0 3 3.333333 0.111111
40
𝑓(𝑥𝑛 ) − 𝑓(𝑥𝑛−1 )
𝑓′(𝑥𝑛 ) ≅
𝑥𝑛 − 𝑥𝑛−1
What is this? HINT: dy / dx = Δy / Δ x
f(x)
1
1 x
new est.