Professional Documents
Culture Documents
Root finding
Dr. Gokul K. C.
Department of Mathematics,
School of Science,
Kathmandu University, Nepal
Email: gokul.kc@ku.edu.np
1 / 37
Objective
To find the roots of equation
f (x) = 0 (1)
2 / 37
Bisection Method
Let a and b be chosen such that f (a) × f (b) < 0. i.e. either
f (a) > 0, f (b) < 0 or f (a) < 0, f (b) > 0. The root lies on [a, b].
If x1 be initial approximation then compute x1 = (a + b)/2.
If f (x1 ) = 0, x1 is the desired root. If not then f (x1 ) < 0 or f (x1 ) > 0.
If f (x1 ) × f (a) < 0, then the root lies on [x1 , a] otherwise on [x1 , b].
Let the root lies on [x1 , b] and this new interval is denoted by [a1 , b1 ] such
that |b1 − a1 | = |b − a|/2.
Now, the next approximation is x2 = (x1 + b)/2.
If f (x2 ) = 0 thenx2 is the required root. If not, the root lies either on
[x1 , x2 ] or on [x2 , b]
Let the root lies on [x1 , x2 ] such that x3 = (x1 + x2 )/2
If this new interval is denoted by [a2 , b2 ], then |b2 − a2 | = |b1 − a1 |/2 = |b−a|
22
After nth approximation, the interval [an , bn ] be such that |bn − an | = |b−a|2 .
n
The computation can be terminated if the error |bn − an | becomes less than
prescribed tolerance(or error()). That is,
|bn − an | = |b−a|
2n ≤ . On simplification gives, n ≥
ln(|b−a|/)
ln2
3 / 37
4 / 37
Bisection Method
Computatioal Steps
1 Input: Function(f (x)), tolerance() and initial approximations (a) and
(b), such that f (a) × f (b) < 0.
2 Compute x = (a + b)/2.
3 If f (x) × f (a) < 0, the root lies on [x, a], set b = x and go to step 2.
4 If f (x) × f (b) < 0, the root lies on [x, b], set a = x and go to step 2.
5 Repeat steps 2-4 until |b − a| < or |f (x)| <
5 / 37
Example
Solve using bisection method the equation x 3 − x − 1 = 0, correct to 4
decimal places.
Given: f (x) = x 3 − x − 1,
Tolerance=4 decimal places
= 1/2 × 10−4 = 0.00005
Let a = 1 such that f (a) = f (1) = −1 < 0
and b = 2 such that f (b) = f (2) = 5 > 0.
Total steps required: (n) ≥ ln(|2 − 1|/0.00005)/ln(2) = 14.28
ThereforeTotal steps required: (n) ≈ 15
Our first approximation is
x = (b + a)/2 = (2 + 1)/2 = 1.5.
Further calculations are tabulated below:
6 / 37
f (a) < 0(−) f (b) > 0(+)
n a b x f(x) Remarks
1 1 2 1.5 0.87 f (x) > 0, replace b by x
2 1 1.5 1.25 -0.29 f (x) < 0, replace a by x
3 1.25 1.5 1.375 0.22 f (x) > 0, replace b by x
4 1.25 1.375 1.3125 -0.05 f (x) < 0, replace a by x
5 1.3125 1.3750 1.3438 0.08 f (x) > 0, replace b by x
6 1.3125 1.3438 1.3281 0.01 f (x) > 0, replace b by x
7 1.3125 1.3281 1.3203 -0.01 f (x) < 0, replace a by x
8 1.3203 1.3281 1.3242 -0.00 f (x) < 0, replace a by x
9 1.3242 1.3281 1.3262 0.00 f (x) > 0, replace b by x
10 1.3242 1.3262 1.3252 0.00 f (x) > 0, replace b by x
11 1.3242 1.3252 1.3247 -0.00 f (x) < 0, replace a by x
12 1.3247 1.3252 1.3250 0.00 f (x) > 0, replace b by x
13 1.3247 1.3250 1.3248 0.00 f (x) > 0, replace b by x
14 1.3247 1.3248 1.3248 0.00 f (x) > 0, replace b by x
Exercise: Find a root, correct to three decimal places of the function
xe x − 1 = 0 Ans : 0.5671
7 / 37
False position method
Let a and b be chosen such that f (a) × f (b) < 0. i.e. either
f (a) > 0, f (b) < 0 or f (a) < 0, f (b) > 0. The root lies on [a, b].
Now, the equation of chord joining (a, f (a)) and (b, f (b)) is given by
y − f (a) = f (b)−f
b−a
(a)
(x − a)
If this chord intersects X-axis at (x1 , 0), we have
0 − f (a) = f (b)−f
b−a
(a)
(x1 − a)
Simplifying, We get first approximation,
f (a) af (b)−bf (a)
x1 = a − f (b)−f (a) (b − a) = f (b)−f (a)
If f (x1 ) = 0, x1 is the desired root. If not then f (x1 ) < 0 or f (x1 ) > 0.
If f (x1 ) × f (a) < 0, then the root lies on [x1 , a] otherwise on [x1 , b].
Let the root lies on [x1 , b], the next approximation(x2 ) is
x2 = x1ff(b)−f
(b)−bf (x1 )
(x1 )
and so on.
8 / 37
9 / 37
False position method
Computatioal Steps
1 Input: Function(f (x)), tolerance() and initial approximations (a) and
(b), such that f (a) × f (b) < 0.
af (b)−bf (a)
2 Compute x = f (b)−f (a)
3 If f (x) × f (a) < 0, the root lies on [x, a], set b = x and go to step 2.
4 If f (x) × f (b) < 0, the root lies on [x, b], set a = x and go to step 2.
5 Repeat steps 2-4 until |xn − xn−1 | < or |f (x)| <
10 / 37
Example
Solve using false position method the equation x 3 − x − 1 = 0, correct to 4
decimal places.
12 / 37
13 / 37
Secant method
Computatioal Steps
1 Input: Function(f (x)), tolerance() and initial approximations (a) and
(b).
af (b)−bf (a)
2 Compute x = f (b)−f (a)
3 Set a = b and b = x.
4 Repeat steps 2-3 until |xn − xn−1 | < or |f (x)| <
14 / 37
Example
Solve using secant method the equation x 3 − x − 1 = 0, correct to 4
decimal places.
15 / 37
Newton-Raphson method
Let x0 be an approximate root of f (x) = 0 and let x1 = x0 + h be the exact
root such that f (x1 ) = f (x0 + h) = 0.
Expanding f (x0 + h) = 0 by Taylor’s series, we obtain
h2 00
f (x0 + h) = f (x0 ) + hf 0 (x0 ) +
f (x0 ) + · · · = 0 (2)
2!
Neglecting the second and higher order derivatives, we have
f (x0 )
f (x0 ) + hf 0 (x0 ) = 0, h = − (3)
f 0 (x0 )
Substituting the value of h in x1 , we get first approximation
f (x0 )
x1 = x0 − (4)
f 0 (x0 )
After nth approximation, we have
f (xn )
xn+1 = xn − (5)
f 0 (xn )
Which is the Newton-Raphson formula
16 / 37
Method of tangent
17 / 37
Newton-Raphson method
Computatioal Steps
1 Input: Function(f (x)), Derivative of function(f 0 (x)), tolerance() and
initial approximation(a)
f (a)
2 Compute x = a − f 0 (a)
3 Set a = x.
4 Repeat steps 2-3 until |xn − xn−1 | < or |f (x)| <
18 / 37
Example
Solve using Newton-Raphson method the equation x 3 − x − 1 = 0, correct
to 4 decimal places.
n a x
1 1 1.5
2 1.5 1.3478
3 1.3478 1.3252
4 1.3252 1.3247
Given equation,
f (x) = 0 (7)
Rewriting equation (7) in the form
x = g (x) (8)
x1 = g (x0 ) (9)
20 / 37
Fixed point iteration method
21 / 37
Fixed point iteration method
Computatioal Steps
1 Input: Function(f (x)), Function(g (x)), tolerance() and initial
approximation(a)
2 Compute x = g (a)
3 Set a = x.
4 Repeat steps 2-3 until |xn − xn−1 | < or |f (x)| <
22 / 37
Example
Solve using Iteration method the equation x 3 − x − 1 = 0, correct to 4
decimal places.
f (x, y ) = 0
g (x, y ) = 0
Convergent Criteria
Rewriting the equation in the form:
∂F ∂F
x = F (x, y ) y = G (x, y ) ∂x ∂y < 1
+
OR
∂G ∂G
x = G (x, y ) y = F (x, y ) ∂x ∂y < 1
+
n x y n x y
1 0.70000 0.80000 8 0.99001 0.99972
2 0.81760 0.92800 9 0.99395 0.99989
3 0.88610 0.97224 10 0.99635 0.99996
4 0.92901 0.98905 11 0.99780 0.99998
5 0.95608 0.99564 12 0.99868 0.99999
6 0.97303 0.99826 13 0.99920 1.00000
7 0.98354 0.99931 14 0.99952 1.00000
f (x, y ) = 0
g (x, y ) = 0
Now,
D1 D2
h= , k=
D D
The new approximations are, therefore,
x1 = x0 + h, y1 = y0 + k
xn+1 = xn + h, yn+1 = yn + k
27 / 37
Exampale
Exmaple: Find a real root of the equations 3yx 2 − 10x + 7 = 0 and
y 2 − 5y + 4 = 0 correct to 4 decimal places using initial approximation (0, 0)
28 / 37
System of linear equations
Consider a system of linear equations:
AX = B (13)
a11 a12 a13 x1 b1
Where, A = a21 a22 a23 , X = x2 , B = b2
a31 a32 a33 x3 b3
In this chapter, we will study the following 3 methods to solve linear
system.
Iterative methods
LU decomposition method
Tri-diagonal system
29 / 37
Iteration methods
Consider a system: Same initial set is used in (∗∗) to
a11 x1 + a12 x2 + a13 x3 = b1 update next value.
a21 x1 + a22 x2 + a23 x3 = b2 · · · (∗) Gauss Seidel method
a31 x1 + a32 x2 + a33 x3 = b3 Let (x10 , x20 , x30 ) be initial approxi-
If the coefficient matrix of (∗) is diag- mation. Substituting (x10 , x20 , x30 ) in
onally dominant, i.e. a11 > a12 + a13 , first equation of (∗∗) to get x11 .
a22 > a21 + a23 , a33 > a31 + a32 , then we Again, substituting (x11 , x20 , x30 ) in
can solve using iterative methods. second equation to get x21 and fi-
Rewriting (15) in the form: nally (x11 , x21 , x30 ) in third equation
x1 = b1
a11 − a12
a11 x2 − a13
a11 x3
to get x31 and so on.
b2 a21 a23 Updated values of previous steps
x2 = a22 − a22 x1 − a22 x3 · · · (∗∗) are used in (∗∗) to update next
x3 = ab333 − aa31 33
x1 − aa32
33
x2 value.
Jacobi method Gauss seidel method is 2 times
Let (x10 , x20 , x30 ) be initial approxi- faster than Jacobi method.
mation. Substituting in r.h.s of Convergent criteria:
Pn aij
(∗∗) we get first update (x11 , x21 , x31 ). j=1,j6=i aii ≤ 1, i = 1, 2, · · · , n,
Again substituting (x11 , x21 , x31 ) we get where the 0 <0 sign should be valid
(x12 , x22 , x32 ) and so on. on at least one equation. 30 / 37
Jacobi method
Solve using iteration methods:
2x − y = 1
−x + 3y − z = 8
−y + 2z = −5
Rewriting,
1+y 8+x+z y −5
x= 2
, y= 3
, z= 2
Using initial approximation (0, 0, 0), the
results are tabulated below:
Gauss-Seidel method
31 / 37
Exercise
Solve using iterative methods:
10x − 2y − z − u = 3
−2x + 10y − z − u = 15
−x − y + 10z − 2u = 27
−x − y − 2z + 10u = −9
32 / 37
LU decomposition method
a11 a12 a13
Let A = a21 a22 a23 be a nonsingular square matrix. Then A can be
a31 a32 a33
factorized in the form LU such that A = LU, where L is lower triangular
matrix
and U is upper
triangular
matrix represented
by:
1 0 0 u11 u12 u13
L = l21 1 0 and U = 0 u22 u23 .
l31 l32 1 0 0 u33
Substituting A = LU in (13), we get
LUX = B (14)
If we set
UX = Y (15)
then,
LY = B (16)
Solving (16) by forward substitution, we obtain vector Y . Substituting this
Y in (15) and solving by backward substitution, we get the required
solution vector X .
33 / 37
Solve the system by LU
decomposition 2 3 1
∴ U = 0 1/2 5/2 .
2x + 3y + z = 9
0 0 18
x + 2y + 3z = 6
3x + y + 2z = 8 Now for L, we collect all pivot
columns from pivot element in
2 3 1 downward direction.
Given A = 1 2 3 .
2 0 0
3 1 2 1 1/2 0
Since 2 is a pivot element, using
3 −7/2 18
Gaussian elimination, perform
R2 = R2 − 1/2R1 , R3 = R3 − 3/2R1 Dividing every column by corre-
sponding pivot element, we get
2 3 1
0 1/2 5/2 1 0 0
0 −7/2 1/2 ∴ L = 1/2 1 0
Again, 1/2 is second pivot element, 3/2 −7 1
perform R3 = R3 + 7R2
Never transform pivot ele-
2 3 1 ment to identity 1
0 1/2 5/2 = U
0 0 18
34 / 37
9
Given, B = 6 . Now, UX = Y is:
8
2 3 1
x
9
A = −3 5
9 1 ,B = 5
∴ Y = 3/2 6 −4 0 2
5
35 / 37
Tridiagonal system
Consider the system of equations defined by:
b1 x1 + c1 x2 = d1 Thomas algorithm
a2 x1 + b2 x2 + c2 x3 = d2 Set α1 = b1 and
a3 x2 + b3 x3 + c3 x4 = d3 compute
.. αi = bi − aαi ci−1
i−1
,
. i = 2, 3, · · · , n.
an−1 xn−2 + bn−1 xn−1 + cn−1 xn = dn−1 Set β1 = d1 /b1 and
an xn−1 + bn xn = dn compute
βi = di −aαi iβi−1 ,
The matrix of coefficient is i = 2, 3, · · · , n.
b1 c1 0 0 ··· ··· ··· 0 Set xn = βn and
a2 b2 c2 0 ··· ··· ··· 0
compute
0 a3 b3 c3 ··· ··· ··· 0
xi = βi − ci αxi+1
,
··· ··· ··· ··· ··· ··· ··· ··· i
0 0 0 ··· 0 an−1 bn−1 cn−1
i = n − 1, n − 2, · · · , 1.
0 0 0 ··· 0 0 an bn
36 / 37
2. Setting β1 = d1 /b1
Solve using Thomas algorithm:
=⇒ β1 = 0/2 = 0 and compute
2x − y = 0 d2 −a2 β1 0−(−1)(0)
−x + 2y − z = 0 β2 = α2 = 3/2 =0
d3 −a3 β2 0−(−1)(0)
−y + 2z − u = 0 β3 = α3 = 4/3 =0
−z + 2u = 1 d4 −a4 β3 1−(−1)(0)
β4 = α4 = 5/4 = 4/5
The augmented matrix is:
2 −1 0 0 : 0
3. Setting x4 = β4
−1 2 −1 0 : 0 =⇒ x4 = 4/5 and compute
0 −1 2 −1 : 0 x3 = β 3 − c3 x4
=0− (−1)(4/5)
= 3/5
α3 4/3
0 0 −1 2 : 1 c2 x3 (−1)(3/5)
x2 = β 2 − α2 =0− 3/2 = 2/5
Given i = 4, c1 x2 (−1)(2/5)
x1 = β 1 − α1 =0− 2 = 1/5
1. Setting α1 = b1
=⇒ α1 = 2 and compute
Exercise: Solve the system using
a2 c1 (−1)(−1)
α2 = b2 − α1 =2− 2 = 3/2 Thomas algorithm
a3 c2 (−1)(−1)
α3 = b3 − α2 =2− 3/2 = 4/3 3x1 − x2 = −1
α4 = b4 − a4 c3
=2− (−1)(−1)
= 5/4 −x1 + 3x2 − x3 = 7
α3 4/3
−x2 + 3x3 = 7
37 / 37