Numerical Chapter2

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

Manalebish D

Numerical Analysis Math-3221


Chapter two : Non linear equations

October 11, 2023


Chapter 1

Basic concepts in error


estimation

1
Chapter 2

Non-linear Equation
Locating roots
consider an equation of the form f (x) = 0, assuming the function f (x) is
continuously differentiable function of sufficiently high order,we want to find
solution (roots of the equation) f (x) = 0. That is, we find numbers a such
that f (a) = 0. a is the point at which the graph of the function intersects
the x−axis.
The function can be algebraic equation such as polynomials, rationals or
transcendental equations: trigonometric, exponential, logarithmic, nth root,
etc.

Example 1 f (x) = ex − 3 cos x = 0

This nonlinear function for example have infinitely many solutions but it is
difficult to find them
In most cases we have to use approximate solutions i.e. find a such that
|f (a)| < ε where ε is given tolerance which gives an interval where the root
is located but not the exact root. in this case the equation f (x) = 0 and
M.f (x) = 0 (where M is a constant) do not have the same roots

2
2.1 Bisection method
This is a simple but slowly convergent method for determining the roots of a
continuous function f (x). it is based on the intermediate value theorem for
f (x) in an interval [a0 , b0 ] for which if f has opposite signs at the end points
say f (a0 ) < 0 and f (b0 ) > 0, then f has a root in [a0 , b0 ]
a0 +b0
compute the mid point x0 = 2

If f (x0 = 0 then x0 is a solution


If f (x0 < 0 then take a1 = x0 and b1 = b0 i.e. [a1 , b1 ] = [x0 , b0 ]
If f (x0 > 0 then take b1 = x0 and a1 = a0 i.e. [a1 , b1 ] = [a0 , x0 ]
continue the process until f (xn ) = 0
|b−a|
after n bisections the interval is reduced by a factor of 2n i.e. ε < 2n

Advantage:-

• it requires little thought and calculations.

• it guarantees convergence and accuracy (no error testing is necessary)

• it works if the equation has odd number of roots in the given interval.

Disadvantage:-

• The need for two initial guesses, one on each side of the root, is difficult
if we have no idea of the root, or if we have roots close to each other.

• even order multiple roots are impossible to be computed in this method.

• Round off error can cause problems as xn approached the actual root
a.

Example 2 Find the roots of ex − 3x = 0 with absolute error δ = 0.0001

Manalebish D: 3 3
f (0) = 1 > 0 f (1) = e − 3 < 0 and f (2) = e2 − 6 ≃ 1.39 > 0
Then there are roots on [0, 1] and [1, 2]

0+1
1. Let us take the first root between [a0 , b0 ] = [0, 1] with x1 = 2 = 0.5

f (x1 ) = f (0.5) = 0.14872 > 0


0.5+1
Take [a1 , b1 ] = [0.5, 1] with x2 = 2 = 0.75

f (x2 ) = f (0.75) = −0.132 < 0


0.5+0.75
Take [a2 , b2 ] = [0.5, 0.75] with x3 = 2 = 0.625

f (x3 ) = f (0.625) = −0.00675 < 0

continuing the process we get

x14 = 0.61902 and [a14 , b14 ] = [0.61902, 0.61914]

Take a ≃ x15 = 0.61908 with f (x15 ) = −0.0000214

Remark 2.1.1 Possible algorithm for this particular question is


%f i n d r o o t s o f e ˆx−3x b e t w e e n [ 0 , 1 ] u s i n g b i s e c t i o n method
f=@( x ) ( exp ( x )−3∗ x ) ; %d e f i n i n g a f u n c t i o n
a =0; %l o w e r l i m i t o f i n t e r v a l
b =1; %u p p e r l i m i t o f i n t e r v a l
Es =0.0001
i t e r =0
w h i l e i t e r <1000
f p r i n t f ( ’ \ n Hence r o o t l i e s b e t w e e n (%.5 f ,%.5 f ) ’ , a , b )
c=(a+b ) / 2 ;
i t e r = i t e r +1;
t e s t =f ( a ) ∗ f ( c ) ;
i f t e s t <0;
b=c ;
e l s e i f t e s t >0;

Manalebish D: 4 4
a=c ;
end
f p r i n t f ( ’ \ n T h e r e f o r e , c=%.5 f \n Here , f ( c )=%.5 f ’ , c , f ( c ) )
if iter > 1
i f a b s ( c )>0
Ea=a b s ( ( c−c o l d )/ c ) ;
i f a b s ( Ea)<Es
break
end
end
end
c o l d=c ;
end
f p r i n t f ( ’ \ n Root o f g i v e n e q u a t i o n i s %f ’ , c )

2. For the second root of of ex − 3x = 0 with absolute error δ = 0.0001 is


between
1+2
[a0 , b0 ] = [1, 2] with x1 = 2 = 1.5
f (x1 ) = f (1.5) = −0.0183 < 0
1.5+2
Take [a1 , b1 ] = [1.5, 2] with x2 = 2 = 1.75
f (x2 ) = f (1.75) = 0.5046 > 0
1.5+1.75
Next [a2 , b2 ] = [1.5, 1.75] with x3 = 2 = 1.625
f (x3 ) = f (1.625) = 0.2034 > 0 and so on similarly
[a14 , b14 ] = [1.5121, 1.5122] continuing the process we get

a ≃ x15 = 1.51215 with f (x15 ) = 0.0000237


Then the best approximation would be
|f (x15 )| = |f (1.51215)| = |0.0000237| < 0.0001

then the root is best approximated by a = 1.51215

Manalebish D: 5 5
Example 3 find the roots of f (x) = x2 −3 on the interval [1, 2] with absolute
error δ = 0.01

f (1) = −2 < 0 and f (2) = 1 > 0


1+2
Let [a0 , b0 ] = [1, 2] with x1 = 2 = 1.5 f (x1 ) = f (1.5) = (1.5)2 − 3 =
−0.75 < 0
1.5+2
Let [a1 , b1 ] = [1.5, 2] with x2 = 2 = 1.75
f (x2 ) = f (1.75) = 3.0625 − 3 = 0.0625 > 0
1.5+1.75
Let [a2 , b2 ] = [1.5, 1.75] with x3 = 2 = 1.625
f (x3 ) = f (1.625) = −0.359 < 0
1.625+1.75
Let [a3 , b3 ] = [1.625, 1.75] with x4 = 2 = 1.6875
f (x4 ) = f (1.6875) = −0.1523 < 0
1.6875+1.75
Let [a4 , b4 ] = [1.6875, 1.75] with x5 = 2 = 1.7188
f (x5 ) = f (1.7188) = −0.0457 < 0
1.7188+1.75
Let [a5 , b5 ] = [1.7188, 1.75] with x6 = 2 = 1.7344
f (x6 ) = f (1.7344) = 0.0081 > 0
1.7188+1.7344
Let [a6 , b6 ] = [1.7188, 1.7344] with x7 = 2 = 1.7266
f (x7 ) = −0.0189 < 0
Here |f (x7 )| = |f (1.7266)| = | − 0.0189| = 0.0189
Then the best approximation would be |f (x6 )| = |f (1.7344)| = |0.008| <
0.01
then the root is best approximated by a = 1.7344

2.2 The method of false position


This method is always convergent for continuous function f
It requires two initial guess [a0 , b0 ] with f (a0 )f (b0 ) < 0 the end points
of the new interval are calculated as a weighted average defined on previous

Manalebish D: 6 6
interval. i.e.

f (b0 )a0 − f (a0 )b0


w1 =
f (b0 ) − f (a0 )
provided f (b0 ) and f (a0 ) have opposite signs.
In general the formula is given as

f (bn−1 )an−1 − f (an−1 )bn−1


wn =
f (bn−1 ) − f (an−1 )
for n = 0, 1, 2, . . . until convergence criteria is satisfied
Then if f (an )f (wn ) ≤ 0 then set an+1 = an : bn+1 = wn otherwise an+1 =
wn : bn+1 = bn
Algorithm
Given a function f (x) continuous on the interval [a, b] satisfying the cri-
teria f (a)f (b) < 0

1. Set a0 = a, b0 = b

2. For n = 0, 1, 2, . . . until convergence criteria is satisfied compute


f (bn−1 )an−1 − f (an−1 )bn−1
wn =
f (bn−1 ) − f (an−1 )
If f (an )f (wn ) ≤ 0 then set an+1 = an ; bn+1 = wn Otherwise an+1 =
wn ; bn+1 = bn

Example 4 Solve 2x3 − 25 x − 5 = 0 for the interval [1, 2] using false position
method with absolute error ε < 10−3

5
f (x) = 2x3 − x − 5
2
5 11
f (1) = 2 − − 5 = − < 0 f (1) < 0
2 2
f (2) = 16 − 5 − 5 = 6 > 0 f (2) > 0
11
f (1)f (2) = − 6 = −33 < 0
2
Manalebish D: 7 7
Then we look for the roots in [1, 2]
Let a0 = 1 b0 = 2

f (b0 )a0 − f (a0 )b0 f (2)1 − f (1)2


w1 = = = 1.47826
f (b0 ) − f (a0 ) f (2) − f (1)
Then f (w1 ) = f (1.47826) = −2.23489761
next f (1)f (w1 ) = − 11

2 (−2.23489761) > 0

Then set a1 = w1 and b1 = b0 = 2

f (2)(1.47826) − f (1.47826)2
w2 = = 1.6198574
f (2) − f (1.47826)
Then f (w2 ) = f (1.6198574) = −0.548832
f (w1 )f (w2 ) = f (1.47826)f (1.6198574) = (−2.23489761)(−0.548832) > 0
Next set a2 = w2 and b2 = b1 = b0 = 2

f (2)(w2 ) − f (w2 )2
w3 = = 1.65171574
f (2) − f (w2 )
Then f (w3 ) = f (1.65171574) = −0.116983
f (w2 )f (w3 ) = (−0.548832)(−0.116983) > 0
Then set a3 = w3 and b3 = 2

f (2)(w3 ) − f (w3 )2
w4 = = 1.658376
f (2) − f (w3 )
f (w4 ) = −0.0241659
f (w3 )f (w4 ) > 0 continuing in this manner
w7 = 1.660085
f (w7 ) = −0.0002089
|f (1.660085)| < 0.001
Hence one of the root is 1.660085

Remark 2.2.1 Possible algorithm for this particular question is

Manalebish D: 8 8
% Find t h e r o o t s o f x ˆ3−2∗x−5=0 by u s i n g F a l s e P o s i t i o n Method .
f=@( x ) 2∗ x ˆ3 −(5/2)∗ x −5;
x0 =1; x1 =2; Es = 0 . 0 1 ;
i t e r =0;
w h i l e i t e r <1000
f p r i n t f ( ’ \ n Hence r o o t l i e s b e t w e e n (%.5 f ,%.5 f ) ’ , x0 , x1 )
x r =( f ( x1 ) ∗ x0−f ( x0 ) ∗ x1 ) / ( f ( x1)− f ( x0 ) ) ;

i f f ( x0 ) ∗ f ( x r )>0
x0=x r ;
e l s e x1=x r ;
end
i t e r = i t e r +1;
f p r i n t f ( ’ \ n T h e r e f o r e , c=%.5 f \n Here , f ( c )=%.5 f ’ , xr , f ( x r ) )
if iter > 1
i f a b s ( x r )>0
Ea=a b s ( ( xr−x r o l d )/ x r ) ;
i f a b s ( Ea)<Es
break
end
end
end

x r o l d=x r ;
end
Answer=x r


Exercise 1 Approximate 2 using f (x) = x2 − 2 = 0 on [0, 2] with error
δ < 0.01

Solution:-

Manalebish D: 9 9
[0, 2] f (0) = −2 < 0 and f (2) = 2 > 0
0(2) − 2(−2)
x1 = =1 f (1) = −1 < 0
2 − (−2)
 
1(2) − 2(−1) 4 4 2
[1, 2] x2 = = f =− <0
2 − (−1) 3 3 9
4 2
(2) − 2(− 9 ) 28
 
4
,2 x3 = 3 = = 1.4 f (1.4) = −0.04 < 0
3 2 − (− 29 ) 20
1.4(2) − 2(−0.04)
[1.4, 2] x4 = = 1.412 f (1.4) = −0.006256 < 0
2 − (−0.04)

5 find roots of 5 sin2 x − 8 cos5 x = 0 on 12 , 32 by false position


 
Example
method with absolute error δ = 10−3

2.3 The secant method


This method is always convergent for continuous function f
It requires two initial two initial guess [x0 , x1 ] with f (x0 )f (x1 ) < 0
Draw a chord from A(x0 , f (x0 )) to B(x1 , f (x1 )).

Manalebish D: 10 10
 
x1 − x0
This chord intersects the x-axis at x2 where x2 = x1 −f (x1 )
  f (x1 ) − f (x0 )
xn−1 − xn−2
In general, for xn = xn−1 − f (xn−1 )
f (xn−1 ) − f (xn−2 )
If f (xn ) = 0 xn is a root
If f (xn ) < 0 take the interval [an+1 , bn+1 ] = [xn , bn ]
If f (xn ) > 0 take the interval [an+1 , bn+1 ] = [an , xn ]
continue the process until f (xn ) = 0 or until |f (xn )| < δ
Algorithm for secant method
To determine a root f (x) = 0 given the values x0 and x1 that are near
the root,
if |f (x0 )| < |f (x1 )| Then swap x0 with x1
Repeat  
x1 − x0
set x2 = x1 − f (x1 )
f (x1 ) − f (x0 )
set x0 = x1
set x1 = x2
until |f (x2 )| <tolerance value

Example 6 Find an approximation of the root of x3 + x − 1 = 0 with δ <


0.001 on [0.5, 1] with f (0.5) = −0.375 < 0 and f (1) = 1 > 0
   
x1 − x0 1 − 0.5
x2 = x1 −f (x1 ) = 1−1 = 0.64 f (0.64) ≈
f (x1 ) − f (x0 ) 1 − (−0.375)
−0.098
next [x1 , x2 ] = [0.64,1] 
0.64 − 1
x3 = 0.64 − f (0.64) = 0.672 f (0.672) ≈ −0.0245
−0.098 − 1
next [0.672, 1]  
0.672 − 1
x4 = 0.672 − f (0.672) = 0.68 f (0.68) ≈ −0.00557
−0.0245 − 1
next [0.68, 1]  
0.68 − 1
x5 = 0.68 − f (0.68) = 0.682 f (0.682) ≈ −0.000785
−0.00557 − 1
and so on

Manalebish D: 11 11
Remark 2.3.1 Possible matlab algorith for this question
%f i n d r o o t s o f xˆ3+x−1 u s i n g s e c a n t method
f=@( x ) 2∗ xˆ3+x−8 ;% d e f i n e t h e f u n c t i o n
a (1)=0;% a s s i g n l o w e r i n i t i a l p o i n t
a (2)=2;% a s s i g n u p p e r i n i t i a l p o i n t
n=0.001; % r e l a t i v e error al lo we d
f o r i =3:10;
f p r i n t f ( ’ \ n Hence r o o t l i e s b e t w e e n (%.6 f ,%.6 f ) ’ , a ( i −2) , a ( i −1))
a ( i )=a ( i −1)−( f ( a ( i − 1 ) ) ) ∗ ( ( a ( i −1)−a ( i −2))/( f ( a ( i −1))− f ( a ( i − 2 ) ) ) ) ;
i f a b s ( ( a ( i )−a ( i −1))/ a ( i ) ) ∗ 1 0 0 0 < n
r o o t=a ( i )
break
end
f p r i n t f ( ’ \ n T h e r e f o r e , a ( i )=%.6 f \n Here , f ( a ( i ))=%.6 f ’ , a ( i ) , f ( a ( i ) ) )
end


Exercise 2 Approximate 2 using f (x) = x2 − 2 = 0 on [0, 2] with error
δ < 0.01

Solution:-

[0, 2] f (0) = −2 < 0 and f (2) = 2 > 0


2 − 0) 2 − 0)
x2 = 2 − f (2) = 2 − f (2) =1 f (1) = −1 < 0
f (2) − f (0) 2 − (−2)
 
1−2 4 4 2
[1, 2] x3 = 1 − (−1) = f( ) = − < 0
−1 − 2 3 3 9

and so on

Manalebish D: 12 12
2.4 Iteration method:-
we choose an arbitrary initial guess x0 (usually with rough graphical methods
) and try to improve the guess by repeating (iterating) a few steps again and
again so that we approach the root a.
we write the equation f (x) = 0 in the form x = g(x) where g is defined
in some interval I containing a and the range of g lies in I for x ∈ I.
Compute successively

x1 = g(x0 ) (2.1)
x2 = g(x1 ) (2.2)
x3 = g(x2 ) (2.3)
..
. (2.4)
xn+1 = g(xn ) (2.5)

Which may converge to the actual root a (depending on the choice of g


and x0 ) with limn→∞ (xn − a) = 0 i.e. ∀ε > 0, ∃M such that |xn − a| < ε for
n ≥ M, or that the values xn may move away from the root a.(divergent)
A solution of the equation x = g(x) is called a fixed point of g.

Example 7 The equation x2 − 5x + 4 = 0 has two roots a1 = 1 and a2 = 4


x2 + 4 √ 4
it can be written as x = or x = 5x − 4 or x =
5 5−x

Manalebish D: 13 13
x2 + 4
Let’s take x0 = 2 and x = g(x) = . Then
5
22 + 4 8
x1 = g(x0 ) = = = 1.6
5 5
2
(1.6) + 4
x2 = g(1.6) = = 1.312
5
(1.312)2 + 4
x3 = g(1.312) = = 1.144
5
(1.144)2 + 4
x4 = g(1.144) = = 1.062
5
x5 = 1.025 x6 = 1.010 x7 = 1.004

which converges to the root a1 = 1


To obtain the second root a2 = 4 If we choose x0 = 5 then
52 + 4
x1 = = 5.8
5
(5.8)2 + 4
x2 = = 7.528
5
x3 = 12.134

Which diverges from 4

12

y=(x2+4)/5
10

6
y=x

−2

−4
−3 −2 −1 0 1 2 3 4 5 6 7

Note 1 From the graph convergence depends on the fact that in a neighbor-
hood I of a solution, the slope of the curve y = g(x) is less than the slope of
y = x(i.e. |g ′ (x)| < 1 for x ∈ I).

Manalebish D: 14 14
Remark 2.4.1 Possible algorithm for this particular question is
%F i x e d p o i n t i t e r a t i o n Method
%f i n d r o o t s o f xˆ2−5x+4 u s i n g F i x e d p o i n t i t e r a t i o n method and p l o t e r r o r
f = @( x ) ( x ˆ2+4)/5;% d e f i n i n g a f u n c t i o n
% starting value
x c u r r e n t = 2;%
i t e r = 0;% c o u n t t h e i t e r a t i o n s , s e t t i n g a maximum i n m a x i t e r
maxiter = 100;
xArray = NaN( 1 , m a x i t e r );% i n i t i a l i z e t h e a r r a y t o s t o r e our i t e r a t i o n s
% convergence tolerance
xtol = 0.001;
% b e f o r e we s t a r t , t h e e r r o r i s s e t t o be BIG . t h i s
% j u s t l e t s our w h i l e l o o p g e t t h r o u g h t h a t f i r s t i t e r a t i o n
xerr = inf ;
% the while w i l l stop i f either criterion f a i l s
w h i l e ( i t e r < m a x i t e r ) && ( x e r r > x t o l )
i t e r = i t e r + 1;
xnew = f ( x c u r r e n t ) ;
% s a v e e a ch i t e r a t i o n
xArray ( i t e r ) = xnew ;
% compute t h e d i f f e r e n c e b e t w e e n s u c c e s s i v e i t e r a t i o n s
x e r r = a b s ( xnew − x c u r r e n t ) ;
x c u r r e n t = xnew ;
end
% r e t a i n o n l y t h e e l e m e n t s o f xArray t h a t we a c t u a l l y g e n e r a t e d
xArray = xArray ( 1 : i t e r ) ;

f p r i n t f ( ’ % . 5 f \n ’ , xArray ) ;

x2 + 1
Exercise 3 Find solutions of f (x) = x2 −3x+1 = 0 using x = g(x) =
3
and x0 = 1, 2, 3

Theorem 2.4.2 (sufficient condition for convergence) Let x = a be a

Manalebish D: 15 15
solution of x = g(x) and suppose that g has a continuous derivative in some
interval I, containing a. Then if |g ′ (x)| ≤ α < 1 in I, then the iteration
process xn+1 = g(xn ) converges for any x0 ∈ I.

proof By the Mean Value Theorem of differential calculus there is a t between


x and a such that

g(x) − g(a) = g ′ (t)(x − a) ∀x ∈ I

since g(a) = a and g(xn ) = xn+1 for n = 0, 1, 2, . . . we have

|xn − a| = |g(xn−1 ) − g(a)| = |g ′ (t)||xn−1 − a|


≤ α|xn−1 − a|
≤ α2 |xn−2 − a|
..
.
≤ αn |x0 − a|

since α < 1, αn −→ 0 as n −→ ∞, and hence |xn − a| −→ 0 as n −→ ∞ i.e.


xn → a.

Remark 2.4.3 1. If g ′ (x) (or α ) is close to 0 in I, it converges quickly.


If g ′ (x) (or α ) is close to 1 in I, it converges slowly.

2. converse of the theorem is not true

counter example:- For f (x) = x2 − 5x + 4 = 0 take x = g(x) = x2 − 4x + 4


with x0 = 0
g ′ (x) = 2x − 4, g ′ (0) = −4 |g ′ (0)| = 4 > 1 yet x1 = g(x0 ) =
g(0) = 4 converges to a2 = 4 for f (x) = x2 − 5x + 4 = 0 with x = g(x) =
x2 + 4 ′ 2x
, g (x) =
5 5

Manalebish D: 16 16
 
2x −5 5 −5 5
|g ′ (x)| < 1 ⇔ −1 < <1⇔ < x < i.e. I = ,
5 2 2 2 2
4
Thus x0 = 2 ∈ I with g ′ (2) = close to 1 Thus xn → a1 = 1 slowly where
5
as x0 = 5 ̸∈ I need not converge to a2 = 4.

Manalebish D: 17 17
Example 8 Find the roots of 4x − 4 sin x = 1

write f (x) = 0 as x = sin x + 0.25 = g(x) with |g ′ (x)| = | cos x| < 1 say for
1 < x < 1.3 choosing x0 = 1.2 we have

x1 = sin(1.2) + 0.25 = 1.182


x2 = sin(1.182) + 0.25 = 1.175
x3 = sin(1.175) + 0.25 = 1.173
x4 = sin(1.173) + 0.25 = 1.172

Thus a = 1.172 (correct to 3D) with an error ε ≤ 12 10−3 = 0.0005 i.e. a =


1.172 ± 0.0005.

Example 9 Find the roots of f (x) = ex − 3x = 0


ex ex
⇔ ex = 3x ⇒ x = = g(x) with |g ′ (x)| = | | < 1 ⇒ x < ln 3 ≈ 1.1
3 3
To find a1 take x0 = 0 then

x1 = 0.3̇
x2 = 0.465
x3 = 0.53
.
= ..
x7 = 0.610

But a2 ̸∈ I suppose x0 = 2

x1 = 2.46
x2 = 3.91
x3 = 16.7

diverges

Manalebish D: 18 18
So to obtain a2 , take x = g(x) = 4x − ex with g ′ (x) = 4 − ex

|g ′ (x)| = |4 − ex | < 1 ⇔ −1 < 4 − ex < 1


−5 < −ex < −3
3 < ex < 5
ln 3 < x < ln 5 x ∈ (1.1, 1.6)

Then take x0 = 1.5

x1 = 4(1.5) − e1.5 = 1.52


x2 = 4(1.52) − e1.52 = 1.51
x3 = 4(1.51) − e1.51 = 1.513
x4 = 4(1.513) − e1.513 = 1.512

Hence convergent

Exercise 4 Find solutions to the following by iteration method

1. f (x) = ex − 3x = 0 with x = g(x) = ex − 2x x0 = 1, 2, . . .


1
2. f (x) = x3 + x − 1 = 0 with x = g1 (x) = 2
and x = g2 (x) = 1 − x3
1+x
x0 = 1

2.5 The Newton Raphson method


• This method is simple and converges quickly

• To solve an equation f (x) = 0 where f has a continuous derivative f ′

• We approximate the graph of f by appropriate tangents.


Let x0 be an initial guess, then Draw the line tangent to the graph of

Manalebish D: 19 19
f at the point (x0 , f (x0 )).
Let x1 be the point of intersection of the tangent line with the x-axis.

The slope of the tangent to f at x0 is


f (x0 ) f (x0 )
tan β = f ′ (x0 ) = =⇒ x1 = x0 − ′
x0 − x1 f (x0 )
Then we continue the process by computing
f (x1 ) f (xn )
x2 = x1 − ′ and in general xn+1 = xn − ′ until say |f (xn )| < ε,
f (x1 ) f (xn )
given

Remark 2.5.1 If we expand f (x) in a Taylor series and express f (xn+1 ) at


xn we get

′ ′′ (xn+1 − xn )2
f (xn+1 ) = f (xn ) + f (xn )(xn+1 − xn ) + f (xn ) + ···
2!
If xn+1 is close to the actual root a, f (xn+1 ) = 0 and xn ≈ xn+1 so that
(xn+1 − xn )2 and all higher powers can be neglected which gives

0 = f (xn ) + f ′ (xn )(xn+1 − xn )


f (xn )
=⇒ xn+1 = xn +
f ′ (xn )
Example 10 Find the roots of f (x) = ex − 3x = 0 starting from x0 = 0 and
x0 = 2

Manalebish D: 20 20
Solution:-

f ′ (x) = ex − 3
f (xn )
xn+1 = xn − ′
f (x )
 xnn 
e − 3xn xn (xn − 1)
= xn − = e
exn − 3 exn −3
e0 (0 − 1) −1
for x0 = 0 x1 = = = 0.5
e0 − 3 −2
e0.5 (0.5 − 1)
x2 = = 0.61
e0.5 − 3
x3 = 0.619

e2 (2 − 1)
for x0 = 2 x1 = = 1.6835
e2 − 3
x2 = 1.5435
x3 = 1.5134
x4 = 1.512

Remark 2.5.2 Possible algorithm for this particular question is


% Newton Raphson Method
f=@( x ) e x p ( x )−3∗ x ; % define the functions
d f=@( x ) e xp ( x ) −3; %t h i s i s t h e d e r i v a t i v e o f t h e a b o v e f u n c t i o n
% g i v e l o w e r l i m i t ’ a ’ and u p p e r l i m i t ’ b ’
a =0; b =1;
Es = 0 . 0 1 ; %a l l o w e d r e l a t i v e e r r o r
i t e r =0;
x=a ;
w h i l e i t e r <100
x1=x −( f ( x )/ d f ( x ) ) ;
x=x1 ;
f p r i n t f ( ’ \ n T h e r e f o r e , x1=%.5 f \n Here , f ( x1 )=%.5 f ’ , x1 , f ( x1 ) )

i t e r = i t e r +1;

Manalebish D: 21 21
if iter > 1
i f a b s ( x )>0
Ea=a b s ( ( x−x o l d )/ x ) ;
i f a b s ( Ea)<Es
break
end
end
end

x o l d=x ;
end

Example 11 Find the root of f (x) = x − 2 sin x = 0 near x0 = 2

Solution:-

f ′ (x) = 1 − 2 cos x (2.6)


 
xn − 2 sin xn 2(sin xn − xn cos xn )
xn+ = xn − = (2.7)
1 − 2 cos xn 1 − 2 cos xn
2(sin 2 − 2 cos 2)
x1 = = 1.901 (2.8)
1 − 2 cos 2
x2 = 1.896 (2.9)

Exercise 5 1. Approximate 2 using Newton Raphson method

2. Find a root of f (x) = x3 + x − 1 = 0 from x0 = 1

Manalebish D: 22 22

You might also like