Numerical Methods II
Numerical Methods II
Numerical Methods II
Preliminaries:
Theorem : If f(x) is continuous on some interval [a, b] and f(a) f(b) < 0, then the equation
f(x) = 0 has at least one real root or an odd number of real roots in the interval (a, b).
BISECTION METHOD
For definiteness, let 𝑓(𝑎) be negative and 𝑓(𝑏) be positive. Then the root lies between a
and b and let its approximate value be given by
ab
x0 . If f ( x0 ) 0 , we conclude that x0 is a root of the equation f ( x) 0, Otherwise
2
the root lies between x0 and b or between x0 and a depending on whether f ( x0 ) is
ba
positive or negative. We designate this new interval as [ a1 , b1 ] whose length is , as
2
1
before this is bisected at x1 and the new interval will be exactly half the length of the
previous one. We repeat this process until the latest interval (which contains the root) is
the small as desired, say . It is clear that the interval width will reduced by a factor of
one-half at each step and at the end of the nth step, the new interval will be [an , bn ] of
ba
length , we then have
2n
ba
log
ba
which gives on simplification n ……….(1)
2n log e 2
Inequality (1) gives the number of iterations required to achieve accuracy . For example,
if b a 1 and = 0.001, then it can be seen that n ≥10 . …….. (2)
It should be noted that this method always succeeds : If there are more roots than one in
the interval, bisection method finds one of the roots. It can be easily programmed using the
following computational steps.
2
1. Choose two real numbers a and b such that f(a) f(b) < 0.
( a b)
2. Set xr .
2
3. (a) If f (a) f ( xr ) 0 , the root lies in the interval (a, xr ). Then, set b = xr, and go to
step 2
(b) If f (a) f ( xr ) 0 , the root lies in the interval (xr, b ). Then, set a =xr, and go to
step2
(c) If f (a) f ( xr ) 0 , it means that xr is a root of the equation f(x) = 0 and the
computation may be terminated.
In practical problems, the roots may not be exact so that the condition (c) above is never
satisfied. In such a case we need to adapt a criterion for deciding when to terminate the
computations. A convenient criterion is to compute the percentage error r defined by
xr1 xr
r 100% …………………………………….. (3)
xr1
Where xr1 is the new value of xr . The computations can be terminated when r becomes
less than a prescribed tolerance p . In addition the maximum number of iterations may also
be specified in advance.
Problems:
Solution: Let f ( x) x3 2 x 5
3
23
x0 2. 5
Hence the root lies between 2 and 3 and we take 2
𝑛 𝑎 𝑏 𝑥 𝑓(𝑥)
1 2 3 2.5 5.6250
12 2.09424 2.09473
At n =12, it is seen that the difference between two successive iterates is 0.0005, which is
less than 0.001. Thus this result agrees with condition (2)
4
Example 2. Find the positive real root of the equation xe x 1 , which lies between 0
and 1.
0 1
x0 0. 5
It follows that the root lies between 0 and 1 and we take 2
Since f(0.5) is negative, it follows that the root lies between 0.5 and 1. Hence the new
root is 0.75, x1 = 0.75, using the values of x0 and x1, we calculate €
x1 x
1 100 33.33%
x1
Again we find that f (0.75) , is positive and hence the root lies between 0.5 and 0.75
ie x2 0.625
0.625 0.75
1 100 20%
0.625
Proceeding in this way, the following table is constructed where only the sign of the
function value is indicated. The prescribed tolerance is 0.05%
1 0 1 0.5 negative --
5
5 0.5625 0.625 0.5938 positive 5.263
After 12 iterates the error r finally satisfies the prescribed tolerance, viz., 0.05%. Hence
the required root is 0.567 and it is easily seen that this value is correct to three decimal
places.
Exercises:
Using bisection method, find the approximate roots of the following equations in the
specified intervals.
6
REGULA FALSI METHOD / METOD OF FALSE POSITION:
The method is also called linear interpolation or chord method. This is the oldest method
for finding the real root of the nonlinear equation f(x) = 0 and closely resembles the
bisection method. This method is also known as method of chords, we choose two points
a and b such that f(a) and f(b) are of opposite signs. Hence the root must lie in the interval
[a, b]. We know the equation of chord joining the two points [𝑎, 𝑓(𝑎)] and [ 𝑏, 𝑓(𝑏)] is
given by
y f (a ) f (b) f (a)
xa ba
……………………….(1)
The method consists in replacing the part of the curve between the points [ 𝑎, 𝑓(𝑎)] and
[ 𝑏, 𝑓(𝑏)] by means of the chord joining the points, and taking the point of intersection of
the chord with the x- axis as an approximation to the root. The point of intersection in the
present case is obtained by using 𝑦 = 0 in equation (1) thus we obtain
a f (b) b f (a)
x1
ba …………..(2)
Which is the first approximate root of the equation f(x) = 0. If now f(x1) and f(a) are of
opposite signs, then the root lies between ‘a’ and x1, and we replace b by x1 in (2) and
obtain the next approximation. Otherwise we replace a by x1 and generate the next
approximations. The procedure is repeated till the root is obtained to the desired accuracy.
The following figure gives a graphical representation of the method.
7
1.Compute the real root of the equation x log x10 1.2 0 by the method of false position.
Carry out three iteration.
The real root lies in the interval (2, 3) and from the values of f(x) at x = 2, 3 and we expect
the root in the neighbourhood of 3 and let us find ( a, b) for applying the method such
that ( b - a) is small enough.
The root lies between (2.7, 2.8) the successive approximations are obtained as follows:
8
I iteration:
II iteration:
III iteration:
Comparing x2 and x3 we have the same value up to the places of fourth decimal.
2. Find the real root of the equation f ( x) cosx 1 3x by Regula false method,
The real root lies in the interval (0, 1) and we expect the root in the neighbourhood of 1
f (0.6) 0.0253 0, f (0.7) 0.3352 0
9
I iteration:
II iteration:
Exercises:
1. Using Regula falsi method, find the approximate roots of the following equations
x3 2 x 5 0 correct to four decimal places.
2. Show that a real root of the equation tan x tanh x 0 lies between 2 and 3 by using
Regula falsi method, by taking 5 approximations.
3. Find the real root of the equation cos x 3x 1 correct to three decimal places by
using Regula falsi method.
4. Find the real root of the equation x4 x3 2 x2 6 x 4 0 in (2, 3) carryout five steps
by using Regula falsi method.
10
The Newton- Raphson Method
Introduction:
Around 1669, Newton originated the idea of solving the non-linear equations
numerically. A systematic and simple method was introduced by Raphson in 1690. So
the iteration method is called Newton - Raphson Method.
Now
f ( x1 ) 0 f ( x0 h) 0
h 2 ''
f ( x0 ) h f ' ( x0 ) f ( x0 ) ........ 0 by Taylor ' s theorem
2!
neglecting h 2 and higher powers of h we get
f (x )
f ( x0 ) h f ' ( x0 ) 0 h ' 0
f ( x0 )
f ( x0 )
Thus x1 x0 is close to the root of f ( x ) 0
f ' ( x0 )
Starting with x1 still closer value of the root of f ( x) 0
is given by
f ( x1 )
x2 x1 continuing this process
f ' ( x1 )
we get values which are closer and closer to the actual root.
and these steps are called iterations.
11
Example 1: Find the root of x3 5x 3 0 by Newton – Raphson method.
Solution : The given equation is f ( x) x3 5x 3 0 .
Here f (1) = - 1 < 0 and f (2) = 1 > 0 so root lies between 1 and 2
Let x0 = 1.5 and f '( x) 3x 2 5
Example 2: Use Newton - Raphson method to find the real root of 3𝑥 = 𝑐𝑜𝑠𝑥 + 1.
Solution: The given equation is f ( x) 3x cos x 1 0
f(0) = -2 < 0 and f(1) = 1.4597 > 0
Clearly root lies between 0 and 1. We take x0 = 0.6 as the root close to unity.
Also f '( x) 3 sin x
By Newton’s formula
f ( xn )
xn 1 xn
f '( xn )
3 xn cos xn 1
xn
3 sin xn
xn sin xn cos xn 1
, n 0,1, 2, 3.....
3 sin xn
12
For n = 0, x1 = 0.6071, x2 = 0.6071 since x1 = x2
So 0.6071 is the root correct to four decimal places.
Exercises:
Use Newton - Raphson method to solve the following equations correct to three decimal
places.
(i) x log x 2 (ii) cos x x e x
(iii) x 4 x 13 0 (iv) e x sin x 1
𝜕𝑓 𝜕𝑓
Where 𝑓0 = 𝑓 (𝑥0 , 𝑦0 ), =( ) etc.
𝜕𝑥0 𝜕𝑥 𝑥0, 𝑦0
Solving the equation (3) for ℎ and 𝑘, we get a new approximation to the root as
𝑥1 = 𝑥0 + ℎ, 𝑦1 = 𝑦0 + 𝑘.
This process is repeated till we get the values to the desired accuracy.
Note: This method will not converge unless the staring values of the roots chosen are close
to the actual roots.
Example1: Solve the system of non-linear equations 𝑥 2 + 𝑦 = 11, 𝑦 2 + 𝑥 = 7 by
Newton’s method.
13
Solution: 𝑓 = 𝑥 2 + 𝑦 − 11, 𝑔 = 𝑦 2 + 𝑥 − 7 --------------- (1)
An initial approximation to the solution is obtained from a graph of (1), as 𝑥0 = 3.5 and
𝑦0 = −1.8.
𝜕𝑓 𝜕𝑓 𝜕𝑔 𝜕𝑔
= 2𝑥, = 1, = 1, = 2𝑦.
𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦
By Newton’s equations (3),
7ℎ + 𝑘 = 0.55, ℎ − 3.6𝑘 = 0.26.
Solving these, we get ℎ = 0.0855, 𝑘 = −0.0485.
Therefore the better approximation to the root is
𝑥1 = 𝑥0 + ℎ = 3.5855, 𝑦1 = 𝑦0 + 𝑘 = −1.8485.
Repeating the above process, replacing (𝑥0 , 𝑦0 ) by (𝑥1 , 𝑦1 ), we obtain 𝑥2 = 3.5844, 𝑦2 =
−1.8482.
Exercise:
1. Use Newton-Raphson method to solve the equations: 𝑥 2 + 𝑦 = 5, 𝑦 2 + 𝑥 = 3.
2. Solve the equations 2𝑥 2 + 3𝑥𝑦 + 𝑦 2 = 3, 4𝑥 2 + 2𝑥𝑦 + 𝑦 2 = 30 correct to three
decimal places, using Newton-Raphson method, given that 𝑥0 = −3 and 𝑦0 = 2.
Introduction:
The analytic methods of solving differential equations are applicable only to limited class
of equations. The differential equations appearing in physical problems do not fall into the
category of familiar types. Therefore one has to study numerical method to solve such
equations. Basically a first order differential equation of the form
y = f(x,y), y(x0 ) = y0 ………………….. (1)
is to be solved numerically by different methods. The methods for the solution of the
initial value problem (1) can be classified mainly into two types. They are single step
method and multi-step methods. In single step methods, the solution at any point Xi+1 is
14
obtained using the solution at only the previous point xi where as in multistep method the
solution is obtained using the solution at a number of previous points. These methods yield
the solution in one of the two forms:
(i) A series for y in terms of powers of x, from which the value of y can be obtained
by direct substitution.
(ii) A set of tabulated values of x and y.
15
𝑥2 𝑥3
𝑦 =1+𝑥+ (5) + (12) +……….. .
2! 3!
(0.1)2 (0.1)3
Therefore y(0.1)= 𝑦(0.1) = 1 + 0.1 + ( 5) + (12) = 1.127 correct to 3
2! 3!
Decimal places.
Example 2. Use Taylor series method to find y(0.1) and y (0.2) from the equation 𝑦 ′ =
−𝑥𝑦 with y(0)=1.
Solution. Given 𝑦 ′ = −𝑥𝑦. Therefore 𝑦 ′ (0) = 0.
𝑦 ′′ = −𝑥𝑦 ′ − 𝑦 , 𝑦 ′′ (0) = −1
𝑦 ′′′ = −𝑥𝑦 ′′ − 2𝑦′ , 𝑦′′′ (0) = 0
𝑦 𝑖𝑣 = −𝑥𝑦 ′′′ − 3𝑦′ , 𝑦 𝑖𝑣 (0) = 3 Similarly, 𝑦 𝑣 (0) = 0, 𝑦 𝑣𝑖 (0) = −15
Substituting these values in the above Taylor series expansion (2),we get
𝑥2 𝑥3 𝑥4 𝑥5 6
𝑦 =1+0+ (−1) + (0) + (3) + (0) + (−15) +……….. .
2! 3! 4! 5! 6!
𝑥2 𝑥4 6
=1− + − +………
2 8 48
Euler’s Method:
In Taylor series method, we express a series for y in terms of powers of x, from
which the value of y can be obtained by direct substitution. As the approximation
is poor, we derive Euler method by using Taylor series method, where the values of
y are computed by short steps ahead for equal intervals h of the independent variable.
dy
Consider the differential equation f (x, y)
dx
with the initial condition y(x 0 ) y0 .
16
If y(x) is the exact solution of the above equation, then the Taylor’s series for
(x x 0 )2 11
y(x) y0 (x x 0 )y01 y0 . . .
2!
Neglecting second and higher order terms, we get
y(x) y0 (x x 0 )y0' .
Taking x1 x 0 h , we get y1 y0 h f (x 0 , y0 ) .
Similarly y2 y1 h f (x1 , y1 ) .
Solution. 𝑓(𝑥, 𝑦) = 𝑥 + 2𝑦 .
𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 ) = 𝑦𝑛 + 0.1𝑓 (𝑥 + 2𝑦) Let us take n=10 and h=0.1.
The various calculations are arranged as follows.
1 1 3 1+0.1(3)=1.3
17
1.4 2.67 6.74 3.34
2.0 9.55
18
Solution : Here 𝑓 (𝑥, 𝑦) = 𝑥 + √𝑦 x0=0, y0=1. Let x1=x0+h = 0.2 and x2=x1+h = 0.4.
We have to find y1=y(x1)=y(0.2) and y2=y(x2)=y(0.4).
Now, f(x0,y0)=f(0.1)=0-1= -1.
Therefore by Euler’s formula, y1(0)=y0+h f(x0,y0)= 1 + (0.2)(0+1)=1.2
(1) ℎ (0)
By Modified Euler’s formula, 𝑦1 = 𝑦0 + {𝑓 (𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )}
2
0.2
=1+ {(0 + √1) + 0.2 + √1.2} = 1.2295
2
Note: In Euler method, the interval length h should be kept small and hence
these methods can be applied for tabulating y over a limited range only.
Exercise
1. Using Euler’s method, find the approximate value of y, when x=0.2 by taking
𝑑𝑦
step length h=0.1. Given that = 1 − 𝑦, 𝑦(0) = 1.
𝑑𝑥
𝑑𝑦
2. Solve the equation = 𝑥(1 + 𝑦), 𝑦(1) = 1 at x = 1.1 taking step length
𝑑𝑥
h=0.05.
Runge-Kutta Method
Introduction:
Euler’s method is less efficient in practical problems since it requires ‘h’ to be small for
obtaining reasonable accuracy. The Runge-Kutta methods are designed to give greater
accuracy and they possess the advantage of requiring only the function value at some
selected points on the subinterval. The basic idea of R-K methods is to approximate the
19
integral by a weighted average of slopes and approximate slopes at a number of points in
the interval [ xi, x i+1]
𝐝𝐲
Consider the initial value problem = 𝐟(𝐱, 𝐲), 𝐲(𝐱 𝟎 ) = 𝐲𝟎 .
𝐝𝐱
𝟏
That is the value of y at x = xi is : 𝐲𝟏 = 𝐲𝟎 + (𝐤 𝟏 + 𝐤 𝟐 ).
𝟐
Where, 𝐤 𝟏 = 𝐡𝐟(𝐱 𝟎 , 𝐲𝟎 )
𝐤 𝟐 = 𝐡𝐟(𝐱 𝟎 + 𝐡, 𝐲𝟎 + 𝐤 𝟏 ).
Example 1. Apply RK method of order two to find the value of y when x=0.2, given that
𝑑𝑦
= 𝑥 + 𝑦, y=1 when x=0.
𝑑𝑥
20
Where 𝐤 𝟏 = 𝐡𝐟(𝐱 𝟎 , 𝐲𝟎 )
𝐡 𝐤𝟏
𝐤 𝟐 = 𝐡𝐟(𝐱 𝟎 + , 𝐲𝟎 + )
𝟐 𝟐
𝐡 𝐤𝟐
𝐤 𝟑 = 𝐡𝐟(𝐱 𝟎 + , 𝐲𝟎 + )
𝟐 𝟐
𝐤 𝟒 = 𝐡𝐟(𝐱 𝟎 + 𝐡, 𝐲𝟎 + 𝐤 𝟑 ).
Example 1. Using 4th order Runge Kutta method , solve 𝑦 ′ = 𝑥 + 𝑦 2 with y(0)=1 at x=
0.2 in steps of length h=0.1
Solution. Here 𝑓 (𝑥, 𝑦) = 𝑥 + 𝑦 2 x0=0, y0=1 , h=0.1, x1= 0+h=0.1,
x2 = 0.1+0.1=0.2 To fond y2=y(x2)=y(0.2).
k1 = h f(x0, y0)=(0.1)(0+12)=0.1
k2 = h f(x0+h/2, y0+k1/2)=(0.1)f(0.05, 1.05)=0.11525
k3 = h f(x0+h/2, y0+k2/2)=(0.1)f(0.05, 1.057625)=0.116857
k4 = h f(x0+h, y0+k3)=(0.1)f(0.1, 1.116857)=0.13474.
𝟏
Then using RK formula, 𝐲𝟏 = 𝐲(𝐱 𝟎 + 𝐡) = 𝐲𝟎 + (𝐤 𝟏 + 𝟐𝐤 𝟐 + 𝟐𝐤 𝟑 + 𝐤 𝟒 ) we get
𝟔
k1 = h f(x1, y1)=(0.1)f(0.1,1.1165)=0.134657
k2 = h f(x0+h/2, y0+k1/2)=(0.1)f(0.15, 1.1838)=0.15514
k3 = h f(x0+h/2, y0+k2/2)=(0.1)f(0.15, 1.1941)=0.15759
k4 = h f(x0+h, y0+k3)=(0.1)f(0.2, 1.27409)=0.18233. Then using RK formula, y2 =
1
y(x1 + h) = y1 + (k1 + 2k 2 + 2k 3 + k 4 ) we get
6
Example 2. Using 4th order Runge Kutta method , solve 𝑦 ′ = 1 + 𝑦 2 with y(0)=0 at x=
0.4 in steps of length h=0.2
Solution. Here 𝑓 (𝑥, 𝑦) = 1 + 𝑦 2 x0=0, y0=0 , h=0.2, x1= 0+h=0.2,
x2 = 0.4 To fond y2=y(x2)=y(0.4).
21
k1 = h f(x0, y0)=(0.2)f(0,0)=0.2
k2 = h f(x0+h/2, y0+k1/2)=h{1+(y0+k1/2)}2 =(0.2){1+(0.1)2}=0.202
k3 = h f(x0+h/2, y0+k2/2)= (0.2){1+(0.101)2}=0.2020402
k4 = h f(x0+h, y0+k3)= (0.2){1+(0.2020402)2}=0.208164. Then using RK formula, y1 =
1
y(x0 + h) = y0 + (k1 + 2k 2 + 2k 3 + k 4 ) we get
6
we get
y2 = y(0.4)= 0.2027074+1/6(0.208218 +2 (0.2188272 +2(0.21948319) + 0.235649) )
=0.42279.
Exercise :
22