Week3 Roots of Eqs - Bracketing

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Part 2

Roots of Equations

1
Roots of Equations

Objective:
Solve for x, given that f(x) = 0
-or-
Equivalently, solve for x such that

g(x) = h(x) ==> f(x) = g(x) – h(x) = 0


Roots of Equations

Mechanical Engineering (C&C 8.4, p. 196):

Find the value of stiffness k of a vibrating mechanical


system such that the displacement x(t) becomes zero at
t= 0.5 s. The initial displacement is x0 and the initial
velocity is zero. The mass m and damping c are known,
and λ = c/(2m).
  
x(t) = x0e-t cos  t  + sin  t   = 0
  
in which
k c2
μ= -
m 4m 2
ROOTS OF EQUATIONS

• Root of an equation: is the value of the equation variable


which make the equations = 0.0

 b  b 2  4ac
ax 2  bx  c  0  x
2a

• But

ax 5  bx 4  cx3  dx 2  ex  f  0  x  ?
sin x  x  0  x  ?
ROOTS OF EQUATIONS

• Non-computer methods:
- Closed form solution (not always available)
- Graphical solution (inaccurate)

• Numerical systematic methods suitable for


computers
ROOTS OF EQUATIONS
Bisection method
Bracketing
Methods
False Position Method

Simple fixed point


iteration

Roots of Newton Raphson


Equations Open Methods
Secant

Modified Newton
Raphson
Roots of Muller
polynomials Method
Nonlinear Equation
Solvers

Bracketing Graphical Open Methods

Bisection Newton Raphson


False Position
(Regula-Falsi) Secant

All Iterative
Graphical Solution

• Plot the function f(x)

f(x)

roots

x
f(x)=0 f(x)=0
• The roots exist where f(x) crosses the x-axis.
Roots of Equations
• Graphical methods:
– Determine the friction coefficient c necessary for a
parachutist of mass 68.1 kg to have a speed of 40 m/s
at 10 seconds.

– Reorganizing.
Graphical Solution: Example
c
mg  t
The parachutist velocity is v  (1  e m
• )
c
• V = 40 m/s, m=68.1 kg, t =10 s, g= 9.8 m/s2

f(c)
c
mg  t
f (c)  (1  e m )  v
c
667.38  0.146843c
f (c)  (1  e )  40
c c
c=14.75 Check: f (14.75) = 0.059 ~ 0.0
v (c=14.75) = 40.06 ~ 40 m/s
Roots of Equations

Two Fundamental Approaches


1. Bracketing or Closed Methods
- Bisection Method
- False-position Method (Regula falsi).
2. Open Methods
- Newton-Raphson Method
- Secant Method
- Fixed point Methods
Chapter 5

Bracketing Methods

12
Bracketing Methods

f(x) No roots or even f(x)


Odd number of roots
number of roots
f(xl)=+ve f(xl)=+ve
roots roots
f(xu)=+ve
x x
xl xu f(xu)=-ve
xl xu
Bracketing Methods (cont.)

• Two initial guesses (xl and xu) are required for


the root which bracket the root (s).
• If one root of a real and continuous function,
f(x)=0, is bounded by values xl , xu then f(xl).f(xu)
<0.
(The function changes sign on opposite sides of the root)
Bracketing Methods
f(x) In Figure a) we have the case of f(xl)
and f(xu) with the same sign, and there
is no root in the interval (xl,xu).
a) x
f(x) In Figure b) we have the case of f(xl)
and f(xu) With different sign, and there
is a root in the interval (xl,xu).
b) x
f(x) In Figure c) we have the case of f(xl)
and f(xu) with the same sign, and there
are two roots.
c) x
f(x)
In Figure d) we have the case of f(xl)
and f(xu) with different sign, and there is
xl x an odd number of roots.
d) xu
Bracketing Methods
• Though the cases above are generally valid, there are
cases in which they do not hold.

f(x) In Figure a) we have the case of f(xl)


and f(xu) with different sign, but there is
a double root.
a) x
f(x) In Figure b) We have the case of f(xl)
and f(xu) With different sign, but there
are two discontinuities.
b) x
f(x) In Figure c) we have the case of f(xl)
and f(xu) with the same sign, but there
is a multiple root.
xl x
c) xu
Bracketing Methods (Bisection Method)

Bisection Method

f(x) f(x)
xl  xu
xr 
2 f(xu) f(xu)
f(xr)
(x1) f(x1) f(xr) > 0 (x1)
(xu) x xr => x1 (xr)(xu) x
f(xr) f(x1)
f(x1)
1. Bisection Method

• Generally, if f(x) is real and continuous in the interval xl

to xu and f (xl).f(xu)<0, then there is at least one real


root between xl and xu to this function.

• The interval at which the function changes sign is

located. Then the interval is divided in half with the root


lies in the midpoint of the subinterval. This process is
repeated to obtained refined estimates.
1. Bisection Method f(x)
xr = ( xl + xu )/2
Step 1: Choose lower xl and upper xu
guesses for the root such that: f(xu)
f(xl).f(xu)<0
Step 2: The root estimate is:
xr = ( xl + xu )/2 xl xr1 xu
x
Step 3: Subdivide the interval according
to: f(xr1) f(xu)
– If (f(xl).f(xr)<0) the root lies in the
lower subinterval; xu = xr and go to f(x)
(f(xl).f(xr)<0): xu = xr
step 2. xr = ( xl + xu )/2
– If (f(xl).f(xr)>0) the root lies in the
f(xu)
upper subinterval; xl = xr and go to
step 2. f(xr2)
– If (f(xl).f(xr)=0) the root is xr and stop xl xu
x
xr2
f(xu)
Bisection Method
Termination Criteria
Approximate relative Error :
True relative Error : X rn  X rn 1
ea   100%
X true  X approximate Xr n
et  100%
X true Xu X l
ea   100% (Bisection)
Xu X l

• For the Bisection Method ea > et


• The computation is terminated when ea becomes less than
a certain criterion (ea < es)
Bisection method: Example
c
mg  t
• The parachutist velocity is v (1  e m
)
c
• What is the drag coefficient c needed to reach a velocity of

40 m/s if m = 68.1 kg, t = 10 s, g= 9.8 m/s2


f(c)
c
mg  t
f (c )  (1  e )  v
m
c
667.38
f (c )  (1  e 0.146843c )  40
c
c
1. Bisection Method f(x)

1. Assume xl =12 and xu=16 6.067


f(xl)=6.067 and f(xu)=-2.269
2. The root: xr=(xl+xu)/2= 14
3. Check f(12).f(14) = 6.067•1.569 1.569
= 9.517 >0; x
12 14 16
-2.269
the root lies between 14 and 16.
4. Set xl = 14 and xu=16, thus the new root
xr=(14+ 16)/2= 15 f(x)
(f(12).f(14)>0): xl = 14
5. Check f(14).f(15) = 1.569•-0.425= -0.666
<0;
the root lies bet. 14 and 15.
6. Set xl = 14 and xu=15, thus the new root
xr=(14+ 15)/2= 14.5 1.569
15
and so on…... 14 16
x
-0.425 -2.269
Bisection method: Example

• In the previous example, if the stopping criterion is et =


0.5%; what is the root?

Iter. Xl Xu Xr ea% et%


1 12 16 14 5.279 --
2 14 16 15 6.667 1.487
3 14 15 14.5 3.448 1.896
4 14.5 15 14.75 1.695 1.204
5 14.75 15 14.875 0.84 0.641
6 14.74 14.875 14.813 0.422 0.291
Bisection method
Start
Flow Chart –Bisection
Input: xl , xu , es, maxi

False f(xl). f(xu)<0

i=0
ea=1.1es

while False
ea> es &
i <maxi
Print: xr , f(xr ) ,ea ,
i
xu  x r
xr 
2
A i  i 1 Stop

B
A B

xu+xl =0

True xu  x l
ea  100%
xu  x l

Test=f(xl). f(xr)

Test True
ea=0.0
=0

True
Test
xu=xr
<0
False
xl=xr
Bracketing Methods (Bisection method)

Bisection Method
Advantages:
1. Simple
xl  xu
2. Estimate of maximum error: E max 
2
1
3. Convergence guaranteed E imax  0.5 E imax

Disadvantages:
1. Slow
2. Requires two good initial estimates which define
an interval around root:
 use graph of function,
 incremental search, or
 trial & error
How Many Iterations will It Take?

• Length of the first Interval Lo=b-a


• After 1 iteration L1=Lo/2
• After 2 iterations L2=Lo/4

• After k iterations Lk=Lo/2k

Lk
e a  100% ea  es
x
• If the absolute magnitude of the error is
es  x
 104
100%
and Lo=2, how many iterations will you have to do to get
the required accuracy in the solution?

4 2
10  k  2k  2 104  k  14.3  15
2
Bracketing Methods
2. False-position Method

• The bisection method divides the interval xl to xu


in half not accounting for the magnitudes of f(xl)
and f(xu). For example if f(xl) is closer to zero
than f(xu), then it is more likely that the root will
be closer to f(xl).
• False position method is an alternative approach
where f(xl) and f(xu) are joined by a straight line;
the intersection of which with the x-axis
represents and improved estimate of the root.
2. False-position Method

• False position method is


an alternative approach
where f(xl) and f(xu) are
joined by a straight line;
the intersection of which
with the x-axis
represents and improved
estimate of the root.
False-position Method -Procedure
f(x)

f(xu)

xl xr xu
x
f(xl) f(xr)

f ( xl ) f ( xu )

xr  xl xr  xu
f ( xu )( xl  xu )
xr  xu 
f ( xl )  f ( xu )
False-position Method -Procedure
Step 1: Choose lower xl and upper xu guesses for
the root such that: f(xl).f(xu)<0
Step 2: The root estimate is:
f ( xu )( xl  xu )
x r  xu 
f ( xl )  f ( xu )

Step 3: Subdivide the interval according to:


– If (f(xl).f(xr)<0) the root lies in the lower subinterval; xu =
xr and go to step 2.
– If (f(xl).f(xr)>0) the root lies in the upper subinterval; xl =
xr and go to step 2.
– If (f(xl).f(xr)=0) the root is xr and stop
Bracketing Methods (False-position Method)

False-position Method
f(x) f(x)
f (x u )(x1  x u )
xr  xu 
f (x1 )  f (x u )
(xr)
f(xu) f(xu)
f(x1) f(xr) > 0
(x1) x1 = x r (x1)
(xu) x (xu)
f(xr) f(x1)
f(x1) f(xr)
False position method: Example
c
mg  t
• The parachutist velocity is v (1  e m
)
c
• What is the drag coefficient c needed to reach a velocity of
40 m/s if m =68.1 kg, t =10 s, g= 9.8 m/s2

f(c) c
mg  t
f (c)  (1  e )  v
m
c
667.38
f (c)  (1  e 0.146843c )  40
c
c
False position method: Example
1. Assume xl = 12 and xu=16 f(x)

f(xl)= 6.067 and f(xu)= -2.269 6.067


2. The root: xr=14.9113
f(12) . f(14.9113) = -1.5426 < 0;
14.91
x
12 16
3. The root lies bet. 12 and 14.9113.
-2.269
4. Assume xl = 12 and xu=14.9113, f(xl)=6.067 and
f(xu)=-0.2543
5. The new root xr= 14.7942
6. This has an approximate error of 0.79%
False position method: Example
Start Flow Chart
False Position
Input: xl , xu , es, maxi

False f(xl). f(xu)<0

i=0
ea=1.1es

while False
ea> es &
i <maxi
Print: xr , f(xr ) ,ea ,
i
f (x u )(x l  x u )
x r  xu 
f (x l )  f (x u )
i  i 1 Stop

A
B
A B
i=1
or
xr=0

True x r  x r0
ea  100%
xr

Test=f(xl). f(xr)

Test True
ea=0.0
=0

True
Test
xu=xr
<0 xr0=xr
False
xl=xr
xr0=xr
• Why this method?
– Faster
– Always converges for a single root.

See Sec.5.3.1, Pitfalls of the False-Position Method


Note: Always check by substituting estimated root in the
original equation to determine whether f(xr) ≈ 0.
Bracketing Methods (False-position Method)

There are some cases in which the false position


method is very slow, and the bisection method gives
a faster solution.
False Position Method-Example 2
False Position Method - Example 2
Bracketing Methods (False-position Method)

Summary of False-Position Method:

Advantages:
1. Simple
2. Brackets the Root

Disadvantages:
1. Can be VERY slow
2. Like Bisection, need an initial interval around the
root.
Problem 5.4
Function:

a. Determine the roots graphically


b. Determine the first roots with bisection
c. Determine the first roots with false-position (regula-
falsi)
Use initial guesses of xl = -1 and xu = 0, and a
stopping criterion of 1%.
Problem 5.4
x
-1.50
f(x)
69.88
a. Graphical solution
-1.25 47.55
-1.00 29.00
-0.75 13.95 f(x)
-0.50 2.13 100.00
-0.25 -6.77
0.00 -13.00
0.25 -16.86 80.00
0.50 -18.63
0.75 -18.58 60.00
1.00 -17.00
1.25 -14.17
1.50 -10.38 40.00
1.75 -5.89
2.00 -1.00 20.00
2.25 4.02
2.50 8.88
2.75 13.30 0.00
f(x)
-1.50 -1.00 -0.50 0.00 0.50 1.00 1.50 2.00 2.50 3.00 3.50 4.00 4.50 5.00 5.50 6.00
3.00 17.00
3.25 19.70 -20.00
3.50 21.13
3.75 20.98
-40.00
4.00 19.00
4.25 14.89
4.50 8.38 -60.00
4.75 -0.83
5.00 -13.00
-80.00
5.25 -28.42
5.50 -47.38
5.75 -70.14 -100.00
6.00 -97.00
Problem 5.4

b. Bisection method

c. Regula-falsi method
Roots of Polynomials: Using Software Packages

MS Excel:Goal seek
f(x)=x-cos x
MS Excel: Solver
u(x,y)= x2+xy-10 =0
v(x,y)=y+3xy2-57=0

You might also like