Roots of Equations - Civil and Environmental Engineering | SIU

ROOTS OF EQUATIONS
ENGR 351
Numerical Methods for Engineers
Southern Illinois University Carbondale
College of Engineering
Dr. L.R. Chevalier
Dr. B.A. DeVantier
Copyright © 2003 by Lizette R. Chevalier and Bruce DeVantier
Permission is granted to students at Southern Illinois University at Carbondale
to make one copy of this material for use in the class ENGR 351, Numerical
Methods for Engineers. No other permission is granted.
All other rights are reserved. No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, photocopying, recording, or otherwise, without
the prior written permission of the copyright owner.
Applied Problem
The concentration of pollutant bacteria C in a lake
decreases according to:
C  80e2 t  20e0.1t
Determine the time required for the bacteria to be
reduced to 10 ppm.
Applied Problem
You buy a $20 K piece of equipment for nothing down
and $5K per year for 5 years. What interest rate are you
paying? The formula relating present worth (P), annual
payments (A), number of years (n) and the interest rate
(i) is:
i1  i
A P
n
1  i  1
n
Quadratic Formula
 b  b 2  4 ac
x
2a
f ( x)  ax 2  bx  c  0
This equation gives us the roots of the algebraic function
f(x)
i.e. the value of x that makes f(x) = 0
How can we solve for f(x) = e-x - x?
Roots of Equations
 Plot the function and determine where
it crosses the x-axis
 Lacks precision
 Trial and error
f(x)
10
8
6
4
2
0
-2
-2
-1
0
x
1
2
Overview of Methods
 Bracketing methods



Graphing method
Bisection method
False position
 Open methods



One point iteration
Newton-Raphson
Secant method
Specific Study Objectives
 Understand the graphical interpretation
of a root
 Know the graphical interpretation of the
false-position method (regula falsi
method) and why it is usually superior to
the bisection method
 Understand the difference between
bracketing and open methods for root
location
Specific Study Objectives
 Understand the concepts of convergence
and divergence.
 Know why bracketing methods always
converge, whereas open methods may
sometimes diverge
 Realize that convergence of open
methods is more likely if the initial guess
is close to the true root
Specific Study Objectives
 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
 Solve two nonlinear simultaneous equations
Bracketing Methods
 Graphical
 Bisection method
 False position method (regula falsi
method)
Graphical
(limited practical value)
f(x)
f(x)
x
consider lower
and upper bound
same sign,
no roots or
even # of roots
x
f(x)
f(x)
opposite sign,
odd # of roots
x
x
Bisection Method
 Takes advantage of sign changing
 f(xl)f(xu) < 0 where the subscripts refer
to lower and upper bounds
 There is at least one real root
f(x)
f(x)
x
f(x)
x
x
Algorithm
 Choose xu and xl. Verify sign change
f(xl)f(xu) < 0
 Estimate root
 xr = (xl + xu) / 2
 Determine if the estimate is in the lower or upper
subinterval
 f(xl)f(xr) < 0
then xu = xr RETURN
 f(xl)f(xr) >0
then xl = xr RETURN
 f(xl)f(xr) =0
then root equals xr - COMPLETE

Algorithm
 Choose xu and xl. Verify sign change
f(xl)f(xu) < 0
 Estimate root
 xr = (xl + xu) / 2
 Determine if the estimate is in the lower or upper
subinterval
 f(xl)f(xr) < 0
then xu = xr RETURN

Algorithm
 Choose xu and xl. Verify sign change
f(xl)f(xu) < 0
 Estimate root
 xr = (xl + xu) / 2
 Determine if the estimate is in the lower or upper
subinterval


f(xl)f(xr) >0
then xl = xr RETURN
Algorithm
 Choose xu and xl. Verify sign change
f(xl)f(xu) < 0
 Estimate root
 xr = (xl + xu) / 2
 Determine if the estimate is in the lower or upper
subinterval
 f(xl)f(xr) < 0
then xu = xr RETURN
 f(xl)f(xr) >0
then xl = xr RETURN
 f(xl)f(xr) =0
then root equals xr - COMPLETE

Error
present approx.  previous approx
a 
 100
present
Let’s consider an example problem:
Example
Use the bisection method to determine the root
•f(x) = e-x - x
•xl = -1 xu = 1
10
8
f(x)
6
3.7 1 8282
4
2
-0.6321 2
0
-2
-2
-1
0
x
1
2
False Position Method
 “Brute Force” of bisection method is
inefficient
 Join points by a straight line
 Improves the estimate
 Replacing the curve by a straight line
gives the “false position”
next
estimate,
xr
f(xu)
xl
f(xl)
xu
Based on
similar
triangles
f  xl 
f  xu 

xr  xl xr  xu
f  xu  xl  xu 
xr  xu 
f  xl   f  xu 
Example
Determine the root of the following equation
using the false position method starting with
an initial estimate of xl=4.55 and xu=4.65
98
30
20
10
f(x)
f(x) =
x3 -
0
-1 0
-20
-30
-40
4
4.5
x
5
Pitfalls of False Position
Method
f(x)
f(x)=x1 0-1
30
25
20
15
10
5
0
-5
0
0.5
1
x
1 .5
Open Methods
 Newton-Raphson method
 Secant method
 Multiple roots
 In the previous bracketing methods,
the root is located within an interval
prescribed by an upper and lower
boundary
Open Methods cont.
 Such methods are said to be convergent

solution moves closer to the root as the
computation progresses
 Open method


single starting value
two starting values that do not necessarily
bracket the root
 These solutions may diverge

solution moves farther from the root as the
computation progresses
f(x)
The tangent
gives next
estimate.
f(xi+1 )
xi
xi+1
f(xi)
x
Solution can “overshoot”
the root and potentially
diverge
f(x)
x2
x1
x0
x
Newton Raphson
tangent
f(xi)
dy
tangent 
 f'
dx
f  xi   0
f '  xi  
xi  xi1
xi+1
xi
rearrange
f  xi 
xi1  xi 
f '  xi 
Newton Raphson
Pitfalls
f(x)
(x)
Newton Raphson
Pitfalls
f(x)
solution diverges
(x)
Example
1 00
80
60
f(x)
Use the Newton
Raphson method
to determine the
root of
f(x) = x2 - 11
using an initial
guess of xi = 3
40
20
0
-20
0
2
4
6
x
8
10
Solution
1 00
80
60
f(x)
 f(x) = x2 - 11
 f '(x) = 2x
 initial guess xi = 3
 f(3) = -2
 f '(3) = 6
40
20
0
-20
0
2
4
6
x
8
10
Solution
f  xi 
 2  3  1  3.33
xi 1  xi 
 3
f '  xi 
6
3
a 
3.33  3
 100  10%
3.33
In this method, we begin to use a numbering system:
x0 = 3
x1 = 3.33
Continue to determine x2, x3 etc.
Solution

f  x1 
0.11
x2  x1 
 3.33 
 3.315
f '  x1 
6.66
3.315 3.33
a 
 100  0.55%
3.315

f  x2 
 0.0108
x3  x2 
 3.315
 3.317
f '  x2 
6.63
3.317  3.315
a 
100  0.05%
3.317
Secant method
Approximate derivative using a finite divided difference
f  xi 1   f  xi 
f '  x 
xi 1  xi
What is this? HINT: dy / dx = Dy / Dx
Substitute this into the formula for Newton Raphson
f  xi 
xi1  xi 
f '  xi 
f  xi  xi 1  xi 
xi1  xi 
f  xi 1   f  xi 
Substitute finite
difference
approximation for the
first derivative into this
equation for Newton
Raphson
Secant
method
Secant method
f  xi  xi1  xi 
xi1  xi 
f  xi1   f  xi 
 Requires two initial estimates
 f(x) is not required to change signs,
therefore this is not a bracketing method
Secant method
Select two estimates.
Note: f(xi) and f(xi+1)
are not opposite
signs.
{
f(x)
x
initial estimates
Secant method
f(x)
{
slope
between
two
estimates
x
initial estimates
Secant method
f(x)
{
slope
between
two
estimates
new estimate
x
initial estimates
Example
Determine the root of f(x) = e-x - x using the
secant method. Use the starting points x0 = 0
and x1 = 1.0.
10
8
f(x)
6
4
2
0
-2
-2
-1
0
x
1
2
Solution
 Choose two starting points


x0 = 0 f(x0 ) =1
x1 = 1.0 f(x1) = -0.632
 Calculate x2

x2 = 1 - (-0.632)(0 - 1)/(1+0.632) = 0.6127
Solution
 Second iteration
x1 = 1.0 f(x1) = -0.632
 x2 = 0.613 f(x2) = -0.0708
 NOTE: f(x) are the same sign. OK here.
 x3 = 0.613 - (-0.0708)(1-0.613)/(0.632+0.0708)
 x3 = 0.564
f(x3) = 0.0052
 a = abs[(0.564-0.613)/(0.564)] x 100 =
8.23%

Solution
 Third iteration



x2 = 0.613 f(x2) = -0.0708
x3 = 0.564 f(x3) = 0.0052
x4 = 0.567 f(x4) = -0.00004
 a = 0.59%
t = 0.0048%
 Know the difference between these error
terms
Comparison of False Position and
Secant Method
2
f(x)
f(x)
2
1
x
1
new est.
x
new est.
FALSE POSITION
f(x)
SECANT METHOD
f(x)
1
x
1
- select first
estimate
x
FALSE POSITION
f(x)
2
SECANT METHOD
2
f(x)
1
1
- select second estimate
x
x
FALSE POSITION
f(x)
2
SECANT METHOD
2
f(x)
1
1
x
Note the sign
of f(x) in each method.
False position must
bracket the root.
x
FALSE POSITION
f(x)
2
SECANT METHOD
2
f(x)
1
x
1
- Connect the
two points
with a line
x
FALSE POSITION
f(x)
2
SECANT METHOD
2
f(x)
1
x
1
new est.
The new estimate
is selected from the
intersection with the
x-axis
x
new est.
Multiple Roots
 Corresponds to a point
where a function is
tangential to the x-axis
 i.e. double root



5x2
f(x) = + 7x -3
f(x) = (x-3)(x-1)(x-1)
i.e. triple root
f(x) = (x-3)(x-1)3
8
6
f(x)

x3
10
4
m ultiple root
2
0
-2
-4
0
1
2
x
3
4
Difficulties
 Bracketing methods won’t work
 Limited to methods that may diverge
10
8
f(x)
6
4
m ultiple root
2
0
-2
-4
0
1
2
x
3
4
 f(x) = 0 at root
 f '(x) = 0 at root
 Hence, zero in
10
8
6
f(x)
the denominator
for NewtonRaphson and
Secant Methods
 Write a “DO
LOOP” to check
is f(x) = 0 before
continuing
4
m ultiple root
2
0
-2
-4
0
1
2
x
3
4
Multiple Roots
 f '  xi   f  xi  f ' '  xi 
2
10
8
6
f(x)
xi  1  xi 
f  xi  f '  xi 
4
m ultiple root
2
0
-2
-4
0
1
2
x
3
4
Systems of Non-Linear
Equations
 We will later consider systems of linear
equations


f(x) = a1x1 + a2x2+...... anxn - C = 0
where a1 , a2 .... an and C are constant
 Consider the following equations


y = -x2 + x + 0.5
y + 5xy = x3
 Solve for x and y
Systems of Non-Linear Equations
cont.
 Set the equations equal to zero


y = -x2 + x + 0.5
y + 5xy = x3
 u(x,y) = -x2 + x + 0.5 - y = 0
 v(x,y) = y + 5xy - x3 = 0
 The solution would be the values of x
and y that would make the functions u
and v equal to zero
Recall the Taylor Series
f ' '  xi  2 f ' ' '  xi  3
f  x i  1   f  x i   f '  x i h 
h 
h
2!
3!
f n  xi  n
. . . . . .
h  Rn
n!
where h  step size  xi  1  xi

Write a first order Taylor
series with respect to u and v
ui
ui
ui  1  ui 
 xi  1  xi    yi  1  y i 
x
y
vi
v i
vi  1  vi 
 xi  1  xi    yi  1  y i 
x
y
The root estimate corresponds to the point where
ui+1 = vi+1 = 0
Therefore
u
vi
 vi
ui
y
y
xi  1  xi 
ui vi ui vi

x  y  y x
u
v i
 vi
ui
y
y
y i  1  yi 
ui vi ui vi

x y  y  x
This is a 2 equation version of Newton-Raphson
Therefore
u
vi
 vi
ui
y
y
xi  1  xi 
ui vi ui vi

x  y  y x
u
v i
 vi
ui
y
y
y i  1  yi 
ui vi ui vi

x y  y  x
THE DENOMINATOR
OF EACH OF THESE
EQUATIONS IS
FORMALLY
REFER RED TO
AS THE DETERMINANT
OF THE
JACOBIAN
This is a 2 equation version of Newton-Raphson
Example
 Determine the roots of the following
nonlinear simultaneous equations


y = -x2 + x + 0.5
y + 5xy = x3
 Use and initial estimate of x=0, y=1
Solution
i
1
2
3
4
5
6
7
8
9
x
0
-0.083
-0.1 90
-0.207
-0.203
-0.203
-0.203
-0.203
-0.203
-0.203
y
1
0.41 7
0.375
0.469
0.497
0.491
0.492
0.492
0.492
0.492
u
-0.5
0.0828
0.1 1 79
0.022
-0.005
0.0004
0.0000
0.0000
0.0000
0.0000
v
1
0.244
0.026
-0.008
0.001
0.000
0.000
0.000
0.000
0.000
dvdx
5
2.063
1 .768
2.21 7
2.360
2.332
2.334
2.334
2.334
2.334
dudx
1
1 .1 67
1 .380
1 .41 4
1 .406
1 .407
1 .407
1 .407
1 .407
1 .407
dvdy
1
0.583
0.051
-0.036
-0.01 6
-0.01 7
-0.01 7
-0.01 7
-0.01 7
-0.01 7
dudy
-1
-1 .000
-1 .000
-1 .000
-1 .000
-1 .000
-1 .000
-1 .000
-1 .000
-1 .000
J
6
2.743
1 .839
2.1 66
2.338
2.308
2.31 0
2.31 0
2.31 0
2.31 0
See file nonlinear simultaneous.xls
Applied Problem
The concentration of pollutant bacteria C in a lake
decreases according to:
C  80e2 t  20e0.1t
Determine the time required for the bacteria to be
reduced to 10 using Newton-Raphson method.
Applied Problem
You buy a $20 K piece of equipment for nothing down
and $5K per year for 5 years. What interest rate are you
paying? The formula relating present worth (P), annual
payments (A), number of years (n) and the interest rate
(i) is:
i1  i
A P
1  i n  1
n
Use the bisection method
Previous Quiz
Graphically illustrate the Newton Raphson Method and
bi-section method for finding the roots of an equation on
graphs provided. Only show two iterations. Be sure
to select initial guesses which avoid pitfalls (i.e. zero
slope).
Previous Quiz
Given the Taylor series approximation, describe the
detail given by a) zero order approximation; b) first
order approximation; c) second order approximation.
f ' '  xi  2 f ' ' '  xi  3
f  x i  1   f  x i   f '  x i h 
h 
h
2!
3!
f n  xi  n
. . . . . .
h  Rn
n!
where h  step size  xi  1  xi

Previous Exam Question
Given the equation:
f(x) = x4 - 3x2 + 6x -2 = 0
a) Indicate on the graph an initial estimate for the Newton
Raphson Method where
- the solution will diverge
- a reasonable choice
b) Solve to three significant figures