You are on page 1of 13

Root finding Methods

Topics
▶ Zeros of nonlinear scalar equations
▶ Bisection algorithm
▶ Fixed point iteration
▶ Newton and other higher order methods
Lecture 4
Zeros of nonlinear scalar equations and Bisection Method

Course Website
https://sites.google.com/view/kporwal/teaching/mtl107
The problem

The problem
Want to find solutions of the scalar nonlinear equation

f (x) = 0 with continuous f : [a, b] ⊂ R 7→ R


We denote a solution of the equation (called root, or zero) by
x∗
In contrast to scalar linear equations
b
ax − b = 0 =⇒ a̸=0 x∗ =
a
nonlinear equations have an undetermined number of zeros.
We denote the set of all continuous functions on the interval [a,b]. So,
above, we require f ∈ C [a, b].
Examples

1. f(x) = x-1 on [a,b] = [0,2].


2. f(x) = sin(x)
On [a,b] = [ π2 , 3π ∗
2 ] there is one root x = π.
On [a, b] = [0, 4π] there are five roots, cf. Fig. on next page.
3. f(x) = x 3 − 20x 2 + 2552 on [0,20].
4. f(x) = 10 cosh( x4 ) on −∞ < x < ∞ .
cosh(t) = 21 (e t + e −t )
merical Methods for Computational Science and Engineering
The problem

Examples(cont.)
xamples (cont.)

SE, Lecture 3, Sept 26, 2013

Figure 1: Examples of Roots


Iterative method for finding roots

▶ Roots that can be expressed analytically are known for very


few special nonlinear functions.
▶ Even for polynomials this holds for very low orders.
▶ We have to resort to iterative methods:
Starting with an initial guess/iterate x0 we generate a
sequence of iterates x1 , x2 , ..... that (hopefully ) converges to
a root of the function.
▶ A rough knowledge of the root’s location is required.
▶ (Plots)
▶ Could probe the function and try to find two arguments a,b
s.t. f (a)f (b) < 0.
intermediate Value Theorem =⇒ ∃ x ∗ in interval (a, b).
Stopping an iterative procedure
In general, an iterative procedure does not find the solution
but gets (arbitrary) close.
Varous criteria are used to check (almost) convergence: We
terminate iterating after n iterations if:

|xn − xn−1 | < atol, and/or

|xn − xn−1 | < rtol|xn |, and/or


|f (xn )| < ftol,
where atol, rtol and ftol are user-defined constants.
Usually (but not always) the relative criterion is more robust
than the absolute one.
A combination of the first two is

|xn − xn−1 | < tol(1 + |xn |)


Desirable algorithm properties

Iterative methods: starting with initial iterate (guess) x0 , generate


sequence of iterates x1 , x2 , ....xk , ..., that hopefully converge to a
root x ∗ .
▶ Efficient: requires a small number of function evaluations.
▶ Robust: fails rarely, if ever. Announces failure if it does fail.
▶ Requires a minimal amount of additional information such as
the derivative of f.
▶ Requires f to satisfy only minimal smoothness properties.
▶ Generalizes easily and naturally to many equations in many
unknowns.
Bisection

▶ Method for finding a root of scalar equation f(x) = 0 in an


interval [a,b].
▶ Assumption: f (a)f (b) < 0.
▶ Since f is continuous there must be a zero x ∗ ∈ [a, b].
▶ Compute midpoint m of the interval and check the values
f (m).
▶ Depending on the sign of f (m), we can decide if x ∗ ∈ [a, m]
or x ∗ ∈ [m, b]
(of course, if f(m) = 0 then we are done.)
▶ Repeat
Code bisection I

1 function [x,fx] = bisect(f,a,b,tol)


2 fa=f(a); if fa==0,x=a;fx=fa;return;end
3 fb=f(b); if fb==0,x=b;fx=fb;return;end
4
5 if fa*fb > 0, error('f(a)*f(b) > 0'), end
6 x = (a+b)/2; fx = f(x);
7 if nargin<4, tol=0; end
8
9 while (b-a>tol) & ((a < x) & (x < b)),
10 if fx == 0, break, end
11 if fa*fx < 0,
12 b = x; fb = fx;
13 else
14 a = x; fa = fx;
15 end
16 x = (a+b)/2; fx = f(x);
17 end
Bisection: Convergence
b−a
Error estimate: |xk − s| ≤ 2k+1
with xk = midpoint of the k-th
interval.
Bisection: Number of Steps
Number of steps for Desired accuracy: If we want the error to
satisfy |xk − x ∗ | ≤ ϵ, then it suffices to have (b − a)/2k ≤ ϵ, so that
b−a b−a
   
k > log2 = log /log 2.
ϵ ϵ
Properties of bisection

▶ Simple
▶ Safe, robust (even foolproof)
▶ Requires f to be only continuous
▶ Slow
▶ Can converge to wrong root
▶ Cant be generalize to the systems

You might also like