numerical methods - marmara Üniversitesi · 2019-03-07 · lecture 4: roots of equations -...
Post on 22-May-2020
5 Views
Preview:
TRANSCRIPT
Numerical Methods
Mustafa YILMAZSchool of Mechanical Engineering
University of Marmara
Lecture 4 –Roots of Equations Bracketing Methods
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 2
Root Concept
• The root of an equation is the value of x that f(x) = 0.
• Roots are called the zeros of equation.
• There are many functions for which the root cannot be determined so easily.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 3
Methods for Determining Roots
• Noncomputer methods.
• Computer methods.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 4
Manual Methods (Graphical Method)
• Graphical method consists to plot the function and determines where it crosses the x axis. The x value for which f(x) = 0 (the root).
• This process is repeated until a guess is obtained that results in an f(x) than is close to zero.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 5
Manual Methods (Trial and Error)
• Graphical method and trail and error are inefficient and inadequate for the requirements of engineering practice.
• Trial and error consists of guessing a value of x and evaluating whether f(x) is zero. If not , another guess is made, f(x) is again evaluated.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 6
Example: the parachutist problem
Given m = 68.1 kg, v = 40 m/s, t = 10 s, g = 9.8 m/s2, find the corresponding c
Graphical Methods
40138667401168891 146843010168 −−=−−=−−= −−− )(.)().(.)()( .)./()/( cctmc ec
ec
vec
gmcf
)( )/( tmcec
gmv −−= 1
Make a plot of the function and observe where it crosses the x axis
Solution:
c f(c)4 34.115
8 17.653
12 6.067
16 -2.269
20 -8.401
Root is between 12 and 16
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 7
A root may occur in an interval
• f (xmin) and f (xmax) have the same sign.• (a) there will be no roots.• (c) there will be an even numbers of roots within
the interval.
Where : xmin: lower bound and xmax: upper bound
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 8
• f (xmin) and f (xmax) have different sign, • (b) and (d) there will be an odd numbers of roots
within the interval.
A root may occur in an interval
Where : xminl: lower bound and xmax: upper bound
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 9
Cases Where the General Rule does not Hold
• For this case, the end points are of the opposite signs,
• there are an even number of axis intersection for the interval.
• multiple roots that occur when the function is tangential to the x axis.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 10
Cases Where the General Rule does not Hold
• (b) Discontinuous function where end points of opposite sign bracket an even number of roots.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 11
Estimate Properties of Roots By Graphical Methods
From (a) and (c):
if both f(xl) and f(xu) have the same sign, there must be 0 or even number of roots
From (b) and (d): if f(xl) and f(xu) have different signs, there must be 1 or odd number of roots
Exceptions:
multiple roots
f(x) = (x-2)2(x-4)
discontinuous f(x)
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 12
Example: Interest Rate
Suppose you want to buy an electronic appliance from a shop and you can either pay an amount of 12,000 or have a monthly payment of 1,065 for 12 months. What is the corresponding interest rate?
1)1()1(−+
+= n
n
xxxPA
A is the monthly paymentP is the loan amountx is the interest rate per period of timen is the loan period
To find the yearly interest rate, x, you have to find the zero of
1)1()1(000,12065,1 12
12
121212
−++
−x
xx
We know the payment formulae is:
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 13
Finding Roots Graphically
• Not accurate
• However, graphical view can provide useful info about a function.– Multiple roots?– Continuous?– etc.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 14
The following root finding methods will be introduced:
A. Bracketing MethodsA.1. Bisection MethodA.2. Regula Falsi
B. Open MethodsB.1. Fixed Point IterationB.2. Newton Raphson's MethodB.3. Secant Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 15
Bracketing Methods
• Bracketing methods consider the fact that a function typically changes sign in the vicinity of the root.
• In this process two initial guesses for the root are required.
• These two initial guesses are called xmin(lower, xl) and xmax (upper, xu).
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 16
Bracketing Methods
• These guesses must “bracket” or be on either side of, the root.
• The particular methods employ different strategies to systematically reduce the width of the bracket, and find the correct answer.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 17
Bracketing Methods
By Mean Value Theorem,
we know that if a function f(x) is
continuous in the interval [a, b]
and f(a)f(b) < 0, then the
equation f(x) = 0 has at least one
real root in the interval (a, b).
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 18
Usually• f(a)f(b) > 0 implies zero or even
number of roots – [figure (a) and (c)]
• f(a)f(b) < 0 implies odd number of roots– [figure (b) and (d)]
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 19
Exceptional Cases• Multiple roots
– Roots that overlap at one point.– e.g.: f(x) = (x-1)(x-1)(x-2) has a
multiple root at x=1.
• Functions that discontinue within the interval
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 20
Algorithm for bracketing methods
Step 1: Choose two points xl and xu such that f(xl)f(xu) < 0
Step 2: Estimate the root xr (note: xl < xr < xu)
Step 3: Determine which subinterval the root lies:if f(xl)f(xr) < 0 // the root lies in the lower subinterval
set xu to xr and goto step 2
if f(xl)f(xr) > 0 // the root lies in the upper subintervalset xl to xr and goto step 2
if f(xl)f(xr) = 0xr is the root than stop
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 21
How to select xr in step 2?
1. Bisection MethodGuess without considering the characteristics of f(x)
in (xl , xu)
2. False Position Method (Regula Falsi)Use "average slope" to predict the root
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 22
The Bisection Method (Bolzano’s Method)
• Given a bracketed root, repeatedly halve the interval while continuing to bracketing the root.
• Bisection always converges if the original interval contained a root.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 23
The Bisection Method
• Given an initial bracket [xl , xu], an approximation to the root ( xm )is the midpoint of the interval.
• An alternative for the midpoint.
𝑥𝑥𝑟𝑟 =12
(𝑥𝑥𝑢𝑢 + 𝑥𝑥𝑙𝑙)
𝑥𝑥𝑟𝑟 = 𝑥𝑥𝑙𝑙 +(𝑥𝑥𝑢𝑢 − 𝑥𝑥𝑙𝑙)
2
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 24
The Bisection Method
• if f(xm)*f(a) < 0, the root lies in the lower subinterval. Set b = xm , a = a.
•• if f(xm)*f(a) > 0, the root lies in the upper
subinterval. Set a = xm , b = b.•• The new value of the midpoint xm is
calculated, and the process is repeated until the
value of the root is found (or an approximate value).
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 25
Use the bisection method to locate the
lowest root of the following polynomial
f(x) = -2 + 7x - 5x2 + 6x3
initial guesses a = 0 and b = 1, εs = 10 %.
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 26
Iteration I:
f(xl)=f(0) = -2, f(xu)=f(1) = 6, f(0)*f(1) < 0
xm = (a + b) / 2= (0 + 1) / 2 = 0.5
f(xm)=f(0.5) = 1 ,
f(a)*f(xm) = f(0)*f(0.5) = (-2) (1) < 0 ,
a = 0 and b= xm=0.5, 𝜀𝜀𝑎𝑎 =xm,i − xm,i−1
xm,i∗ 100%
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 27
Iteration II:
xm = (a + b) / 2= (0 + 0.5) / 2 = 0.25
f(0.25) = - 0.46875
f(a)*f(xm) = (-2) (- 0.46875) > 0 ,
a= xm=0.25 & b = 0.5, εa = 100 %.
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 28
Iteration III:
xm = (a + b) / 2= (0.25 + 0.5) / 2 = 0.375
f(0.375) = 0.2383
f(a)*f(xm) = (- 0.46875) (0.2383) < 0 ,
a= 0.25 & b = xm = 0.375, εa = 33%.
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 29
Iteration IV:
xm =(a + b)/2=(0.25 + 0.375) / 2=0.3125
f(0.3125) = - 1.6802
f(a)*f(xm) = (- 0.46875) (- 1.6802) > 0 ,
b = 0.375 & a = xm = 0.3125, εa = 20%.
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 30
Iteration V:
xm = (a + b) / 2= (0.3125 + 0.375) / 2 = 0.34375
f(0.34375) = 0.0591428
f(a)*f(xm) = (- 1.6802) (0.0591428) < 0 ,
a = 0.3125 & b= xm = 0.34375
εa = 9.09% < εs = 10 % The process stops.
Example: The Bisection Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 31
Example: The Bisection Method
Apply Bisection to x – x1/3 – 2 = 0.
Use the MATLAB function
demoBisect( xleft, xright, n)
where
xleft, xright : left and right brackets of the root.
n: optional number of iterations.
Default: n = 15
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 32
Bisection Method – Example
𝑓𝑓(𝑥𝑥) =667.38𝑥𝑥
(1 − 𝑒𝑒−0.146843𝑥𝑥) − 40
Find the root of f(x) = 0 with an
approximated error below 0.5%.
(True root: α=14.7802)
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 33
Example (continue)
n xl xr xu f(xl) f(xr) f(xu) f(xl)f(xr) εa (%)0 12 16 6.067 -2.2691 12 14 16 6.067 1.569 -2.269 > 02 14 15 16 1.569 -0.425 -2.269 < 0 6.7
3 14 14.5 15 1.569 0.552 -0.425 > 0 3.5
4 14.5 14.75 15 0.552 0.0590 -0.425 > 0 1.7
5 14.75 14.875 15 0.0590 -0.184 -0.425 < 0 0.8
6 14.75 14.8125 14.875 0.0590 -0.0629 -0.184 < 0 0.4
%100newr
oldr
newr
a xxx −
=ε
%219.0%1007802.14
8125.147802.14=
−=tε𝜀𝜀𝑡𝑡 =
xt − xr
xt∗ 100%
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 34
Error Bounds
The true root, xr , must lie between xl and xu.
xl xuxr
xl(1) xu
(1)
After the 1st iteration, the solution, xr(1), should be within an
accuracy of)1()1(
21
lu xx −
xr(1)
Let xr(n) denotes xr in the nth iteration
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 35
Error Bounds
xl(2) xu
(1)xu(2)
Suppose the root lies in the lower subinterval.
xr(2)
)1()1(2
)2()2(
21
21
lulu xxxx −=−
After the 2nd iteration, the solution, xr(2), should be
within an accuracy of
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 36
Error Bounds
)1()1()1()1(2
)()(
21...
21
21
lunn
ln
un
ln
u xxxxxx −==−=− −−
In general, after the nth iteration, the solution, xr(n),
should be within an accuracy of
If we want to achieve an absolute error of no more than Exr
)(log
21
)1()1(
2
)1()1(
rx
lu
lun
Exxn
Exx
−≥⇒
≤− α
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 37
Implementation Issues
• The condition f(xl)*f(xr) = 0 (in step 3) is difficult to achieve due to errors.
• We should repeat until xr is close enough to the root, but we don't know what the root is!
• Therefore, we have to estimate the error as
and repeat until εa < εs (acceptable error)
ε𝑎𝑎 =𝑥𝑥𝑟𝑟𝑛𝑛𝑛𝑛𝑛𝑛 − 𝑥𝑥𝑟𝑟𝑜𝑜𝑙𝑙𝑜𝑜
𝑥𝑥𝑟𝑟𝑛𝑛𝑛𝑛𝑛𝑛100%
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 38
Pseudocode of Bisection Algorithm
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 39
A.2. Regula Falsi Method
• Also known as the false-position method, or linear interpolation
method.
• Unlike the bisection method which divides the search interval by
half, regula falsi interpolates f(xu) and f(xl) by a straight line and
the intersection of this line with the x-axis Is used as the new
search position.
• The slope of the line connecting f(xu) and f(xl) represents the
"average slope" (i.e., the value of f'(x)) of the points in [xl, xu ].
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 40
=>−
=− rl
l
ru
u
xxxf
xxxf )()(
𝑥𝑥𝑟𝑟 = 𝑥𝑥𝑢𝑢 −𝑓𝑓(𝑥𝑥𝑢𝑢)(𝑥𝑥𝑙𝑙 − 𝑥𝑥𝑢𝑢)𝑓𝑓(𝑥𝑥𝑙𝑙) − 𝑓𝑓(𝑥𝑥𝑢𝑢)
Similar to the bisection method except that the new division point xr is not the middle point of the interval but this:
f(xl) is much closer to 0 than f(xu) the root should be closer to xl than to xu
Using similar triangles, the intersection of the straight line with the x axis can be estimated as
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 41
40138667 1468430 −−= − )(.)( . cec
cf
Example Linear Interpolation Method
1st iteration:xl = 12 ⇒ f(xl) = 6.067xu = 16 ⇒ f(xu) = -2.2688xr = 16 – (-2.268(12 – 16))/(6.067 – (-2.2688)) =14.9113εt = 0.89%
2nd iteration:f(xl)f(xr) = -1.5426 < 0xl = 12, xu = 14.9113;xr = 14.9113 – (-0.2543(12 – 14.9113))/(6.0669-(- 0.2543) = 14.7942εt = 0.09% < εt = 0.2% (Bisection @ 6th iteration)
(True root: α=14.7802)
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 42
Example (continue)
n xl xr xu f(xl) f(xr) f(xu) f(xl)f(xr) εt (%)0 12 16 6.067 -2.2691 12 14.9113 16 6.067 -0.2543 -2.269 > 0 0.89
2 12 14.7942 14.9113 6.067 -0.2543 < 0 0.09
%100newr
oldr
newr
a xxx −
=ε
𝜀𝜀𝑡𝑡 =14.7802 − 14.7942
14.7802100% = 0.09%
𝜀𝜀𝑡𝑡 =xt − xr
xt∗ 100%
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 43
• The error for false
position decreases
much faster than for
bisection.
•The false-position
method is more
efficient.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 44
False-position vs Bisection
• False position in general performs better than bisection method.
• Exceptional Cases:– (Usually) When the deviation of f'(x) is high and
the end points of the interval are selected poorly.– For example,
3.1,0with1)( 10
==−=
ul xxxxf
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 45
Iteration xl xu xr εa (%) εt (%)1 0 1.3 0.65 352 0.65 1.3 0.975 33.3 253 0.975 1.3 1.1375 14.3 13.84 0.975 1.1375 1.05625 7.7 5.65 0.975 1.05625 1.015625 4.0 1.6
Iteration xl xu xr εa (%) εt (%)1 0 1.3 0.09430 90.62 0.09430 1.3 0.18176 48.1 81.83 0.18176 1.3 0.26287 30.9 73.74 0.26287 1.3 0.33811 22.3 66.25 0.33811 1.3 0.40788 17.1 59.2
Bisection Method (Converge quicker)
False-position Method
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 46
3.1,0with1)( 10
==−=
ul xxxxf
The slow convergence of the false-position method.
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 47
Summary
• Bracketing Methods– f(x) has the be continuous in the interval [xl, xu]
and f(xl)f(xu) < 0
– Always converge
– Usually slower than open methods
• Bisection Method– Slow but guarantee the best worst-case convergent rate.
• False-position method– In general performs better than bisection method (with some
exceptions).
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 48
Incremental Search and Determining Initial Guesses
• For every interval xi – xi+1, apply bisection or false-position method to find the roots in the interval
• Only roots in x4-x5 will be found
MATH259 Numerical AnalysisLecture 4: Roots of Equations - Bracketting 49
Home Work of Chapter 5
From the text book:Problem 5.5, 5.6, 5.13.
Additional:None.
top related