Sunteți pe pagina 1din 28

Numerical Methods with Applications (MEC500)

Chapter 02

Roots of equations Bracketing methods

Dr Baljit Singh
Faculty of Mechanical Engineering
Universiti Teknologi MARA (UiTM)
Office: T1-A18-1C

Adapted from : Ramlan Kasiran


Ice breaker
An engineering problem

A car is accelerating at 10 m/s2 from an initial velocity of 25 m/s.

Derive the equation that would let you find the time the car takes to
cover 200 m distance?

2
Solution..
Given data;

u = 25 m/s, a=10 m/s2, s = 200 m.

s = ut + 0.5at2
200 = 25t + (0.5)(10t2)
5t2 + 25t -200 = 0
f(t) = 5t2 + 25t -200

Solving f(t) = 0 gives ,


t1 = 4.3 s & t2 = -9.3s

Since t must be > 0, Solution is t = 4.3 s.

Solution of f(t) = 0 is the root (or zero) of the equation.

3
Learning outcome
Understanding what roots problems are and where they occur in
engineering and science.

Knowing how to determine a root graphically.

Understanding the incremental search method and its shortcomings.

Knowing how to solve a roots problem with the bisection method.

Knowing how to estimate the error of bisection and why it differs from
error estimates for other types of root location algorithms.

Understanding false position and how it differs from bisection.

4
Roots of equations - Introduction
Why NM?
b b 2 4ac
f(x) ax bx c 0
2
x
2a

But! ax 5 bx 4 cx 3 dx 2 ex f 0 x ?
sinx x 0 x ?
f(x) e - x x x ?
Many functions cannot be solved analytically!!!

Roots problems occur when some function f can be written in terms of


one or more dependent variables x, where the solutions to f(x)=0 yields
the solution to the problem.

These problems often occur when a design problem presents an implicit


equation for a required parameter.

ROOTS = value of x that make f(x)=0. (a.k.a ZERO of equation


OR x values when the graph crosses x-axis)

5
Roots of equations Why NM?
Recall the parachutists velocity:

v(t)
gm
c

1 e (c/m)t
Solution method:
V is an explicit variable can be solved analytically Graphical
Trial & error
Supposed, we want to find C NM
No way we can express C explicitly C = ???????
C is an implicit function (C on both side of equal sign)
Thus we need to re-express the equation as

f(c)
gm
c

1 e (c/m)t v y e -2x .Sin(3x 5)

The value of c that makes f (c) = 0 is, therefore, the root of the
equation
NM can be used to solve this implicit function!

A lot of engineering problems involved with implicit functions!!!


Only Numerical Method is available. 6
You have no other choice!
Numerical methods approaches

Nonlinear Equation
Solvers

1. Graphical 2. Bracketing 3. Open Methods

All Iterative Bisection


distinguish by the Newton Raphson
type of initial False Position
guesses! Secant
(Regula-Falsi)

NM process:
Find approximate solution by plotting graph and estimate the roots
(Find the point where the graph cross the x-axis)
Apply numerical method to determine more accurate solution.
Some stopping criterion is applied to decide when solution is
accurate enough

7
1. Graphical Method
A simple method for obtaining the rough estimate
of the root of the equation f(x)=0 observe where
it crosses the x-axis.

Graphs can also indicate where roots may be and


where some root-finding methods may fail.

In general, if xl = lower bound & xu = upper bound

f(xl) & f(xu) have same sign


no root or even number of roots
f(xl) & f(xu) have different sign
odd number of roots

Useful for initial guess for NM lack of precision!

Alternative method trial & error (guessing


repeatedly the value of x and evaluate whether
f(x) = 0) inefficient!

Combine these methods + computer NM 8


2. Bracketing method

Theorem
An equation f(x)=0, where f(x) is a real
continuous function, has at least one root
between xl and xu if f(xl) f(xu) < 0.

Bracketing methods are based on making two


initial guesses that bracket the root - that is,
are on either side of the root.

Brackets are formed by finding two guesses xl


and xu where the sign of the function changes;
that is, where f(xl ).f(xu ) < 0

Initial guesses are determined by incremental


search method.

The incremental search method tests the value


of the function at evenly spaced intervals and
finds brackets by identifying function sign
changes between neighbouring points.
9
Incremental search hazard
Used to locate all roots by observing function sign changes within an
interval.

Method: Evaluate function as small increment across the region of


interest. If function change sign there is a root within the increment.

Problems:
Increment length too small time consuming
Increment length too big miss closely paced roots & multiple roots.

Incremental search is not foolproof always find more information by


plotting graph and understand the physical problem from which the
equation originated.

10
Bisection methods
The bisection method is a
bracketing method in which the
interval is always divided in half.

If a function changes sign over


an interval, the function value at
the midpoint is evaluated.

The location of the root is then


determined as lying within the
subinterval where the sign
change occurs.

The absolute error is reduced by


a factor of 2 for each iteration.

Also called binary chopping,


interval halving, Bolzanos
method

11
Algorithm for Bisection method
THEOREM:
An equation f(x)=0, where f(x) is a real
continuous function, has at least one root
between xl and xu if f(xl) f(xu) < 0.

STEP 1: Choose initial guesses


Choose xl and xu as two guesses for the root
xl xu
such that f(xl) f(xu) < 0, or in other words, f(x)
changes sign between xl and xu.

STEP 2: Estimate the root


Estimate the root, xr of the equation f(x) = 0 as xl xr xu
the mid-point between xl and xu as LOWER UPPER
Sub Sub
Interval Interval

x x Interval
xr l u
2

12
Algorithm for Bisection method
STEP 3 : Evaluate f(xl).f(xr)
Evaluate f(xl).f(xr) to locate where root lies in
the subinterval

If f(xl).f(xr) < 0 : root is in lower subinterval;

Set xl = xl & xu = xr for next iteration xl xr xu

If f(xl).f(xr) > 0 : root is in upper


subinterval; xl xr xu
Set xl = xr & xu = xu for next iteration

If f(xl).f(xr) = 0 : the root is xr.

Stop the algorithm if this is true.

STEP 4: Find new estimate


Repeat STEP 2 & 3 until one of the following is
reached:
a s 13

f(xl).f(xr) = 0 (true root)


Termination criteria & error estimate
True error is unknown

Approximate percent relative error is


new
X - X old X new = root for present iteration
a r r 100% r
X new
r Xold
r = root from previous iteration

Stop iteration when a s , where s is the pre-specified stopping


criterion.

Remarks
Each succeeding iteration halves
0 the error. Thus, the relationship
E = absolute error
xof iteration
between error and number a
is
Ea
n
n
n = iteration number
2 x0 = zero iteration error =
xu - x l

Number of iteration, n, to obtain a particular absolute error can be


calculated based on initial guess
x 0 E = desired error
n log 2
a,d
E n = iteration number
a,d x0 = zero iteration error

14
Example: Root finding using graphical method
Estimate the root (i.e. c value) using graphical method


v gm 1e-(c/m)t
c

f(c) gm 1e-(c/m)t v
c

IF t=10, g=9.8 , v = 40 & m = 68.1

c f(c)
4 34.115
8 17.653
Root
12 6.067
16 -2.269
20 -8.401

From the graph, the root, c is between 12 & 16

15
Example: Root finding using Bisection Method
From the graph, the root, c is between 12 &
16
[Note: True root = 14.7802]

s = 0.5%.
xll xuu
Choose xl = 12 and xu = 16 [initial guesses]

First estimate:
xr = (12 + 16)/2 = 14 xll xr xuu
t = {(14.7802 14)/14.7802}x100% =
5.3%

Evaluate f(xl).f(xr)
f(xl).f(xr) = f(12).f(16) = 9.517 ,i.e. > 0
Root is in upper subinterval!
Set xl = xr & xu = xu for next iteration
xl = 14 & xu = 16 for next iteration

16
Example

Choose xl = 14 and xu = 16 xu
xl
Second estimate:
xr = (14 + 16)/2 = 15
t = {(14.7802 15)/14.7802}x100% = 1.5%
xl x
xrr xu

Evaluate f(xl).f(xr)
f(xl).f(xr) = f(14).f(15) = -0.666, i.e. < 0
Root is in lower subinterval!
Set xl = xl & xu = xr for next iteration
xl = 14 & xu = 15 for next iteration

17
Example
Choose xl = 14 and xu = 15
xl xu
Third estimate:
xr = (14 + 15)/2 = 14.5
t = {(14.7802 14.5)/14.7802}x100% = 1.9%
xl xr xu
Evaluate f(xl).f(xr)
f(xl).f(xr) = f(14).f(15) = ?????????

This procedure is repeated until the result is accurate enough to satisfy


your need!

So when to stop? In this example error estimate is based on true value but
in practice this is not possible!

SO stop When a s!

18
Example stopping criteria & error estimate
For the previous example, find the root when s = 0.5%

Approximate percent relative error is

new old
a X r - X r 100% X new
r = root for present iteration
X new X old
r = root from previous iteration
r

Thus from previous example, from 1 & 2 iterations;


Xr1 = 14 & Xr2 = 15
a = {(15 14)/15}x100% = 6.6667%
Calculate the error for all iterations.

19
Example stopping criteria & error estimate
In table form

The iteration stop after 6 iterations as a 0.422% (s < 0.5%)

Iteration 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 0.204
5 14.75 15 14.875 0.840 0.641
6 14.74 14.875 14.8125 0.422 0.219

Observe that a is always greater than t Can stop iteration with


confidence!!!!

20
Pros & cons
Pros
Easy
The bisection method is always convergent. Since the method brackets
the root, the method is guaranteed to converge.
As an iteration is conducted, the interval gets halved. So one can
guarantee the error in the solution of the equation.
Number of iterations required to attain an absolute error can be
computed a priori.

Cons
Slow convergent
If one of the initial guesses is close to the root, the convergence is slower
Multiple roots cannot find lower & upper guesses!
No account is taken of f(xl) and f(xu), if f(xl) is closer to zero, it is likely
that root is closer to xl .

21
False position method
(a.k.a. linear interpolation method)

22
False position method
The false position method is another bracketing method.

It determines the next guess not by splitting the bracket in half


but by connecting the endpoints with a straight line and
determining the location of the intercept of the straight line (xr).

The value of xr then replaces whichever of the two initial guesses yields a
function value with the same sign as f(xr).

If a real root is bounded by xl & xu,


approximate the solution by a linear
interpolation between xl & xu

Using similar triangle,


FALSE-POSITION FORMULA:

f(x u )(x l x u )
xr xu
f(x l ) f(x u )

23
Algorithm for False Position method
1. Choose a pair of values of xl and xu such that they always bracket the
root. (i.e. f(xl).f(xu) <0).

2. Estimate the root using

f(x u )(x l x u )
xr xu LOWER Sub UPPER Sub
f(x l ) f(x u ) Interval Interval
xl xr xu

3. Evaluate the following


IF f(xl).f(xr) < 0 root lies in lower sub interval
SET xl = xl & xr = xu for the next iteration
IF f(xl).f(xr) > 0 roots lies in upper subinterval
SET xr = xl & xu = xu for the next iteration
If f(xr)=0 you have found the root! So stop!

4. Repeat #2 & #3 until you reach to close enough. Apply same stopping
criterion

24
COMPARISON BISECTION Vs. FALSE POSITION

BISECTION FALSE POSITION


Iteratio Root True Root Appr True
n Estimate App Err Err Estimate Err Err

1 1.7000 - 15.00 2.0615 - -3.000

2 1.9500 12.85 2.50 2.0180 2 0.900

3 2.0750 6.02 -3.70 2.0053 0.6 0.250

4 2.0125 -3 -0.60 2.0015 0.2 0.071

5 1.9813 -1.5 0.90

6 1.9969 0.7 0.15

25
Advantages
Why this method?
Faster
Always converge for a single root

Disadvantages
One-sideness one bracketing point will tend
to stay fixed
can lead to poor convergence, especially
for functions with significant curvature.

Note: Always check by substituting estimated


root in the original equation to determine
whether f(xr) 0.
Bisection vs. False Position
Bisection does not take into account the
shape of the function (only use the sign of
f(x)).

False position does take into account the


shape of the function this can be good or
bad depending on the function!

Bad : f(x) x10 1

Fasle position is based on the premise


that:
If f(xl) is closer to zero than f(xu), then
the root is closer to xl than to xu.

In this case, the opposite is true! ..


Because
of the shape of the function.
I never teach my pupils. I only attempt to provide the conditions
in which they can learn Albert Einstein (1879 - 1955)

Next lecture: Open Method

End
Class dismissed!

28

S-ar putea să vă placă și