Professional Documents
Culture Documents
2 - Finding Roots of Nonlinear Equations
2 - Finding Roots of Nonlinear Equations
2 - Finding Roots of Nonlinear Equations
Numerical Methods
These presentations are prepared by Dr. Cüneyt Sert and modified by Dr. Sezer Özerinç.
They cannot be used and/or modified without the permission of the authors.
Fall 2015
Ankara, Turkey
csert@metu.edu.tr ozerinc@metu.edu.tr
Finding Roots of Equations
f(x)
f(x) is given
x f(x r) = 0 xr = ?
• Bracketing Methods: Need two initial estimates that bracket the root. Always
converge. (Chapter 5)
• Bisection Method
• False-Position Method
• Open Methods: Need one or two initial estimates. May diverge. (Chapter 6)
• Secant Method
General Idea of Bracketing Methods (Chapter 5)
f(x) f(x) If f(x L)*f(x U) < 0
xL xL There are odd number of
xU x xU x
roots.
f(x) f(x)
If (x L)*f(x U) > 0
There are even number
xL xU x xL xU x of roots (or no root).
xU xL xU i) multiple roots
xL x x ii) discontinuities
Bracketing Methods: Bisection Method
f(x) 1) Start with two initial guesses:
Iteration
xL xU x f(x) |e t| % |e a| %
number
6
Bisection Method (continued)
Figure from Chapra and Canale, 2010
• True error does not drop
monotonically but oscillates.
f ( xU )( xL xU )
x xU
f(x) f ( xL ) f ( xU )
xL 4) Determine the interval which contains the
x xU x root
if f(x L)*f(x) < 0 root is between xL and x
else root is between x and xU
f(x) 5) Estimate a new root in this new interval
xL
6) Iterate and compute the error after each
x xU x
iteration.
Iteration
xL xU x f(x) |e t| % |e a| %
no.
6
False-Position Method (continued)
Figure from Chapra and Canale, 2010
xr ε t (%)
Iter.
False- False-
Bisection Bisection
Position Position
DO iter = 1, maxiter
x = (xL + xU) / 2 ! Only this line changes for the False-Position Method
fx = FUNC (x) ! Call a subroutine to calculate the function.
error = (xU - xL) / (xU + xL)*100 ! See page 121
WRITE(*,*) iter, x, fx, error
IF (error < tol) STOP
• Remember:
Bracketing methods
always converge.
1) Start with an initial guess x0 Figure from Chapra and Canale, 2010
i xi x i+1=g(xi) |e t| % i xi x i+1=g(x i) |e t| %
0 3 1 70 0 3 3.5 5.53
1 1
2 2
3 3
• Selection of g(x) is important. Note that we did not use the trivial one, x = sqrt(11).
• If the method converges, convergence is linear. That is, the relative error at each iteration is
roughly proportional to the half of the previous error. This is easier to see for et.
Simple One-Point Iteration (continued)
Monotone Spiral
• Graphical convergence convergence
illustration of the
stability criterion
|g(x)| < 1.
• Exercise: Show
that Example 4(a)
violates the
convergence criteria
Monotone Spiral
|g(x)| < 1. divergence divergence
iteration x f(x) |e t| %
0 3 -2 9.55
f ( xi 1 ) f ( xi ) f ( xi )( xi 1 xi )
0 f ( xi ) f ( xi )( xi 1 xi )
f ( xi )
xi 1 xi
f ( xi )
Error Analysis of NR Method from Taylor Series
1st Order Taylor Series of f(xi+1) around xi:
f ( xi 1 ) f ( xi ) f ( xi )( xi 1 xi ) . Assume that xi+1 is the root:
0 = f ( xi ) f ( xi )( xi 1 xi ) (Equation 1)
1st Order Taylor Series of f(xr) around xi where xr is the exact root.
f (x )
f ( xr ) 0 f ( xi ) f ( xi )( xr xi ) ( xr xi ) 2 (Equation 2)
2!
Subtract Equation 1 from Equation 2:
f (x ) Et ,i ( xr – xi )
0 f ( xi )( xr xi 1 ) ( xr xi ) 2
2 Et ,i 1 ( xr – xi 1 )
f (x ) 2
0 f ( xi ) Et ,i 1 Et ,i where xi x xr
2
For convergence xi xr , therefore x xr
f ( xr )
Et ,i 1 Et2,i
r)
2 f (x
Error Analysis of NR Method from Taylor Series (continued)
f ( xr )
Et ,i 1 Et2,i
r)
2 f (x
• The analysis shows quadratic convergence.
• Therefore, the error at each iteration is roughly proportional to the
square of the previous error.
• See Example 6.4 in Chapra and Canale for a demonstration.
Iteration x f(x) |ε t| %
-1 2 -7 -311
0 3 -2 -160
Example 11: There is no guarantee for the secant method to converge. Try to
calculate the root of ln(x) starting with (a) x-1 = 0.5 and x0 = 4, (b) x-1 = 0.5 and
x0 = 5. Part (a) converges, but part (b) does not.
Secant Method vs. False-Position Method
Secant Method False-Position Method
f ( xi )( xi 1 xi ) f ( xU )( xL xU )
xi 1 xi x xU
f ( xi 1 ) f ( xi ) f ( xL ) f ( xU )
• f’(x) also goes to zero at a multiple root. This creates the risk of division
by zero for the Secant and the NR. f(x) will reach zero faster than f’(x),
therefore use a zero-check for f(x), and stop before f’(x) becomes zero.
i) If you know the multiplicity of the root, the NR can be modified as:
ii) Define a new function u(x) = f(x) / f’(x) and solve for the roots of u(x)
instead of f(x). It can be shown that u(x) has the same roots as f(x).
u( xi ) f ( xi ) f ( xi ) f’’(x) needs to
xi 1 xi
u ( xi ) [ f ( xi )]2 f ( xi ) f ( xi ) be known.
Graphical Visual - - -
False- Slow/
Bracketing 2 Always
position medium
One- May
Open 1 Slow
Point diverge
Newton- May
Open 1 Fast
Raphson diverge
Medium May
Secant Open 2
/fast diverge Figure from Chapra and Canale, 2010
Solving Systems of Nonlinear Equations
y
Simple One-Point Iteration Method
Solve the system of equations: x y 4 ex y 1
2 2
x
Put the functions into the form x=g1(x,y), y=g2(x,y)
x g1 ( y ) ln(1 y ) y g2 ( x) 4 x 2
Select initial guesses such as x0 = 0.0 and y0 = 0.0. Use g1 and g2 for
calculating the next guesses.
x1= g1(y0) = 0 y1= g2(x1) = -2
Exercise: Solve the same system but rearrange the equations as: x = ln(1 – y),
y = (4 – x2) / y and start from x0 = 1, y0 = –1.7. Remember, this method may diverge.
Solving Systems of Nonlinear Equations: Newton-Raphson
Consider the following general form of a two-equation system.
u ( x, y ) 0
v ( x, y ) 0
Write 1st order Taylor Series Expansion (TSE) for these equations.
ui ui
ui 1 ui ( xi 1 xi ) ( yi 1 yi )
x y
vi vi
vi 1 vi ( xi 1 xi ) ( yi 1 yi )
x y
To find the solution set u i+1 = 0 and v i+1 = 0. Rearrange
ui ui ui ui
xi 1 yi 1 ui xi yi
x y x y
vi vi vi vi
xi 1 yi 1 vi xi yi
x y x y
Solving Systems of Nonlinear Equations: Newton-Raphson (cont.)
Write in matrix form:
ui ui
ui ui ui xi yi
x xi 1 x y
y The 2 x 2 coefficient
matrix is called the
vi vi Jacobian matrix.
x y v v
y i 1
vi i
xi i
yi
x y
The method can be generalized for n simultaneous equations.
Solve for x i+1 ,y i+1 using Cramer’s rule (ME 210), and iterate.
vi ui ui vi
ui vi vi ui
y y x x
xi 1 xi , yi 1 yi
ui vi ui vi ui vi ui vi
x y y x x y y x
u x2 y2 4 0 v ex y 1 0
u u v v
2x , 2y , e ,
x
1 |J| 2x - 2ye x
x y x y
ui 2 yi vi 2 xvi e xi ui
xi 1 xi , y i 1 yi
|J | |J |
i x y u v J
0 1 1 -2 2.718282 -3.436564
1 -1.163953 3.335387 8.479595 2.647636 -4.410851
2
3
The solution is converging to the root in the 2nd quadrant, x -1.8, y 0.8.
Exercises: a) Can you start with x0 = 0 and y0 = 0 ? b) Try to find initial guesses that will
converge to the solution in the 4th quadrant.