Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 2 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

1

Numerical Analysis
Lecture-2

Dr. Ilyas Fakhir

CS Dept. GCU, Lahore

January 27, 2020

Dr. Ilyas Fakhir Numerical Analysis


2

Bisection Method

Definition
The first technique, based on the Intermediate Value Theorem, is
called the Bisection, or Binary-search, method.

Suppose f is a continuous function defined on the interval [a, b],


with f (a) and f (b) of opposite sign. The Intermediate Value
Theorem implies that a number p exists in (a, b) with f( p) = 0.
The method calls for a repeated halving (or bisecting) of
subintervals of [a, b] and, at each step, locating the half containing
p.

Dr. Ilyas Fakhir Numerical Analysis


3

Bisection Method Algorithm

To begin, set a1 = a and b1 = b, and let p1 be the midpoint of [a,


b]; that is,
b 1 − a1 a1 + b 1
p1 = a1 + = .
2 2

If f (p1 ) = 0, then p = p1 , and we are done.


If f (p1 ) 6= 0, then f (p1 ) has the same sign as either f (a1 ) or
f (b1 ).
If f (p1 ) and f (a1 ) have the same sign, p ∈ (p1 , b1 ). Set
a2 = p1 and b2 = b1 .
If f (p1 ) and f (a1 ) have opposite signs, p ∈ (a1 , p1 ). Set
a2 = a1 and b2 = p1 .

Dr. Ilyas Fakhir Numerical Analysis


4

Bisection Method Contd...

Dr. Ilyas Fakhir Numerical Analysis


5

Bisection Method Algorithm to solve f(x) = 0

Given the function f defined on [a, b] satisfying f (a)f (b) < 0.

1 a1 = a, b1 = b, p0 = a;
2 i = 1;
3 pi = 21 (ai + bi );
4 If |pi − pi−1 | <  or |f (pi )| <  then 10;
5 If f (pi )f (ai ) > 0, then 6;
If f (pi )f (ai ) < 0, then 8;
6 ai+1 = pi , bi+1 = bi ;
7 i = i + 1; go to 3;
8 ai+1 = ai ; bi+1 = pi ;
9 i = i + 1; go to 3;
10 End of Procedure.

Dr. Ilyas Fakhir Numerical Analysis


6

Bisection Method Contd...

Comment on Stopping Criteria for the Algorithm


Other stopping procedures can be applied in Step 4.
For example, we can select a tolerance  > 0 and generate
p1 , ..., pN until one of the following conditions is met:

|pN − pN−1 | <  (1)


|pN − pN−1 |
< , pN 6= 0, or (2)
|pN |
|f (pN )| <  (3)
Without additional knowledge about f or p, Inequality (2) is
the best stopping criterion to apply because it comes closest
to testing relative error.

Dr. Ilyas Fakhir Numerical Analysis


7

Bisection Method Contd...

Example
Show that f (x) = x 3 + 4x 2 − 10 = 0 has a root in [1, 2], and use
the Bisection method to determine an approximation to the root
that is accurate to at least within 10−4 .

Relative Error Test


Note that, for this example, the iteration will be terminated when
a bound for the relative error is less than 10−4 , implemented in the
form:
|pn − pn−1 |
< 10−4
|pn |

Dr. Ilyas Fakhir Numerical Analysis


8

Bisection Method Contd...

Solution
Because f (1) = −5 and f (2) = 14 the Intermediate Value
Theorem ensures that this continuous function has a root in [1, 2].
For the first iteration of the Bisection method we use the fact that
at the midpoint of [1, 2] we have f (1.5) = 2.375 > 0. This
indicates that we should select the interval [1, 1.5] for our second
iteration. Then we find that f (1.25) = −1.796875 so our new
interval becomes [1.25, 1.5], whose midpoint is 1.375. Continuing
in this manner gives the values in Table on next slide.

Dr. Ilyas Fakhir Numerical Analysis


9

Solution Contd...

Dr. Ilyas Fakhir Numerical Analysis


10

Solution Contd...

After 13 iterations, p13 = 1.365112305 approximates the root


p with an error
|p − p13 | < |b14 − a14 | = |1.365234375 − 1.365112305| =
0.000122070.
Since |a14 | < |p|, we have

|p − p13 | |b14 − a14 |


< ≤ 9.0 × 10−5
|p| |a14 |

so the approximation is correct to at least within 10−4 .


The correct value of p to nine decimal places is p =
1.365230013

Dr. Ilyas Fakhir Numerical Analysis


11

Theoretical Results for Bisection Method

Theorem
Suppose that f ∈ C [a, b] and f (a)f (b) < 0. The Bisection method
generates a sequence {pn }∞n=1 approximating a zero p of f with

b−a
|pn − p| ≤ , when n ≥ 1.
2n

Dr. Ilyas Fakhir Numerical Analysis


12

Theoretical Results for Bisection Method

Proof
For each n ≥ 1, we have
1
bn − an = (b − a) and p ∈ (an , bn ).
2n−1
Since pn = 12 (an + bn ) for all n ≥ 1, it follows that

1 b−a
|pn − p| ≤ (bn − an ) = .
2 2n

Dr. Ilyas Fakhir Numerical Analysis


13

Theoretical Results for Bisection Method

Rate of Convergence
Because
1
|pn − p| ≤ (b − a) ,
2n
the sequence {pn }∞n=1 converges to p with rate of convergence
O( 21n ); that is,
1
pn = p + O( ).
2n

Dr. Ilyas Fakhir Numerical Analysis


14

Theoretical Results for Bisection Method

Conservative Error Bound


It is important to realize that the theorem gives only a bound
for approximation error and that this bound might be quite
conservative.
For example, this bound applied to the earlier problem,
namely where
f (x) = x 3 + 4x 2 − 10
ensures only that
2−1
|p − p9 | ≤ ≈ 2 × 10−3
29
but the actual error is much smaller:

|p − p9 | = |1.365230013 − 1.365234375| ≈ 4.4 × 10−6

Dr. Ilyas Fakhir Numerical Analysis


15

Theoretical Results for Bisection Method

Example
Using the Error Bound Determine the number of iterations
necessary to solve f (x) = x 3 + 4x 2 − 10 with accuracy 10−3 using
a1 = 1 and b1 = 2.

Solution
We we will use logarithms to find an integer N that satisfies

|pN − p| ≤ 2−N (b − a) = 2−N < 10−3

Logarithms to any base would suffice, but we will use base-10


logarithms because the tolerance is given as a power of 10.

Dr. Ilyas Fakhir Numerical Analysis


16

Theoretical Results for Bisection Method

Solution Contd...
Since 2−N < 10−3 implies that log10 2−N < log10 10−3 = −3,
we have
3
−Nlog10 2 < −3 and N > ≈ 9.96.
log10 2
Hence, ten iterations will ensure an approximation accurate to
within 10−3 .
The earlier numerical results show that the value of
p9 = 1.365234375 is accurate to within 10−4 .
Again, it is important to keep in mind that the error analysis
gives only a bound for the number of iterations.
In many cases, this bound is much larger than the actual
number required.
Dr. Ilyas Fakhir Numerical Analysis

You might also like