Second Term 05/061 Roots of Equations Bracketing Methods.

29
Second Term 05/06 1 Roots of Equations Bracketing Methods
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    238
  • download

    1

Transcript of Second Term 05/061 Roots of Equations Bracketing Methods.

Second Term 05/06 1

Roots of Equations

Bracketing Methods

Second Term 05/06 2

Root

We are given f(x), a function of x, and we want to find α such that

f(α) = 0

α is called the root of the equation f(x) = 0, or the zero of the function f(x)

Second Term 05/06 3

Example: Interest RateSuppose you want to buy an electronic appliance from a shop and you can either pay an amount of 12,000 or have a monthly payment of 1,065 for 12 months. What is the corresponding interest rate?

1)1(

)1(

n

n

x

xxPA

A is the monthly payment

P is the loan amount

x is the interest rate per period of time

n is the loan period

To find the yearly interest rate, x, you have to find the zero of

1)1(

)1(000,12065,1

1212

121212

x

xx

We know the payment formulae is:

Second Term 05/06 4

Finding Roots Graphically

• Not accurate

• However, graphical view can provide useful info about a function.– Multiple roots?– Continuous?– etc.

Second Term 05/06 5

The following root finding methods will be introduced:

A. Bracketing MethodsA.1. Bisection MethodA.2. Regula Falsi

B. Open MethodsB.1. Fixed Point IterationB.2. Newton Raphson's MethodB.3. Secant Method

Second Term 05/06 6

Bracketing Methods

By Mean Value Theorem,

we know that if a function f(x) is continuous in the interval [a, b] and f(a)f(b) < 0, then the equation f(x) = 0 has at least one real root in the interval (a, b).

Second Term 05/06 7

Usually• f(a)f(b) > 0 implies zero or even

number of roots – [figure (a) and (c)]

• f(a)f(b) < 0 implies odd number of roots– [figure (b) and (d)]

Second Term 05/06 8

Exceptional Cases

• Multiple roots– Roots that overlap at one

point.– e.g.: f(x) = (x-1)(x-1)(x-2) has

a multiple root at x=1.

• Functions that discontinue within the interval

Second Term 05/06 9

Algorithm for bracketing methods

Step 1: Choose two points xl and xu such that f(xl)f(xu) < 0

Step 2: Estimate the root xr (note: xl < xr < xu)

Step 3: Determine which subinterval the root lies:

if f(xl)f(xr) < 0 // the root lies in the lower subinterval

set xu to xr and goto step 2

if f(xl)f(xr) > 0 // the root lies in the upper subinterval

set xl to xr and goto step 2

if f(xl)f(xr) = 0

xr is the root

Second Term 05/06 10

How to select xr in step 2?

1. Bisection MethodGuess without considering the characteristics of

f(x) in (xl, xu)

2. False Position Method (Regula Falsi)Use "average slope" to predict the root

Second Term 05/06 11

A.1. Bisection Method

• Each guess reduce the search interval by half

2lu

r

xxx

Second Term 05/06 12

Bisection Method – Example

40)1(38.667

)( 146843.0 xex

xf

Find the root of f(x) = 0 with an approximated error below 0.5%. (True root: α=14.7802)

Second Term 05/06 13

Example (continue)

n xl xr xu f(xl) f(xr) f(xu) f(xl)f(xu) εa

0 12 16 6.067 -2.269

1 12 14 16 6.067 1.569 -2.269 > 0

2 14 15 16 1.569 -0.425 -2.269 < 0 6.667%

3 14 14.5 15 1.569 0.552 -0.425 > 0 3.448%

4 14.5 14.75 15 0.552 0.0590 -0.425 > 0 1.695%

5 14.75 14.875 15 0.0590 -0.184 -0.425 < 0 0.840%

6 14.75 14.8125 14.875 0.0590 -0.0629 -0.184 < 0 0.422%

%100newr

oldr

newr

ax

xx

%219.0%1007802.14

8125.147802.14

t

Second Term 05/06 14

Error BoundsThe true root, α, must lie between xl and xu.

xl xuxr

xl(1) xu

(1)

After the 1st iteration, the solution, xr(1), should be within an

accuracy of)1()1(

2

1lu xx

xr(1)

Let xr(n) denotes xr in the nth iteration

Second Term 05/06 15

Error Bounds

xl(2) xu

(1)xu(2)

Suppose the root lies in the lower subinterval.

xr(2)

)1()1(2

)2()2(

2

1

2

1lulu xxxx

After the 2nd iteration, the solution, xr(2), should be

within an accuracy of

Second Term 05/06 16

Error Bounds

)1()1()1()1(2

)()(

2

1...

2

1

2

1lun

nl

nu

nl

nu xxxxxx

In general, after the nth iteration, the solution, xr(n),

should be within an accuracy of

If we want to achieve an absolute error of no more than Eα

)(log

2

1

)1()1(

2

)1()1(

E

xxn

Exx

lu

lun

Second Term 05/06 17

Implementation Issues• The condition f(xl)f(xr) = 0 (in step 3) is difficult to

achieve due to errors.

• We should repeat until xr is close enough to the root, but we don't know what the root is!

• Therefore, we have to estimate the error as

and repeat until ea < es (acceptable error)

%100newr

oldr

newr

ax

xxe

Second Term 05/06 18

Bisection Method (as C function)

// xl, xu: Lower and upper bound of the interval// es: Acceptable relative percentage error// xr: Estimated root in zero iteration (can simply// take xl or xu)// iter_max: Maximum # of iterationsdouble Bisect(double xl, double xu, double es, double xr, int iter_max) { double xr_old; // Est. root in the previous step double ea; // Est. error int iter = 0; // Keep track of # of iterations

do { iter++; xr_old = xr;

Second Term 05/06 19

xr = (xl + xu) / 2; // Estimate root

if (xr != 0) ea = fabs((xr – xr_old) / xr) * 100;

test = f(xl) * f(xr);

if (test < 0) xu = xr; else if (test > 0) xl = xr; else ea = 0;

} while (ea > es && iter < iter_max);

return xr;}

Second Term 05/06 20

Additional Implementation Issues

• Function call is a relatively slow operation.

• In the previous example, function f() is called twice in each iteration. Is it necessary?– We only need to update one of the bounds (see step 3

in the algorithm for the bracketing method).

Second Term 05/06 21

Revised Bisection Method (as C function)

double Bisect(double xl, double xu, double es, double xr, int iter_max) { double xr_old; // Est. root in the previous step double ea; // Est. error int iter = 0; // Keep track of # of iterations double fl, fr; // Save values of f(xl) and f(xr)

fl = f(xl); do { iter++; xr_old = xr;

xr = (xl + xu) / 2; // Estimate root fr = f(xr);

Second Term 05/06 22

if (xr != 0)

ea = fabs((xr – xr_old) / xr) * 100;

test = fl * fr;

if (test < 0) xu = xr; else if (test > 0) { xl = xr; fl = fr; } else ea = 0;

} while (ea > es && iter < iter_max);

return xr;}

Second Term 05/06 23

Comments on Bisection Method

• The method is guaranteed to converge.

• However, the convergence is slow as we gain only one binary digit in accuracy in each iteration.

Second Term 05/06 24

A.2. Regula Falsi Method• Also known as the false-position method, or linear

interpolation method.

• Unlike the bisection method which divides the search interval by half, regula falsi interpolates f(xu) and f(xl) by a straight line and the intersection of this line with the x-axis Is used as the new search position.

• The slope of the line connecting f(xu) and f(xl) represents the "average slope" (i.e., the value of f'(x)) of the points in [xl, xu ].

Second Term 05/06 25

rl

l

ru

u

xx

xf

xx

xf )()(

)()(

))((

ul

uluur xfxf

xxxfxx

Second Term 05/06 26

False-position vs Bisection

• False position in general performs better than bisection method.

• Exceptional Cases:– (Usually) When the deviation of f'(x) is high

and the end points of the interval are selected poorly.

– For example,

3.1,0with

1)( 10

ul xx

xxf

Second Term 05/06 27

Iteration xl xu xr εa (%) εt (%)

1 0 1.3 0.65 35

2 0.65 1.3 0.975 33.3 25

3 0.975 1.3 1.1375 14.3 13.8

4 0.975 1.1375 1.05625 7.7 5.6

5 0.975 1.05625 1.015625 4.0 1.6

Iteration xl xu xr εa (%) εt (%)

1 0 1.3 0.09430 90.6

2 0.09430 1.3 0.18176 48.1 81.8

3 0.18176 1.3 0.26287 30.9 73.7

4 0.26287 1.3 0.33811 22.3 66.2

5 0.33811 1.3 0.40788 17.1 59.2

Bisection Method (Converge quicker)

False-position Method

Second Term 05/06 28

3.1,0with

1)( 10

ul xx

xxf

Second Term 05/06 29

Summary• Bracketing Methods

– f(x) has the be continuous in the interval [xl, xu] and f(xl)f(xu) < 0

– Always converge– Usually slower than open methods

• Bisection Method– Slow but guarantee the best worst-case convergent

rate.

• False-position method– In general performs better than bisection method

(with some exceptions).