0% found this document useful (0 votes)
6 views

IntroductionToComputation-Lecture2_new

Uploaded by

an23ms268
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

IntroductionToComputation-Lecture2_new

Uploaded by

an23ms268
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to Computation (CS2201)

Lecture 2

Kripabandhu Ghosh

CDS, IISER Kolkata


NUMERICAL SOLUTION OF EQUATIONS
Numerical Solution

Objective
Numerical computation of real roots of an equation of the form f (x) = 0, where f
can be algebraic (e.g. polynomial) or transcendental (e.g. exponential, sin, log
etc.)

Assumption
f is continuously differentiable

Theorem
If f (x) is is continuous in the closed interval [a, b] and f (a), f (b) are of opposite
signs, then there is a real root α of the equation f (x) = 0 such that a < α < b
If further f (x) is differentiable in the open interval (a, b) and either f 0 (x) < 0 or f 0
> 0 in (a, b), then f (x) is strictly monotonic in [a, b] and then the root in unique.
Method of Tabulation

Description
Method for finding a rough location (interval) of the roots of an equation
using the sign change method
We start with a rough interval, say, [xl , xr ] and moderate interval length (say
h)
We check for change in sign for the function f (x) in each of the
sub-intervals: [xl , xl + h], [xl + h, xl + 2h], ..., [xl + nh, xr ]
The above process is repeated with shorter intervals (h/10)
Stop if the desired approximation is achieved

Drawback
Crude and computationally expensive process

Utility
Simple method to provide the initial approximation for starting an iterative method
Method of Tabulation (example)

Equation
f (x) = 10x + x - 4 = 0

x f(x)
0 -3
0.1 -2.64
0.2 -2.21
0.3 -1.70
0.4 -1.09
0.5 -0.34
0.6 0.58
0.7 1.71
0.8 3.11
0.9 4.84
1 7
Method of Tabulation (example)

Equation
f (x) = 10x + x - 4 = 0

x f(x)
0 -3
0.1 -2.64
0.2 -2.21
0.3 -1.70
0.4 -1.09
0.5 -0.34
0.6 0.58
0.7 1.71
0.8 3.11
0.9 4.84
1 7
Method of Tabulation (example)
Equation
f (x) = 10x + x - 4 = 0
Method of Tabulation (example)
Equation
f (x) = 10x + x - 4 = 0
Iteration Process

Premise
Let xn be the sequence of iterates of a required root α of the equation f (x)
= 0, produced by a given method
The error at the nth iteration (n ) is defined by n = α - xn

Convergence
The iteration converges if and only if n → 0 as n → ∞

Features
Initial approximation (x0 ) is chosen judiciously (e.g. using tabular method) –
critical for convergence (bad initial guess may cause the iterative process to
fail)
Self-correcting: if an accidental error occurs in calculating the iterate, the
erroneous iterate serves as the new initial guess and ultimately leads to the
correct result
Bisection Method

Initial Interval
Use tabulation method to find a sufficiently small interval [a0 , b0 ] containing the
root α of the equation f (x) = 0 such that f (a0 ) and f (b0 ) are of opposite signs.

Generation of iterates
1 Set x0 = a0 or b0 , x1 = (a0 + b0 )/2 and f (x1 )
2 If f (a0 ), f (x1 ) are of opposite signs, set a1 = a0 , b1 = x1 ([a1 , b1 ] = [a0 , x1 ])
3 Else, if f (x1 ), f (b0 ) are of opposite signs, set a1 = x1 , b1 = b0 ([a1 , b1 ] =
[x1 , b0 ])
4 Set x2 = (a1 + b1 )/2
5 If the desired accuracy is reached end; else continue the above steps
Bisection Method (algorithm)

General
1 With the interval [an , bn ] containing α such that f (an )f (bn ) < 0,
set xn+1 = (an + bn )/2
2 an+1 = an , bn+1 = xn+1 , if f (an )f (xn+1 ) < 0
an+1 = xn+1 , bn+1 = bn , if f (xn+1 )f (bn ) < 0
3 [an+1 , bn+1 ] contains α (f (an+1 )f (bn+1 ) < 0)

Convergence
|n | = |α − xn | ≤ bn − an = (b0 − a0 )/2n → 0 as n → ∞
Bisection Method (algorithm)

General
1 With the interval [an , bn ] containing α such that f (an )f (bn ) < 0,
set xn+1 = (an + bn )/2
2 an+1 = an , bn+1 = xn+1 , if f (an )f (xn+1 ) < 0
an+1 = xn+1 , bn+1 = bn , if f (xn+1 )f (bn ) < 0
3 [an+1 , bn+1 ] contains α (f (an+1 )f (bn+1 ) < 0)

Convergence
|n | = |α − xn | ≤ bn − an = (b0 − a0 )/2n → 0 as n → ∞
CONVERGENCE GUARANTEED!!
Bisection Method (example)

Equation
f (x) = 10x + x - 4 = 0

n an f (an ) bn f (bn ) xn+1 f (xn+1 )


0 0.500000 -0.337722 0.600000 0.581072 0.550000 0.098134
1 0.500000 -0.337722 0.550000 0.098134 0.525000 -0.125346
2 0.525000 -0.125346 0.550000 0.098134 0.537500 -0.015034
3 0.537500 -0.015034 0.550000 0.098134 0.543750 0.041188
4 0.537500 -0.015034 0.543750 0.041188 0.540625 0.012987
5 0.537500 -0.015034 0.540625 0.012987 0.539063 -0.001046
6 0.539063 -0.001046 0.540625 0.012987 0.539844 0.005965
7 0.539063 -0.001046 0.539844 0.005965 0.539453 0.002458
8 0.539063 -0.001046 0.539453 0.002458 0.539258 0.000706
9 0.539063 -0.001046 0.539258 0.000706 0.539160 -0.000170
Bisection (example)
Equation
f (x) = 10x + x - 4 = 0

f (x) BISECTION METHOD

a2 x3 b2 STEP 3

a1 x2 (= a1 +b
2 )
1
b1 STEP 2

a0 x1 (= a0 +b
2 )
0
b0 STEP 1

0.5 0.525 0.5375 0.55 0.6


-ve ROOT
-ve -ve +ve X +ve
Newton-Raphson Method

Initial guess
1 Use tabulation method to find a sufficiently small interval [a0 , b0 ] containing
the root α of the equation f (x) = 0 such that f (a0 ) and f (b0 ) are of
opposite signs.
2 Choose a0 or b0 as the initial guess x0 for the root

Generation of iterates
1 Set hn = – ff0(x(xnn))
f (xn )
2 xn+1 = xn + hn = xn - f 0 (xn )
3 If the desired accuracy is reached end; else continue the above steps

Convergence Condition
|f (x)f 00 (xn )| < |f 0 (xn )|2
Newton-Raphson Method (geometric interpretation)

The point at which the tangent to the curve y = f (x) at the point (xn , f (xn ))
cuts the x-axis is xn+1 , for the said tangent has the equation

y − f (xn ) = f 0 (xn )(x − xn )


f (xn )
and intersects y = 0 at x = xn - f 0 (xn ) = xn+1

f (xn )

y = f (x)

α xn+1 xn
0
Newton-Raphson Method (example)

Equation
f (x) = 10x + x - 4 = 0

n xn f (xn ) f 0 (xn ) hn
0 0.540781 0.014388 8.998277 -0.040781
1 0.539182 0.000024 8.968883 0.001599
2 0.539179 0.000000 8.968835 0.000003
Newton-Raphson Method: Features

Advantages
If |f (x)| is small and |f 0 (x)| is of moderate magnitude, the iteration converges
Rapidly convergent

Disadvantages
If the initial guess (x0 ) is bad, the iteration may not converge
Computationally expensive: both f (x) and f 0 (x) need to be computed
Regula Falsi Method

Initial Interval
Use tabulation method to find a sufficiently small interval [a0 , b0 ] containing the
root α of the equation f (x) = 0 such that f (a0 ) and f (b0 ) are of opposite signs.

Generation of iterates
(b0 −a0 )
1 Set x0 = a0 or b0 , x1 = a0 - f (a0 ) f (b0 )−f (a0 )
2 If f (a0 ), f (x1 ) are of opposite signs, set a1 = a0 , b1 = x1 ([a1 , b1 ] = [a0 , x1 ])
3 Else, if f (x1 ), f (b0 ) are of opposite signs, set a1 = x1 , b1 = b0 ([a1 , b1 ] =
[x1 , b0 ])
4 If the desired accuracy is reached end; else continue the above steps
Regula Falsi Method (algorithm)

General
1 With the interval [an , bn ] containing α such that f (an )f (bn ) < 0,
−an )
set xn+1 = an - f (an ) f (b(bnn)−f (an )
2 an+1 = an , bn+1 = xn+1 , if f (an )f (xn+1 ) < 0
an+1 = xn+1 , bn+1 = bn , if f (xn+1 )f (bn ) < 0
3 [an+1 , bn+1 ] contains α (f (an+1 )f (bn+1 ) < 0)

Convergence
|n | ≤ ( M1m−m
1
1 n
) |0 | → 0 as n → ∞ (M1 , m1 denote respectively the maximum
and minimum of |f 0 (x)| in [a0 , b0 ] and M1 − m1 < m1 )
Regula Falsi Method (algorithm)

General
1 With the interval [an , bn ] containing α such that f (an )f (bn ) < 0,
−an )
set xn+1 = an - f (an ) f (b(bnn)−f (an )
2 an+1 = an , bn+1 = xn+1 , if f (an )f (xn+1 ) < 0
an+1 = xn+1 , bn+1 = bn , if f (xn+1 )f (bn ) < 0
3 [an+1 , bn+1 ] contains α (f (an+1 )f (bn+1 ) < 0)

Convergence
|n | ≤ ( M1m−m
1
1 n
) |0 | → 0 as n → ∞ (M1 , m1 denote respectively the maximum
and minimum of |f 0 (x)| in [a0 , b0 ] and M1 − m1 < m1 )
CONVERGENCE GUARANTEED!!
Regula Falsi Method (geometric interpretation)

The chord joining the points (an , f (an )) and (bn , f (bn )) has the equation

y − f (an ) x − an
=
f (bn ) − f (an ) bn − an
(bn −an )
which and intersects (x-axis) y = 0 at x = an - f (an ) f (bn )−f (an ) = xn+1

f (bn )

y = f (x)
an xn+1
α bn
0

f (an )
Regula Falsi Method (example)

Equation
f (x) = 10x + x - 4 = 0

n an bn xn+1 f (xn+1 )
0 0.500000 0.600000 0.536757 -0.021669
1 0.536757 0.600000 0.539031 -0.001331
2 0.539031 0.600000 0.539170 -0.000081
THANK YOU !!!

You might also like