Numerrical Lecture Note
Numerrical Lecture Note
Department of Mathematics
Lecture Note
Numerical Analysis
Tadesse Nigisa
May 3, 2017
Contents
3 System of equation 32
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.2 Direct Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.2.1 Gauss Elimination Method . . . . . . . . . . . . . . . 35
3.2.2 Gauss-Jordan Method . . . . . . . . . . . . . . . . . . 41
3.2.3 Matrix Decomposition . . . . . . . . . . . . . . . . . . 43
3.3 Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.3.1 Gauss-Jacobi Iteration Method . . . . . . . . . . . . . 50
3.3.2 Gauss-Seidel Iteration Method . . . . . . . . . . . . . . 55
3.4 Solving System of non-linear Equations using Newtons Method 60
4 Curve Fitting 63
4.1 Least squares Method for Fitting . . . . . . . . . . . . . . . . 63
4.1.1 Linear least squares Regression . . . . . . . . . . . . . 63
4.1.2 power least square regression . . . . . . . . . . . . . . . 66
1
4.1.3 Polynomial least square regression . . . . . . . . . . . . 68
4.2 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.2.1 Interpolation with equally spaced intervals . . . . . . . 75
4.2.2 Interpolation with unequal interval . . . . . . . . . . . 81
2
Chapter 1
1.1 Introduction
What is Numerical Analysis?
The aim of the field numerical analysis is to provide convenient methods
for obtaining useful solutions to mathematical problems. Such mathemat-
ical problems can be formulated, for example, in terms of an algebraic or
transcendental equation, an ordinary or partial differential equation, or an
integral equation, or in terms of a set of such equations.
3
1.3 Common types of errors:
Inherent errors:
• Arise either due to the given data being approximate or due to the lim-
itations of mathematical tables, calculators, or the digital computers.
Rounding errors:
• Arise from the process of rounding off the numbers during the compu-
tation.
Truncation errors:
Hence,
Rounding error=13.66-13.658=0.002;and
Truncation error=13.658-13.65=0.008.
4
Ea |X−X|
• Relative error, Er = |X|
= |X|
; and
1. The relative and percentage errors are independent of the units used.
5
1.5 Approximations of Errors
Errors in the Approximation of a Function Let y = f (x1 , x2 ) be a
function of two variables x1 and x2 . If δx1 and δx2 be the errors in x1 and
x2 , respectively, then the error δy in y is given by
6
Example 1.5.2 Find the maximum relative error in the function y = axm 1 m2 mn
1 x2 · · · xn ,
where a, m1 , m2 , · · · , mn are constants.
Solution: ln(y) = ln(a) + m1 ln(x1 ) + m2 ln(x2 ) + · · · + mn ln(xn )
∂y 1 1 ∂y ∂y
Therefore, y1 ∂x 1
=m ,
x1 y ∂x2
=m
x2
2
· · · , y1 ∂xn
=mn
xn
.
∂y δx1 ∂y δx2 ∂y δxn
Hence, Er ≈ ∂x1 y
+ ∂x2 y
+ ··· + ∂xn y
.
δx1 δx2 δxn
= m1 + m2 + · · · + mn .
x1 x2 xn
Since the errors δx1 , δx2 , · · · , δxn may be positive or negative, we take the
absolute values of the terms on the right side. This gives:
δx1 δx2 δxn
(Er )max = |m1 | + |m2 | + · · · + |mn |.
x1 x2 xn
Remark: Taking a = 1, m1 = m2 = · · · = mn = 1, we have y = x1 x2 · · · xn .
Then
δx1 δx2 δxn
Er = + + ··· + .
x1 x2 xn
Thus the relative error of a product of n numbers is approximately equal to
the algebraic sum of their relative errors.
The Taylors series for f(x) at x=a with a remainder after n terms is
(x − a)2 00 (x − a)n−1 (n−1)
f (x) = f (a+x−a) = f (a)+(x−a)f 0 (a)+ f (a)+· · ·+ f (a)+Rn (x)
2! (n − 1)!
(1.5)
n
where Rn (x) = (x−a)
n!
f n (θ), a < θ < x.
If the series is convergent, then Rn (x) → 0 as n → ∞ and hence if f (x) is
approximated by the first n terms of this series, then the maximum error will
be given by the remainder term Rn (x). Moreover, if the accuracy required
in a series approximation is pre-assigned, then we can find n, the number of
terms which would yield the desired accuracy.
Example 1.5.3 : Find the number of terms of the exponential series such
that their sum gives the value of ex correct to six decimal places at x = 1.
Solution: The Taylors series for ex at x = 0 is
x2 x 3 xn−1
ex = 1 + x + + + ··· + + Rn (x) · · · (i)
2! 3! (n − 1)!
7
n
where Rn (x) = xn eθ , 0 < θ < x. Therefore, the maximum absolute error (at
n n
θ = x) = xn! ex ; and the maximum relative error = xn!
Hence, (Er )max at x=1 = n!1 .
For a six decimal place accuracy at x=1, we have
1 1
(Er )max = < × 10−6
n! 2
⇒ n! > 2 × 106
Thus the minimum integer value of n which satisfy this condition is n=10.
Thus we need 10 terms of the series (i) in order that its sum is correct to 6
decimal places.
Propagated error:
Stability:
• If errors made at initial step die out (decrease) as the algorithm con-
tinuous, the algorithm is said to be stable.
8
Chapter 2
Solutions of non-linear
Equations
f (x) = 0
9
Figure 2.1: geometrical representation
f 00 (x) = 6x − 6, f 00 (2) = 6 6= 0.
We shall derive methods for finding only the real roots. The methods for
finding the roots are classified as (i) direct methods ,and (ii) iterative methods
Direct Methods: These methods give the exact value of all the roots in
10
a finite number of steps( disregarding the round off errors).Therefore , for
any direct method , we can give the total number of operations ( addition,
subtraction divisions and multiplications ) This number is the operational
count of the method.
For example ,the roots of the quadratic equation ax2 + bx + c = 0, a = 0 ,
can be obtained using the method
1 √
x = [−b ± b2 − 4ac]
2a
For this method we can give the count of total number of operations. There
are direct methods for finding the roots of a cubic and fourth degree polyno-
mial. However these methods are difficult to use. Direct methods for finding
the roots of polynomial equations of degree greater than 4 or transcendental
equations are not available in literature
Iterative Methods: These methods are based on the idea of successive
approximations. We start with one or two initial approximations to the root
and obtain a sequence of approximations x0 , x1 , x2 , · · · , xk , · · · which in the
limit as k → ∞ , converge to the exact root α. An iterative method for
finding a root of the equation f (x) = 0 can be obtained as
xk+1 = ϕ(xk ), k = 0, 1, 2, . . .
This method uses one initial approximation to the root x0 . The sequence of
approximations is given by
x1 = ϕ(x0 ), x2 = ϕ(x1 ), x3 = ϕ(x2 ), · · · .
The function ϕ is called the iteration function and x0 is called the initial
approximation.
If the method uses two initial approximations x0 , x1 to the root , then we can
write the method as xk+1 = ϕ(xk−1 , xk ) k = 1, 2, · · · Convergence of iterative
methods : The sequence of iterates ,xk , is said to converge to the exact root
α , if
limk→∞ xk = α
Remark 2.2 Given one or two initial approximations to the root, we re-
quire a suitable iteration function α for a given function f (x) , such that the
sequence of iterates,{xk } , converge to the exact root α.
Further , we also require a suitable criterion to terminate the iteration.
11
1. The equation f (x) = 0 is satisfied to a given accuracy or f (xk ) is
bounded by an error tolerance . |f (xk )| ≤ .
|xk+1 − xk | ≤ .
ii) We write the equation f (−x) = pn (−x) = 0 and count the number of
changes of signs in the coefficients of pn (−x). The number of negative
roots can not exceed the number of changes of signs. For example ,
if there are 4 changes of signs, then the equation may have 4 negative
roots or 2. If there are 3 changes of signs , then the equation may have
3 negative roots or definitely one negative root.
12
Theorem 1
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).
i. 8x3 − 12x2 − 2x + 3 = 0
x -2 -1 0 1 2 3
f (x) -105 -15 3 -3 15 105
x -3 -2 0 1 2 3
f (x) -101 -35 -5 -5 9 55
13
From the table there is 1 positive real root in the interval (1, 2). The equation
has no negative real root .
Example 2.1.2 Locate the smallest positive real root of the equations
i. xex = cosx
ii. tanx = 2x
Solution
14
Figure 2.2: Bisection method
Remark 2.3 Since the new interval containing the root is exactly half the
length of the previous one , the interval width is reduced by a factor of 21 at
each step. Therefore at the end of the nth step , the interval will be of length
b−a
(2.2)
2n
If on repeating this process n times , the latest interval is as small as given
ε ,then
b−a ln( b−a )
2n ≤ ε or n ≥ ln2
ε
Example 2.2.1 Find a root of the equation x3 −4x−9 = 0 using the bisection
method correct to 3 decimal places.
15
x5 = 2.71875, x6 = 2.70313
x7 = 2.71094, x8 = 2.70703
x9 = 2.70508, x10 = 2.70605
x11 = 2.70654
Since |x11 − x10 | = 0.00012 < 0.0005, the required root is x ≈ x11 = 2.70654.
16
Now, if f (x0 )f (x2 ) < 0 , then the root lies in the interval (x0 , x2 ). Otherwise,
the root lies in the interval (x2 , x1 ). The iteration is continued using the
interval in which the root lies, until the required accuracy criterion is satisfied.
Remark: At the start of each iteration, the required root lies in an interval,
whose length is decreasing. Hence, the method always converges.
Remark: The method of false position has a disadvantage. If the root
lies initially in the interval (x0 , x1 ), then one of the end points is fixed for
all iterations. For example, in Fig.1.2a, the left end point x0 is fixed and
the right end point moves towards the required root. Therefore, in actual
computations, the method behaves like
x0 f k − xk f 0
xk+1 = , k = 1, 2, . . .
fk − f0
In Fig.1.2b, the right end point x1 is fixed and the left end point moves
towards the required root. Therefore, in this case, in actual computations,
the method behaves like
x1 f k − xk f 1
xk+1 = , k = 2, 3, . . .
fk − f1
Example 2.3.1 Locate the intervals which contain the positive real roots of
the equation x3 − 3x + 1 = 0.
Obtain these roots correct to three decimal places, using the method of false
position.
Solution: We form the following table of values for the function f(x).
x 0 1 2 3
f (x) 1 -1 3 19
There is one positive real root in the interval (0, 1) and another in the interval
(1, 2). There is no real root for x > 2 as f (x) > 0 for all x > 2. First, we
find the root in (0, 1). We have
x0 f 1 − x1 f 0 0(−1) − 1
x2 = = = 0.5, f2 = f (x2 ) = f (0.5) = −0.375 < 0.
f1 − f0 −1 − 1
Since f (0)f (0.5) < 0 ,the root lies in the interval (0, 0.5)
x 0 f 2 − x2 f 0 0 − 0.5
x3 = = = 0.36364.
f2 − f0 −0.375 − 1
17
and
f3 = f (x3 ) = f (0.36364) = −0.04283 < 0
Since f (0)f (0.36364) < 0, the root lies in (0, 0.36364)
x0 f 3 − x3 f 0 0 − 0.36364
x4 = = = 0.34870
f3 − f0 −0.04283 − 1
and f4 = f (x4 ) = f (0.34870) = −0.00370 < 0
Since f (0)f (0.34870) < 0 the root lies in (0, 0.34870).
x0 f 4 − x4 f 0 0 − 0.34870(1)
x5 = = = 0.34741
f4 − f0 −0.00370 − 0
and f5 = f (x5 ) = f (0.34741) = −0.00030 < 0
since f (0)f (0.34741) < 0 , the root lies in (0, 0.34741)
x0 f 5 − x5 f 0 0 − 0.34741
x6 = = = 0.347306
f5 − f0 −0.00030 − 1
Now |x6 − x5 | = |0.347306 − 0.34741| = 0.000104 < 0.0005
Since the root has been computed correct to 3 decimal places the required
roots can be taken as x ≈ x6 = 0.347306 , We may give the result as 0.347 ,
even though x6 is more accurate .
Note: The left end point x = 0 is fixed for all iterations. Now we compute
the root in (1, 2).
we have x0 = 1, x1 = 2 , f0 = f (x0 ) = f (1) = −1 and f1 = f (x1 ) = f (2) = 3
Therefore
x0 f 1 − x1 f 0 3 − 2(−1)
x2 = = = 1.25
f1 − f0 3 − (−1)
f2 = f (x2 ) = f (1.25) = −0.796875
Since f (1.25)f (2) < 0, the root lies in (1.25, 2)
x2 f 1 − x1 f 2 1.25(3) − 2(−0.796875)
x3 = = = 1.407407
f1 − f2 3 − (−0.796875)
f3 = f (x3 ) = f (1.407407) = −0.434437 Since f (1.407407)f (2) < 0, the root
lies in (1.407407, 2)
x3 f 1 − x1 f 3 1.407407(3) − 2(−0.434437)
x4 = = = 1.482367
f1 − f3 3 − (−0.434437)
f4 = f (x4 ) = f (1.482367) = −0.189730
Since f (1.482367)f (2) < 0 , the root lies in the interval (1.482367, 2)
x4 f 1 − x1 f 4 1.482367(3) − 2(−0.189730)
x5 = = = 1.513156
f1 − f4 3 − (−0.189730)
18
and
f5 = f (x5 ) = f (1.513156) = −0.074884
Since f (1.513156)f (2) < 0 , the root lies in the interval (1.513156, 2)
x5 f 1 − x1 f 5 1.513156(3) − 2(−0.074884)
x6 = = = 1.525012
f1 − f5 3 − (−0.074884)
and
f6 = f (x6 ) = f (1.525012) = −0.028374
Since f (1.525012)f (2) < 0 ,the root lies in the interval (1.525012, 5)
x6 f 1 − x1 f 6 1.525012(3) − 2(−0.028374)
x7 = = = 1.529462
f1 − f6 3 − (−0.028374)
x7 f 1 − x1 f 7 1.529462(3) − 2(−0.010586)
x8 = = = 1.531116
f1 − f7 3 − (−0.010586)
x8 f 1 − x1 f 8 1.531116(3) − 2(−0.003928)
x9 = = = 1.531729
f1 − f8 3 − (−0.003928)
f (x9 ) = f (1.531729) = −0.001454.
Since, f (1.531729)f (2) < 0, the root lies in the interval (1.531729, 2).
x9 f 1 − x 1 f 9 1.531729(3) − 2(−0.001454)
x10 = = = 1.531956
f1 − f9 3 − (−0.001454)
Example 2.3.2 Find the root correct to two decimal places of the equation
xex = cosx, using the method of false position.
19
Solution Define f (x) = cosx − xex = 0. There is no negative root for the
equation.
We have f (0) = 1, f (1) = cos1 − e = −2.17798.
A root of the equation lies in the interval (0, 1). Let x0 = 0, x1 = 1. Using
the method of false position, we obtain the following results.
x0 f 1 − x1 f 0 0 − 1(1)
x2 = = = 0.31467
f1 − f0 −2.17798 − 1
and
f (x2 ) = f (0.31467) = 0.51986
Since, f (0.31467)f (1) < 0, the root lies in the interval (0.31467, 1).
x2 f 1 − x 1 f 2 0.31467(−2.17798) − 1(0.51986)
x3 = = = 0.44673
f1 − f2 −2.17798 − 0.51986
f (x3 ) = f (0.44673) = 0.20354.
Since, f (0.44673)f (1) < 0, the root lies in the interval (0.44673, 1).
x3 f 1 − x1 f 3 0.44673(2.17798) − 1(0.20354)
x4 = = = 0.49402
f1 − f3 −2.17798 − 0.20354
f (x4 ) = f (0.49402) = 0.07079.
Since, f (0.49402)f (1) < 0, the root lies in the interval (0.49402, 1).
x4 f 1 − x 1 f 4 0.49402(−2.17798) − 1(0.07079)
x5 = = = 0.50995
f1 − f4 −2.17798 − 0.07079
f (x5 ) = f (0.50995) = 0.02360.
Since, f (0.50995)f (1) < 0, the root lies in the interval (0.50995, 1).
x5 f 1 − x1 f 5 0.50995(−2.17798) − 1(0.0236)
x6 = = = 0.51520
f1 − f5 −2.17798 − 0.0236
f (x6 ) = f (0.51520) = 0.00776.
Since, f (0.51520)f (1) < 0, the root lies in the interval (0.51520, 1).
x6 f 1 − x1 f 6 0.5152(−2.17798) − 1(0.00776)
x7 = = = 0.51692.
f1 − f6 −2.17798 − 0.00776
Now, |x7 − x6 | = |0.51692 − 0.51520| ≈ 0.00172 < 0.005.
The root has been computed correct to two decimal places. The required
root can be taken as x ≈ x7 = 0.51692.
Note that the right end point x = 2 is fixed for all iterations
Exercises 2.1 Find a root of the equation x3 − 4x − 9 = 0 using regula-falsi
method correct to 3 decimal places.
20
2.4 Secant Method
This method does not require the condition f (x0 )f (x1 ) < 0 of the method.see
fig(4.3) Here also the graph of the function y = f (x) is approximated by a
secant line but at each iteration ,two most recent approximations to the root
are used to find the next approximation.Also it is not necessary that the
interval must contain the root. Taking x0 and x1 as the intial limits of the
interval the equation of the secant line through (x0 , f (x0 )) and (x1 , f (x1 )) is
f (x1 ) − f (x0 )
y − f (x1 ) = (x − x1 )
x1 − x0
Then the abscissa of the point where it crosses the x-axis (y=0) is given by
x1 − x0
x = x1 − ( )f (x1 )
f (x1 ) − f (x0 )
Remark 2.4 If f (xn ) = f (xn−1 ) ,then this method fails and shows that it
does not converge necessarily. This is a drowback of secant method . But if
the secant method once converges,its rate of convergence is faster than that
of the method of false position.
21
Example 2.4.1 Find the root of the equation cosx = xex using the secant
method correct to 4 decimal places .
y − f (x0 ) = (x − x0 )f 0 (x0 )
y − f (x0 ) = (x − x0 )f (x0 )
22
Figure 2.5: Newton Raphson Method
where f (x0 ) is the slope of the tangent to the curve at P. Setting y = 0 and
solving for x, we get
f (x0 ) 0
x = x0 − , f (x0 ) 6= 0
f 0 (x0 )
The next approximation to the root is given by
f (x0 )
x1 = x0 − , f 0 (x0 ) 6= 0
f 0 (x0 )
We repeat the procedure. The iteration method is defined as
f (xk )
xk+1 = xk − , f 0 (xk ) 6= 0
f 0 (xk )
This method is called the Newton-Raphson method or simply the Newtons
method. The method is also called the tangent method.
0 (∆x)2 00
f (xk ) + ∆xf (xk ) + f (xk ) + . . . = 0
2!
Neglecting the second and higher powers of ∆x, we obtain
or
f (xk )
∆x = −
f 0 (xk )
23
Hence, we obtain the iteration method
f (xk )
xk+1 = xk + ∆x = xk − , f 0 (xk ) 6= 0 , k = 0, 1, 2, . . .
f 0 (xk )
which is same as the method derived earlier.
Remark 2.5 Convergence of the Newtons method depends on the initial ap-
proximation to the root. If the approximation is far away from the exact root,
the method diverges (see Example 2.5.1). However, if a root lies in a small
interval (a, b) and x0 ∈ (a, b), then the method converges.
Remark 2.6 From Eq.(1.14), we observe that the method may fail when
f 0 (x) is close to zero in the neighborhood of the root. Later, in this section,
we shall give the condition for convergence of the method.
Remark 2.7 The computational cost of the method is one evaluation of the
function f (x) and one evaluation of the derivative f 0 (x), for each iteration.
Example 2.5.1 Derive the Newtons method for finding N1 , where N > 0.
1
Hence, find 17 ,using the initial approximation as (i) 0.05, (ii) 0.15. Do the
iterations converge ?
Solution: Let x = N1 or 1
x
=N Define f (x) = 1
x
− N.
Then ,f 0 (x) = − x12 .
Newtons method gives
1
f (xk ) xk
−N
xk+1 = xk − 0 = xk − = xk + (xk − N x2k ) = 2xk − N x2k
f (xk ) − x12
k
24
x2 = 2x1 − N x21 = 2(−0.0825) − 17(−0.8025)2 = −0.280706.
x3 = 2x2 − N x22 = 2(−0.280706) − 17(0.280706)2 = −1.900942.
x4 = 2x3 − N x23 = 2(−1.900942) − 17(−1.900942)2 = −65.23275.
We find that xk → −∞ as k increases.
Therefore, the iterations diverge very fast. This shows the importance of
choosing a proper initial approximation.
Example 2.5.2 Derive the Newtons method for finding the q th root of a
positive number N, N 1/q , where N > 0, q > 0.
Hence, compute 171/3 correct to four decimal places, assuming the initial
approximation as x0 = 2.
Solution : Let x = N 1/q , or xq = N. Define f (x) = xq − N.
2x31 + 17 2(2.75)3 + 17
x2 = = = 2.582645
3x21 3(2.75)2
2x32 + 17 2(2.582645)3 + 17
x3 = = = 2.571332
3x22 3(2.582645)2
2x33 + 17 2(2.571332)3 + 17
x4 = = = 2.571282.
3x23 3(2.571332)2
Now,
|x4 − x3 | = |2.571282 − 2.571332| = 0.00005.
We may take x ≈ 2.571282 as the required root correct to four decimal places
25
Example 2.5.3 Perform four iterations of the Newtons method to find the
smallest positive root of the equation f (x) = x3 − 5x + 1 = 0.
Solution: We have f (0) = 1, f (1) = 3. Since, f (0)f (1) < 0 , the smallest
positive root lies in the interval (0, 1). Applying the Newtons method, we
obtain
x3k − 5xk + 1 2x3k − 1
xk+1 = xk − = , k = 0 , 1 , 2 , ...
3x2k − 5 3x2k − 5
2x30 − 1 2(0.5)3 − 1
x1 = = = 0.176471,
3x20 − 5 3(0.5)2 − 5
2x31 − 1 2(0.176471)3 − 1
x2 = = = 0.201568,
3x21 − 5 3(0.176471)2 − 5
2x32 − 1 2(0.201568)3 − 1
x3 = = = 0.201640,
3x22 − 5 3(0.201568)2 − 5
2x33 − 1 2(0.201640)3 − 1
x4 = = = 0.201640.
3x23 − 5 3(0.201640)2 − 5
Therefore, the root correct to six decimal places is x ≈ 0.201640.
ans:x ≈ 11.594854
x = ϕ(x). (1)
There are many ways of rewriting f (x) = 0 in this form. For example,
f (x) = x3 − 5x + 1 = 0, can be rewritten in the following forms.
r
x3 + 1 1 5x − 1
x= , x = (5x − 1) 3 , x = , etc. (2)
5 x
26
Now, finding a root of f (x) = 0 is same as finding a number α such that
α = ϕ(α), that is, a fixed point of ϕ(x). A fixed point of a function ϕ is a
point α such that α = ϕ(α). This result is also called the fixed point theorem.
Using Eq.(1), the iteration method is written as
The function ϕ(x) is called the iteration function. Starting with the initial
approximation x0 , we compute the next approximations as
The stopping criterion is same as used earlier. Since, there are many ways
of writing f (x) = 0 as x = ϕ(x), it is important to know whether all or at
least one of these iteration methods converges.
Consider again, the iteration methods given in Eq.(2), for finding a root of
the equation f (x) = x3 − 5x + 1 = 0. The positive root lies in the interval
(0, 1).
x3 + 1
(i) xk+1 = k k = 0, 1, 2, ... (4)
5
With x0 = 1, we get the sequence of approximations as
27
With x0 = 1, we get the sequence of approximations as
which does not converge to the root in (0, 1). Now, we derive the condition
that the iteration function ϕ(x) should satisfy in order that the method con-
verges.
Condition of convergence
Theorem 1
proof:
The iteration method for finding a root of f (x) = 0, is written as
α = ϕ(α) (2.4)
εk = xk ,
28
(using the mean value theorem) (2.5) or
Setting k = k − 1, we get
Hence,
εk+1 = ϕ0 (tk )ϕ0 (tk−1 )εk−1 .
Using (2.5) recursively, we get
Now |ϕ0 (x)| < 1, when x is close to 1 and |ϕ(x)| > 1 in the other part
of the interval. Convergence is not guaranteed.
q
iii. We have ϕ(x) = 5x−1 x
, ϕ0 (x) = 3 1 1 .
2x 2 (5x−1) 2
Again, |ϕ0 (x)| < 1, when x is close to 1 and |ϕ0 (x)| > 1 in the other
part of the interval. Convergence is not guaranteed.
29
Example 2.6.1 Find the smallest positive root of the equation x3 − x − 10 =
0, using the general iteration method.
Solution: We have
We obtain
1
ϕ0 (x) = 2
3(x + 10) 3
We find |ϕ0 (x)| < 1 for all x in the interval (2, 3). Hence, the iteration
converges. Let x0 = 2.5. We obtain the following results.
1 1
x1 = (12.5) 3 = 2.3208, x2 = (12.3208) 3 = 2.3097,
1 1
x3 = (12.3097) 3 = 2.3090, x4 = (12.3090) 3 = 2.3089.
Since, |x4 − x3 | = |2.3089 − 2.3090| = 0.0001, we take the required root as
x ≈ 2.3089.
Example 2.6.2 Find the smallest negative root in magnitude of the equation
3x4 + x3 + 12x + 4 = 0, using the method of successive approximations.
Solution: We have
Since, f (−1)f (0) < 0, the smallest negative root in magnitude lies in the
interval (−1, 0). Write the given equation as
x(3x3 + x2 + 12) + 4 = 0,
and
4
x=− = ϕ(x)
3x3
+ x2 + 12
The iteration method is written as
4
xk+1 = −
3x3k + x2k + 12
30
We obtain
4(9x2 + 2x)
ϕ0 (x) =
(3x3 + x2 + 12)2
We find |ϕ0 (x)| < 1 for all x in the interval (−1, 0). Hence, the iteration
converges. Let x0 = −0.25. We obtain the following results.
4 4
x1 = − =− = −0.33290,
3x30 2
+ x0 + 12 3(−0.25) + (−0.25)2 + 12
3
4 4
x2 = − =− = −0.33333,
3x31 2
+ x1 + 12 3(−0.33290) + (−0.33290)2 + 12
3
4 4
x3 = − =− = −0.33333.
3x32 2
+ x2 + 12 3(−0.33333) + (−0.33333)2 + 12
3
31
Chapter 3
System of equation
3.1 Introduction
Consider a system of n linear algebraic equations in n unknowns
32
We define the following.
i. The system of equations (3.1) is consistent (has at least one solution),
if rank(A) = rank[A|b] = r. If r = n, then the system has unique
solution. If r < n, then the system has (n − r) parameter family of
infinite number of solutions.
ii. The system of equations (3.1) is inconsistent (has no solution) if
rank(A) 6= rank[A|b].
We assume that the given system is consistent. The methods of solution of
the linear algebraic system of equations (3.1) may be classified as direct and
iterative methods.
(a) Direct methods produce the exact solution after a finite number of steps
(disregarding the round-off errors). In these methods, we can determine
the total number of operations (additions, subtractions, divisions and
multiplications). This number is called the operational count of the
method.
(b) Iterative methods are based on the idea of successive approximations.
We start with an initial approximation to the solution vector x = x0 ,
and obtain a sequence of approximate vectors x0 , x1 , ·, xk , · which in the
limit as k → ∞ converge to the exact solution vector x.
Now, we derive some direct methods.
a11 x1 = b1
a22 x2 = b2
... ..
.
ann xn = bn
This system is called a diagonal system of equations. Solving directly,
we obtain
bi
xi = , aii 6= 0, i = 1, 2, ..., n.
aii
33
(b) Let A be an upper triangular matrix, A = U . That is, we consider the
system of equations U x = b as
a11 x1 + a12 x2 + · · · + a1n xn = b1
a22 x2 + · · · + a2n xn = b2
... ..
.
an−1,n−1 xn−1 + an−1,n xn = bn−1
ann xn = bn
This system is called an upper triangular system of equations. Solving for
the unknowns in the order xn , xn−1 , ..., x1 , we get
xn = abnn
n
bn−1 −an−1,n xn
xn−1 = an−1 ,n−1
··· P···
(b1 − nj=2 a1j xj )
x1 = a11
The unknowns are obtained by back substitution and this procedure is called
the back substitution method. Therefore, when the given system of equa-
tions is one of the above two forms, the solution is obtained directly.
34
3.2.1 Gauss Elimination Method
The method is based on the idea of reducing the given system of equations
Ax = b, to an upper triangular system of equations U x = z, using elementary
row operations
This reduced system U x = z, is then solved by the back substitution method
to obtain the solution vector x.
We illustrate the method using the 3 × 3 system
We write the augmented matrix [A|b] and reduce it to the following form
[A|b]−−
Gauss −−−−−−−−−→[U |z]
−−−−−elimination
The augmented matrix of the system (3.2) is
a11 a12 a13 b1
a21 a22 a23 b2 (3.3)
a31 a32 a33 b3
where
(1) a21 (1) a21 (1) a21
a22 = a22 − a12 , a23 = a23 − a13 , b2 = b2 − b1
a11 a11 a11
(1) a31 (1) a31 (1) a31
a32 = a32 − a12 , a33 = a33 − a13 , b3 = b3 − b1
a11 a11 a11
35
Second stage of elimination
(1) (1)
We assume a22 6= 0 . This element a22 in the 2 × 2 position is called
the second pivot. We use this pivot to reduce the element below this pivot
(1)
a32
in the second column as zero. Multiply the second row in (3.4) by (1) and
a22
subtract from the third row. That is, we are performing the elementary row
(1)
a32
operation R3 − ( (1) )R2 . We obtain the new augmented matrix as
a22
Where
(1) (1)
(2) (1) a32 (1) (2) (1) a32 (1)
a33 = a33 − a
(1) 23
, b 3 = b3 − b
(1) 2
a22 a22
(2)
The element a33 6= 0 is called the third pivot. This system is in the required
upper triangular form [U |z]. The solution vector x is now obtained by back
substitution. (2)
b
From the third row, we get x3 = 3(2)
a33
(1) (1)
(b2 −a23 x3 )
From the second row, we get x2 = (1) .
a(22)
(b1 −a12 x2 −a13 x3 )
From the first row, we get x1 = a11
.
In general, using a pivot, all the elements below that pivot in that column
are made zeros. Alternately, at each stage of elimination, we may also make
the pivot as 1, by dividing that particular row by the pivot.
Remark 3.1 When does the Gauss elimination method as described above
fail? It fails when any one of the pivots is zero or it is a very small number,
as the elimination progresses.
If a pivot is zero, then division by it gives over flow error, since division
by zero is not defined. If a pivot is a very small number, then division by it
introduces large round-off errors and the solution may contain large errors.
In the second stage of elimination, the second column is searched for the
largest element in magnitude among the n − 1 elements leaving the first
element, and this element is brought as the second pivot by interchanging
the second row of the augmented matrix with the later row having the largest
element in magnitude. This procedure is continued until the upper triangular
36
system is obtained. Therefore, partial pivoting is done after every stage of
elimination. There is another procedure called complete pivoting. In this
procedure, we search the entire matrix A in the augmented matrix for the
largest element in magnitude and bring it as the first pivot.
This requires not only an interchange of the rows, but also an interchange
of the positions of the variables. It is possible that the position of a variable
is changed a number of times during this pivoting. We need to keep track
of the positions of all the variables. Hence, the procedure is computationally
expensive and is not used in any software.
37
Example 3.2.1 Solve the system of equations
x1 + 10x2 − x3 = 3
2x1 + 3x2 + 20x3 = 7
10x1 − x2 + 2x3 = 4
using the Gauss elimination with partial pivoting.
Solution: We have the augmented matrix as
1 10 −1 3
2 3 20 7
10 −1 2 4
We perform the following elementary row transformations and do the elimi-
nations.
10 −1 2 4
R1 ↔ R3 : 2 3 20 7
1 10 −1 3
R2 − (R1 /5) → R2 , R3 − (R1 /10) → R3 :
10 −1 2 4
0 3.2 19.6 6.2
0 10.1 −1.2 2.6
R2 ↔ R3 :
10 −1 2 4
0 10.1 −1.2 2.6
0 3.2 19.6 6.2
R3 − (3.2/10.1)R2 → R3 :
10 1 2 4
0 101 12 26
0 0 19.98020 5.37624
Back substitution gives the solution.
5.37624
Third equation gives x3 = 19.98020 = 0.26908
38
Example 3.2.2 Solve the system of equations
4x1 + 2x3 + x4 = 8
3x1 + 2x2 + 2x3 = 7
x1 + 3x2 + 2x3 − x4 = −5
using the Gauss elimination with partial pivoting.
4 0 2 1 8
0 1 0 − 25 −14
R2 −(1/2)R1 → R2 , R3 −(3/4)R1 → R3 , R4 −(1/4)R1 → R4 : 1 3
0 2
2
− 4
1
3 5
0 3 2
− 4 −7
4 0 2 1 8
0 3 3 − 5 −7
R2 ↔ R4 : 2
0 2 1 −3
4
2 4
1
0 1 0 − 25 −14
4 0 2 1 8
0 3 3 − 5 −7
R3 − (2/3)R2 → R3 , R4 − (1/3)R2 → R4 : 0 0 −1
2
1
4
17
2 12 3
0 0 − 12 − 25 2
− 35
3
4 0 2 1 8
0 3 3 − 5 −7
R4 − R3 → R4 , : 0 0 −1
2
1
4
17
2 12 3
0 0 0 − 13 6
− 52
3
39
Using back substitution, we obtain
52 6 17 1 17 1
x4 = (− )(− ) = 8 , x3 = −2( − )x4 = −2( − ( )8) = −10
3 13 3 12 3 12
1 3 5 1 3 5
x2 = [−7 − ( )x3 + ( )x4 ] = [−7 − ( )(−10) + ( )8] = 6
3 2 4 3 2 4
1 1
x1 = [8 − 2x3 − x4 ] = [8 − 2(−10) − 8] = 5.
4 4
Exercises 3.1 Solve the system of equations
2x1 + x2 + 3x3 = 13
x1 + x2 + 3x3 = 6
using the Gauss elimination method.
x1 + 10x2 x3 = 3
40
3.2.2 Gauss-Jordan Method
The method is based on the idea of reducing the given system of equations
Ax = b, to a diagonal system of equations Ix = d, where I is the identity
matrix, using elementary row operations. We know that the solutions of both
the systems are identical. This reduced system gives the solution vector x.
This reduction is equivalent to finding the solution as x = A−1 b.
[A|b]−Gauss-Jordan
−−−−−−−−−−−− method
−−−−→[I|X]
In this case, after the eliminations are completed, we obtain the aug-
mented matrix for a 3 × 3 system as
1 0 0 d1
0 1 0 d2 (3.6)
0 0 1 d3
Elimination procedure
The first step is same as in Gauss elimination method, that is, we make the
elements below the first pivot as zeros, using the elementary row transfor-
mations. From the second step onwards, we make the elements below and
above the pivots as zeros using the elementary row transformations. Lastly,
we divide each row by its pivot so that the final augmented matrix is of the
form (3.6). Partial pivoting can also be used in the solution. We may also
make the pivots as 1 before performing the elimination.
x1 + x2 + x3 = 1
4x1 + 3x2 − x3 = 6
3x1 + 5x2 + 3x3 = 4
using the Gauss-Jordan method (i) without partial pivoting, (ii) with partial
pivoting.
Solution: We have the augmented matrix as
1 1 1 1
4 3 −1 6
3 5 3 4
41
(i) We perform the following elementary row transformations and do the
eliminations.
1 1 1 1
R2 − 4R1 → R2 , R3 − 3R1 → R3 : 0 −1 −5 2
0 2 0 1
1 0 −4 3
R1 + R2 → R1 , R3 + 2R2 → R3 : 0 −1 −5 2
0 0 −10 5
1 0 0 1
4 5
R1 − R3 → R1 , R2 − R3 → R2 : 0 −1 0 − 12
10 10
0 0 −10 5
R3
Now, making the pivots as 1, ((−R2 ), −10 ) we get
1 0 0 1
0 1 0 1
2
0 0 1 − 12
1 43 − 14 32
R1
→ R1 : 1 1 1 1
4
3 5 3 4
1 34 − 14 3
2
R2 − R1 → R2 , R3 − 3R1 → R3 : 0 41 5
4
− 12
0 114
15
4
− 12
1 43 − 41 3
4R2 15
2
2
→ R2 : 0 1 11 − 11
11
0 41 54 − 12
14 18
1 0 − 11
3 1 11
R1 − R2 → R1 , R3 − R2 → R3 : 0 1 15 11
2
− 11
4 4
0 0 10 11
5
− 11
42
14 18
1 0 − 11 11
R3 /(10/11) → R3 : 0 1 15
11
2
− 11
1
0 0 1 −2
1 0 0 1
R1 + (14/11)R3 → R1 , R2 − (15/11)R3 → R2 : 0 1 0 12
0 0 1 − 21
Therefore, the solution of the system is x1 = 1, x2 = 12 , x3 = − 12 .
Remark 3.4 Partial pivoting can also be done using the augmented matrix
[A|I]. However, we cannot first interchange the rows of A and then find the
inverse. Then, we would be finding the inverse of a different matrix.
using the Gauss-Jordan method (i) without partial pivoting, and (ii) with
partial pivoting.
AX = B.
43
Definition 3.1 An LU decomposition of a matrix A is the product of a lower
triangular matrix and an upper triangular matrix that is equal to A.
Thus write the matrix A as
A = LU
where
L11 0 0 ··· 0
L21 L22 0 ··· 0
L=
L31 L32 L33 ··· 0
.. .. .. .. ..
. . . . .
Ln1 Ln2 Ln3 ··· Lnn
U11 U12 U13 ··· U1n
0 U22 U23 ··· U2n
U =
0 0 U33 ··· U3n
.. .. .. .. ..
. . . . .
0 0 0 ··· Unn
Provided that Lii = 1 i = 1, 2, 3, · · · , n Doolittle’s method and
Uii = 1 i = 1, 2, 3, · · · , n Crout’s method
Note: One can consider Lii and uii any other value.
For the sack of simplicity we need only to consider
Lii = 1
for all i = 1, 2, 3, · · · n.
Remark 3.5 What ever the assumption one can take ,the result is not changed
Here is an example, let
1 2 4
A = 3 8 14 = LU
2 6 13
1 0 0 U11 U12 U13
where L = L21 1 0 and U = 0 U22 U23 Multiplying out
L31 L32 1 0 0 U33
LU and setting the answer equal to A gives
U11 U12 U13 1 2 4
LU = L21 U11 L21 U12 + U22 L21 U13 + U23 = 3 8 14
L31 U11 L31 U12 + L32 U22 L31 U13 + L32 U23 + U33 2 6 13
44
Now we have to use this to find the entries in L and U. Fortunately this is
not nearly as hard as it might at first seem. We begin by running along the
top row to see that
The benefit of this approach is that we only ever need to solve triangular
systems. The cost is that we have to solve two of them.
45
Figure 3.1: Lu decomposition
x1 1 2 4 x1
Example 3.2.5 Find the solution of X = x2 of 3 8 14 x2 =
x3 2 6 13 x3
3
13
4
Solution
The first step is to calculate the LU decomposition of the coefficient matrix
on the lefthand side. In this case that job has already been done since this
is the matrix we considered earlier. We found that
1 0 0 1 2 4
L= 3 1 0 , U = 0 2 2
2 1 1 0 0 3
d1
The next step is to solve LD = B for the vector D = d2 That is we
d3
consider
1 0 0 d1 3
LD = 3 1 0 d2 = 13 = B
2 1 1 d3 4
which can be solved by forward substitution. From the top equation we see
that d1 = 3. The middle equation states that 3d1 +d2 = 13 and hence d2 = 4.
Finally the bottom line says that 2d1 + d2 + d3 = 4 from which we see that
d3 = −6. Now that we have found D we finish the procedure by solving
46
U X = D for X. That is we solve
1 2 4 x1 3
U X = 0 2 2 x2 = 4 = D
0 0 3 x3 −6
by using back substitution. Starting with the bottom equation we see that
3x3 = −6 so clearly x3 = −2. The middle equation implies that 2x2 +2x3 = 4
and it follows that x2 = 4. The top equation states that x1 + 2x2 + 4x3 = 3
and consequently x1 = 3. Therefore we have found that the solution to the
system of simultaneous equations
1 2 4 x1 3 3
3 8 14 x2 = 13 is X = 4
2 6 13 x3 4 −2
QR Decomposition
If A is a m × n matrix with linearly independent columns, then A can be
decomposed as A = QR, where Q is a m × n matrix whose columns form an
orthonormal basis for the column space of A and R is an nonsingular upper
triangular matrix.
Theorem 1
47
⇒ ui = kvi kqi + hui , q1 iq1 + hui , q2 iq2 + · · · + hui , qi−1 iqi−1
i.e. ui ∈ span{v1 , v2 , v3 , . . . , vi } = span{q1 , q2 , q3 , . . . , qi }
Thus ui is orthogonal to qj for j > i
u1 = kv1 kq1
u2 = kv2 kq2 + hu2 , q1 iq1
u3 = kv3 kq3 + hu3 , q1 iq1 + hu3 , q2 iq2
..
.
un = kvn kqn + hun , q1 iq1 + hun , q2 iq2 + · · · + hun , qn−1 iqn−1
Let Q = [q1 q2 ... qn ] , so Q is a m × n matrix whose columns form an
orthonormal basis for the column space of A . Now
kv1 k hu2 , q1 i hu3 , q1 i . . . hun , q1 i
0
kv2 k hu3 , q2 i . . . hun , q2 i
A = [u1 u2 . . . un ] = [q1 q2 q3 · · · qn ] 0
0 kv3 k . . . hun , q3 i
.. .. .. .. ..
. . . . .
0 kvn k
0 0 ...
(3.7)
Thus A can be decomposed as A = QR, where R is an upper triangular and
nonsingular matrix.
0 0 −1
48
step 2
2
r12 = q1T a2 = − √
3
step 3
1
√
− 31
−1 3
√1 2
− (− √2 )
0
qb2 = a2 − q1 q1T a2 = a2 − q1 r12 = √13 = 3
−1 1
3 3
− 3
0 0 0
r
2
r22 = kqb2 k =
3
√1
− 6
q
1 2
q2 = qb2 = 3
kqb2 k −√ 1
6
0
step 4
1
r13 = q1T a3 = − √
3
step 5
1
r23 = q2T a3 = √
6
step 6
1
−2
T T
qb3 = a3 − q1 q1 a3 − q2 q2 a3 = a3 − r13 q1 − r23 q2 = 0 12
−1
√
6
r33 = kqb3 k =
2
− √16
1 0
q3 = qb3 = √1
kqb3 6
− √26
Therefore, A = QR
√1 − √16 − √16 √
1 −1 −1 3 3 − √2 − √1
1 0 0 √1 √2 0 3 3
3 6 √2 √1
= 0
1 −1 0 √1 − √6 √16
1 6 √6
3 6
0 0 −1 0 0 − √26 0 0 2
49
Uses: QR decomposition is widely used in computer codes to find the eigen-
values of a matrix, to solve linear systems, and to find least squares approx-
imations.
Since, we replace the complete vector x(k) in the right hand side of (3.10) at
the end of each iteration, this method is also called the method of simulta-
neous displacement.
50
Remark 3.6 A sufficient condition for convergence of the Jacobi method is
that the system of equations is diagonally dominant, that is, the coefficient
matrix A is diagonally dominant. We can verify that
n
X
|aii | ≥ |aij |.
j=1,i6=j
Remark 3.7 If the system is diagonally dominant, then the iteration con-
verges for any initial solution vector. If no suitable approximation is avail-
able, we can choose x = 0, that is xi = 0 for all i. Then, the initial approxi-
mation becomes xi = abiii , for all i.
4x1 + x2 + x3 = 2
x1 + 5x2 + 2x3 = −6
x1 + 2x2 + 3x3 = −4
Solution: Note that the given system is diagonally dominant. Jacobi method
gives the iterations as
(k+1) (k) (k)
x1 = 0.25[2 − (x2 + x3 )]
(k+1) (k) (k)
x2 = 0.2[−6 − (x1 + 2x3 )]
(k+1) (k) (k)
x3 = 0.33333[−4 − (x1 + 2x2 )], k = 0, 1, ...
We have the following results.
(0) (0) (0)
(i) x1 = 0, x2 = 0, x3 = 0
First iteration
(1) (0) (0)
x1 = 0.25[2 − (x2 + x3 )] = 0.5
51
(1) (0) (0)
x2 = 0.2[−6 − (x1 + 2x3 )] = 1.2
(1) (0) (0)
x3 = 0.33333[−4 − (x1 + 2x2 )] = 1.33333.
Second iteration
(2) (1) (1)
x1 = 0.25[2 − (x2 + x3 )] = 0.25[2 − (−1.2 − 1.33333)] = 1.13333
(2) (1) (1)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(0.5+2(−1.33333))] = −0.76668,
(2) (1) (1)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(0.5+2(−1.2))] = −0.7.
Third iteration
(3) (2) (2)
x1 = 0.25[2 − (x2 + x3 )] = 0.25[2 − (−0.76668 − 0.7)] = 0.86667,
(3) (2) (2)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(1.13333+2(−0.7))] = −1.14667,
(3) (2) (2)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(1.13333+2(−0.76668))] = −1.19998.
Fourth iteration
(4) (3) (3)
x1 = 0.25[2 − (x2 + x3 )] = 0.25[2(1.146671.19999)] = 1.08666,
(4) (3) (3)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(0.86667+2(−1.19998))] = −0.89334,
(4) (3) (3)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(0.86667+2(−1.14667))] = −0.85777.
Fifth iteration
(5) (4) (4)
x1 = 0.25[2−(x2 +x3 )] = 0.25[2−(−0.89334−0.85777)] = 0.93778,
(5) (4) (4)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(1.08666+2(−0.85777))] = −1.07422,
(5) (4) (4)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(1.08666+2(−0.89334))] = −1.09998.
It is interesting to note that the iterations oscillate and converge to the
exact solution
x1 = 1.0, x2 = 1, x3 = −1.0.
(0) (0) (0)
(ii) x1 = 0.5, x2 = −0.5, x3 = −0.5.
First iteration
(1) (0) (0)
x1 = 0.25[2 − (x2 + x3 )] = 0.25[2 − (−0.5 − 0.5)] = 0.75,
(1) (0) (0)
x2 = 0.2[−6 − (x1 + 2x3 )] = 0.2[−6 − (0.5 + 2(−0.5))] = −1.1,
(1) (0) (0)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(0.5+2(−0.5))] = −1.16667.
52
Second iteration
(2) (1) (1)
x1 = 0.25[2 − (x2 + x3 )] = 0.25[2 − (−1.1 − 1.16667)] = 1.06667,
(2) (1) (1)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(0.75+2(−1.16667))] = −0.88333,
(2) (1) (1)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(0.75+2(−1.1))] = −0.84999.
Third iteration
(3) (2) (2)
x1 = 0.25[2−(x2 +x3 )] = 0.25[2−(−0.88333−0.84999)] = 0.93333,
(3) (2) (2)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(1.06667+2(−0.84999))] = −1.07334,
(3) (2) (2)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(1.06667+2(−0.88333))] = −1.09999.
Fourth iteration
(3) (3)
x1 (4) = 0.25[2−(x2 +x3 )] = 0.25[2−(−1.07334−1.09999)] = 1.04333,
(4) (3) (3)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(0.93333+2(−1.09999))] = −0.94667,
(4) (3) (3)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(0.93333+2(−1.07334))] = −0.92887.
Fifth iteration
(5) (4) (4)
x1 = 0.25[2−(x2 +x3 )] = 0.25[2−(−0.94667−0.92887)] = 0.96889,
(5) (4) (4)
x2 = 0.2[−6−(x1 +2x3 )] = 0.2[−6−(1.04333+2(−0.92887))] = −1.03712,
(5) (4) (4)
x3 = 0.33333[−4−(x1 +2x2 )] = 0.33333[−4−(1.04333+2(−0.94667))] = −1.04999.
using the Jacobi iteration method. Obtain the result correct to three decimal
places.
53
(k+1) (k) (k)
x3 = [6.0 − (2x1 + 3x2 )]/17 k = 0, 1, ...
Choose the initial approximation as
(0) (0) (0)
x1 = 0, x2 = 0, x3 = 0.
54
(4) (3)
|x2 − x2 | = | − 0.59999 + 0.59941| = 0.00058,
(4) (3)
|x3 − x3 | = |0.39989 − 0.39960| = 0.00029.
Three decimal places of accuracy have not been obtained at this iteration.
Fifth iteration
(5) 1 (4) (4) 1
x1 = [12.6−(2x2 +2x3 )] = [12.6−2(−0.59999+0.39989)] = 0.50001,
26 26
(5) 1 (4) (4) 1
x2 = [−14.3−(3x1 +x3 )] = [−14.3−(3(0.50000)+0.39989)] = −0.60000
27 27
(5) 1 (4) (4) 1
x3 = [−6.0−(2x1 +3x2 )] = [6.0−(2(0.50000)+3(−0.59999))] = 0.40000
17 17
. We find
(5) (4)
|x1 − x1 | = |0.50001 − 0.5| = 0.00001
(5) (4)
|x2 − x2 | = | − 0.6 + 0.59999| = 0.00001,
(5) (4)
|x3 − x3 | = |0.4 − 0.39989| = 0.00011.
Since, all the errors in magnitude are less than 0.0005, the required solu-
tion is
x1 = 0.5, x2 = 0.6, x3 = 0.4.
55
Example 3.3.3 Find the solution of the system of equations
First iteration
(1) 1 (0) (0) 1
x1 = (58 − 2x2 − 3x3 ) = (58) = 1.28889,
45 45
1
(1) (1) (0) 1
x2 = (47 + 3x1 − 2x3 ) = (47 + 3(1.28889) − 2(0)) = 2.31212,
22 22
(1) 1 (1) (1) 1
x3 = (675x1 − x2 ) = (67 − 5(1.28889) − (2.31212)) = 2.91217
20 20
Second iteration
(2) 1 (1) (1) 1
x1 = (58 − 2x2 − 3x3 ) = (58 − 2(2.31212) − 3(2.91217)) = 0.99198,
45 45
(2) 1 (2) (1) 1
x2 = (47 + 3x1 − 2x3 ) = (47 + 3(0.99198) − 2(2.91217)) = 2.00689,
22 22
(2) 1 (2) (2) 1
x3 = (67 − 5x1 − x2 ) = (67 − 5(0.99198) − (2.00689)) = 3.00166.
20 20
Third iteration
(3) 1 (2) (2) 1
x1 = (58 − 2x2 − 3x3 ) = (58 − 2(2.00689) − 3(3.00166) = 0.99958,
45 45
(3) 1 (3) (2) 1
x2 = (47 + 3x1 − 2x3 ) = (47 + 3(0.99958) − 2(3.00166)) = 1.99979,
22 22
56
(3) 1 (3) (3) 1
x3 = (67 − 5x1 − x2 ) = (67 − 5(0.99958) − (1.99979)) = 3.00012.
20 20
Fourth iteration
(4) 1 (3) (3) 1
x1 = (58 − 2x2 − 3x3 ) = (58 − 2(1.99979) − 3(3.00012)) = 1.00000,
45 45
(4) 1 (4) (3) 1
x2 = (47 + 3x1 − 2x3 ) = (47 + 3(1.00000) − 2(3.00012)) = 1.99999,
20 22
(4) 1 (4) (4) 1
x3 = (67 − 5x1 − x2 ) = (67 − 5(1.00000) − (1.99999)) = 3.00000.
20 20
We find
(4) (3)
|x1 − x1 | = |1.00000 − 0.99958| = 0.00042,
(4) (3)
|x2 − x2 | = |1.99999 − 1.99979| = 0.00020,
(4) (3)
|x3 − x3 | = |3.00000 − 3.00012| = 0.00012.
Since, all the errors in magnitude are less than 0.0005, the required solu-
tion is
x1 = 1.0, x2 = 1.99999, x3 = 3.0.
Rounding to three decimal places, we get x1 = 1.0, x2 = 2.0, x3 = 3.0.
−4x1 + x2 − x3 = −8
x1 − 3x2 + 7x3 = 17
diverges. Take the initial approximations as x1 = 0.9, x2 = −3.1, x3 = 0.9.
Interchange the first and second equations and solve the resulting system by
the Gauss-Seidel method. Again take the initial approximations as x1 =
0.9, x2 = 3.1, x3 = 0.9, and obtain the result correct to two decimal places.
The exact solution is x1 = 1.0, x2 = 3.0, x3 = 1.0.
Solution: Note that the system of equations is not diagonally dominant.
Gauss-Seidel method gives the iteration
57
1
(k+1) (k+1) (k+1)
x3 = [17 − x1 + 3x2 ].
7
Starting with the initial approximations x1 = 0.9, x2 = −3.1, x3 = 0.9, we
obtain the following results.
First iteration
(1) 1 (0) (0) 1
x1 = [23 + 6x2 − 2x3 ] = [23 + 6(−3.1) − 2(0.9)] = 0.8667,
3 3
(1) (1) (0)
x2 = [−8 + 4x1 + x3 ] = [−8 + 4(0.8667) + 0.9] = −3.6332
(1) 1 (1) (1) 1
x3 = [17 − x1 + 3x2 ] = [17 − (0.8667) + 3(−3.6332)] = 0.7477
7 7
Second iteration
(2) 1 (1) (1) 1
x1 = [23 + 6x2 − 2x3 ] = [23 + 6(−3.6332) − 2(0.7477)] = −0.0982,
3 3
(2) (2) (1)
x2 = [−8 + 4x1 + x3 ] = [−8 + 4(−0.0982) + 0.7477] = −7.6451,
(2) 1 (2) (2) 1
x3 = [17 − x1 + 3x2 ] = [17 + 0.0982 + 3(−7.6451)] = −0.8339.
7 7
Third iteration
(3) 1 (2) (2) 1
x1 = [23 + 6x2 − 2x3 ] = [23 + 6(−7.6451) − 2(−0.8339)] = −7.0676,
3 3
(3) (3) (2)
x2 = [−8 + 4x1 + x3 ] = [−8 + 4(−7.0676) − 0.8339] = −37.1043,
(3) 1 (3) (3) 1
x3 = [17 − x1 + 3x2 ] = [17 + 7.0676 + 3(−37.1043)] = −12.4636.
7 7
It can be observed that the iterations are diverging very fast.
Now, we exchange the first and second equations to obtain the system
−4x1 + x2 − x3 = −8
58
1
(k+1) (k+1) (k+1)
x3= [17 − x1 + 3x2 ]
7
Starting with the initial approximations x1 = 0.9, x2 = 3.1, x3 = 0.9, we
obtain the following results. First iteration
(1) 1 (0) (0) 1
x1 = [8 + x2 − x3 ] = [8 − 3.1 − 0.9] = 1.0,
4 4
(1) −1 (1) (0) −1
x2 = [23 − 3x1 2x3 ] = [23 − 3(1.0) − 2(0.9)] = −3.0333,
6 6
(1) 1 (1) (1) 1
x3 = [17 − x1 + 3x2 ] = [17 − 1.0 + 3(−3.0333)] = 0.9857
7 7
Second iteration
(2) 1 (1) (1) 1
x1 = [8 + x2 − x3 ] = [8 − 3.0333 − 0.9857] = 0.9953,
4 4
(2) 1 (2) (1) 1
x2 = − [23 − 3x1 − 2x3 ] = − [23 − 3(0.9953) − 2(0.9857)] = −3.0071,
6 6
(2) 1 (2) (2) 1
x3 = [17 − x1 + 3x2 ] = [17 − 0.9953 + 3(−3.0071)] = 0.9976.
7 7
Third iteration
(3) 1 (2) (2) 1
x1 = [8 + x2 − x3 ] = [8 − 3.0071 − 0.9976] = 0.9988,
4 4
(3) 1 (3) (2) 1
x2 = − [23 − 3x1 − 2x3 ] = − [23 − 3(0.9988) − 2(0.9976)] = −3.0014,
6 6
(3) 1 (3) (3) 1
x3 = [17 − x1 + 3x2 ] = [17 − 0.9988 + 3(−3.0014)] = 0.9996.
7 7
Fourth iteration
(4) 1 (3) (3) 1
x1 = [8 + x2 − x3 ] = [8 − 3.0014 − 0.9996] = 0.9998,
4 4
(4) 1 (4) (3) 1
x2 = − [23 − 3x1 − 2x3 ] = − [23 − 3(0.9998) − 2(0.9996)] = −3.0002,
6 6
(4) 1 (4) (4) 1
x3 = [17 − x1 + 3x2 ] = [17 − 0.9998 + 3(−3.0002)] = 0.9999.
7 7
We find
(4) (3)
|x1 − x1 | = |0.9998 − 0.9988| = 0.0010,
(4) (3)
|x2 − x2 | = | − 3.0002 + 3.0014| = 0.0012,
(4) (3)
|x3 − x3 | = |0.9999 − 0.9996| = 0.0003.
Since, all the errors in magnitude are less than 0.005, the required solution is
x1 = 0.9998, x2 = −3.0002, x3 = 0.9999. Rounding to two decimal places,
we get x1 = 1.0, x2 = −3.0, x3 = 1.0.
59
3.4 Solving System of non-linear Equations
using Newtons Method
Now we consider the solution of simultaneous non-linear equations by New-
tons method.
Consider the system
f (x, y) = 0
(3.12)
f (x, y) = 0
involving two non-linear equations. Let (x0 , y0 ) be an initial approximation
to the root of the system, and (x0 + h, y0 + k) be the root of the system given
by (3.12). Then we must have
f (x0 + h, y0 + k) = 0
(3.13)
g(x0 + h, y0 + k) = 0
neglecting, the second and higher order terms and retaining only the linear
terms of (3.14), we obtain
∂f ∂f
h ∂x + k ∂y = −f0
∂g
0
∂g
0
(3.15)
h ∂x0 + k ∂y0 = −g0
∂f
where f0 = f (x0 , y0 ), ∂x0
= ( ∂f )
∂x x=x0
∂f
; ∂y 0
= ( ∂f )
∂y y=y0
solving (3.14) for h and
k, the next approximation of the root is given by
x1 = x0 + h
and
y1 = y0 + k
The above process is repeated to desired degree of accuracy.
Example 3.4.1 Solve
x2 − y 2 = 4
and
x2 + y 2 = 16
By NewtonRaphson Method
60
Solution: To obtain the initial approximation we replace the first equation
by its asymptote y = x, which gives
√
2x2 = 16 ⇒ x = 2 2
√ √
let x0 = 2 2, y0 = 2 2, and (x0 , y0 ) be the initial approximation to the
root of the system.
We have f = x2 − y 2 − 4 ⇒ f0 = −4 and g = x2 + y 2 − 16 ⇒ g0 = 0
differentiating partially, we obtain
∂f ∂f
= 2x , = −2y
∂x ∂y
∂g ∂g
= 2x , = 2y
∂x ∂y
∂f
√ ∂f
√
so that ∂x0
= 2x0 = 4 2 , ∂y 0
= −4 2
∂g √ ∂g √
= 2x0 = 4 2 , = 2y0 = 4 2
∂x0 ∂y0
The system of linear equations can be written as
∂f ∂f √ √
h +k = −f0 ⇒ h(4 2) − k(4 2) = −(−4)
∂x0 ∂y0
⇒ h − k = 0.7072
and
∂g ∂g √ √
h +k = −g0 ⇒ h(4 2) + k(4 2) = 0
∂x0 ∂y0
⇒ h+k =0
so that
hk = 0.7072 (i)
h+k =0 (ii)
solving we get h = 0.3536, k = 0.3536
The second approximation to the root is given by
√
x1 = x0 + h = 2 2 + 0.3536 = 3.1820
√
y1 = y0 + k = 2 2 − 0.3536 = 2.4748
The process can be repeated.
61
Example 3.4.2 Solve
f (x, y) = x2 + y − 20x + 40 = 0
g(x, y) = x + y 2 − 20y + 20 = 0
So that
∂f ∂f
= −20, =1
∂x0 ∂y0
∂g ∂g
=1 , = −20
∂x0 ∂y0
the linear equations are
∂f ∂f
h +k = −f0 ⇒ 20h + k = −40
∂x0 ∂y0
∂g ∂g
h +k = −g0 ⇒ h − 20k = −20
∂x0 ∂y0
Solving, we get
h = 2.055, k = 1.103
The next approximation is given by
x1 = x0 + h = 2.055
y1 = y0 + k = 1.103.
62
Chapter 4
Curve Fitting
The function does not have to give the exact value at any single point ,but
fits the data will overall.
y = a1 x + a0
that fits the data points overall. To determine a1 and a0 we use the definition
of best fit which is given by the following formula.i.e
n
X
E= ri2 = minimum
i=1
where
ri = [yi − a1 x − a0 ]
63
Figure 4.1: (a) Data exhibiting significant error. (b) Polynomial fit oscillating
beyond the range of the data. (c) More satisfactory result using the least-
squares fit.
Figure 4.2: The residual in linear regression represents the vertical distance
between a data point and the straight line.
64
value when
∂E
=0
∂a1
∂E
=0
∂a0
∂E X ∂
= (yi − a1 x − a0 )2 = 0
∂a1 ∂a1
X
⇒ 2(−xi )(yi − a1 xi − a0 ) = 0
X X X
⇒ a1 x2i + a0 xi = xi y i (i)
∂E
=0
∂a0
∂E X ∂
= (yi − a1 x − a0 )2 = 0
∂a0 ∂a0
X
⇒ 2(−1)(yi − a1 xi − a0 ) = 0
X X X
⇒ a1 x i + a0 1= yi
X X
⇒ a1 xi + na0 = yi (ii)
Using (i) and (ii) we have a system of linear equation in a1 and a0
P 2 P P
a1 xP i + a0 xi =P xi yi
(4.2)
a1 xi + na0 = yi
P 2 P P
x i x i a 1 x i y i
P = P (4.3)
xi n a0 yi
x -1 0 1 2 3 4 5 6
y 10 9 7 5 4 3 0 -1
y = ax + b
65
x y xy x2
-1 10 -10 1
0 9 0 0
1 7 7 1
2 5 10 2
3 4 12 9
4 3 12 16
5 0 0 25
6 -1 -1 36
20 37 25 92 sum
Then P 2 P P
x i x i a x i yi
P = P (4.4)
xi n b yi
92 20 a 25
⇒ = (4.5)
20 8 b 37
Using Cramer’s Rule
25 20
37 8
a= = −1.607
92 20
20 8
92 25
20 37
b= = 8.643
92 20
20 8
Therefore y = ax + b
⇒ y = −1.607x + 8.643
66
is minimum by extreme value theorem.
∂E
=0
∂a
X ∂
⇒ (yi − axm 2
i ) = 0
∂a
X
⇒ 2(−xm m
i )(yi − axi ) = 0
X X
⇒a x2m
i = xmi yi
P m
x yi
⇒ a = P i2m
xi
Example 4.1.2 Given the following data ,that experimentally represents the
relation d = 12 gt2 where d, dependent variable and t ,independent variable g,
constant.Find the value of g
solution
Let a = 12 g ,y = d and x = t
⇒ y = ax2 herem = 2
then P 2
x yi
a = P i4
xi
xi yi x2i x2i yi x4i
0.2 0.1960 0.4 0.0078 0.0016
0.4 0.7850 0.16 0.1256 0.256
0.6 1.7665 0.36 0.6359 0.1296
0.8 3.1405 0.64 2.0099 0.4096
1.0 4.9075 1.0 4.9075 1.0000
2.56 7.6863 1.5664 sum
P 2
x yi 7.6863
a = P i4 = = 4.9070
xi 1.5664
But a = 12 g ⇒ g = 2a = 2(4.9070) = 9.8140
67
4.1.3 Polynomial least square regression
consider a second degree polynomial
y = a2 x 2 + a1 x + a0
⇒ e = y − a2 x 2 − a1 x − a0
X
E= e2
X
⇒E= (y − a2 x2 − a1 x − a0 )2 minimum
∂E
=0
∂a2
X ∂
⇒ (y − a2 x2 − a1 x − a0 )2 = 0
∂a2
X
⇒ 2(−x2 )(y − a2 x2 − a1 x − a0 ) = 0
X X X X
⇒ a2 x4i + a1 x3i + a0 x2i = xi y i (i)
∂E
=0
∂a1
X X X X
⇒ a2 x3i + a1 x2i + a0 xi = xi y i (ii)
∂E
=0
∂a0
X X X
⇒ a2 x2i + a1 x i + a0 n = yi (iii)
combining the three (i.e (i),(ii),(iii) ) equation we have a system of three
equations in a2 , a1 , and a0 .
P 4 P 3 P 2 P 2
x i x
P 3 P 2 P i x i a 2 P xi y i
P x2i P xi xi a1 = Pxi yi
xi xi n a0 yi
x 1 1.5 2 2.5
i.
y 3.8 4.9 5.2 5.4
x -3 0 2 4
ii.
y 3 1 1 3
68
4.2 Interpolation
Introduction:
Remark 4.1 Through two distinct points, we can construct a unique poly-
nomial of degree 1 (straight line). Through three distinct points, we can
construct a unique polynomial of degree 2(parabola) or a unique polynomial
of degree 1 (straight line). That is, through three distinct points, we can
construct a unique polynomial of degree ≤ 2.
In general, through n + 1 distinct points, we can construct a unique poly-
nomial of degree ≤ n. The interpolation polynomial fitting a given data is
unique. We may express it in various forms but are otherwise the same
polynomial
Finite Differences
Introduction
69
Numerical Analysis is a branch of mathematics which leads to approx-
imate solution by repeated application of four basic operations of Algebra.
The knowledge of finite differences is essential for the study of Numerical
Analysis. In this section we introduce few basic operators.
Shift Operator
Let y = f (x) be function of x and x, x + h, x + 2h, x + 3h, . . . , etc., be the
consecutive values of x, then the operator E is defined as
Ef (x) = f (x + h),
E is called shift operator. It is also called displacement operator.
Note: E is only a symbol but not an algebraic sum. E 2 f (x) means the
operator E is applied twice on f (x), i.e.,
E 2 f (x) = E[Ef (x)]
= Ef (x + h)
= f (x + 2h)
Similarly
E n f (x) = f (x + nh)
and
E −n f (x) = f (x − nh).
The operator E has the following properties:
1. E(f1 (x) + f2 (x) + + fn (x)) = Ef1 (x) + Ef2 (x) + + Efn (x)
2. E(cf (x)) = cEf (x) (where c is constant)
3. E m (E n f (x)) = E n (E m f (x)) = E m+n f (x) where m, n are positive
integers
4. If n is positive integer E n [E −n f (x)] = f (x)
Alternative notation If y0 , y1 , y2 , . . . , yn , . . . , etc are consecutive values of
the function y = f (x) corresponding to equally spaced values x0 , x1 , x2 , . . . , xn ,
etc., of x then in alternative notation
Ey0 = y1
Ey1 = y2
...
2
E y0 = y2
...
n
and in general E y0 = yn .
70
Forward Difference Operator
Let y = f (x) be any function given by the values y0 , y1 , y2 , . . . , yn , which it
takes for the equidistant values x0 , x1 , x2 , . . . , xn , of the independent variable
x, then y1 − y0 , y2 − y1 , . . . , yn − yn1 are called the first differences of the
function y. They are denoted by y0 , y1 , . . . , etc. We have
∆y0 = y1 − y0
∆y1 = y2 − y1
...
∆yn−1 = yn − yn−1
The symbol ∆ is called the difference operator. The differences of the first
differences denoted by ∆y and ∆2 y0 , ∆2 y1 , . . . , ∆2 yn are called second differ-
ences, where
∆2 y0 = ∆[∆y0 ]
= ∆[y1 − y0 ]
= ∆y1 − ∆y0
= y2 − 2y1 + y0
Similarly
∆r yk = ∆r−1 yk+1 − ∆r−1 yk
Alternative Notation
Let the functions y = f (x) be given at equal spaces of the independent
variable x, say at x = a, a + h, a + 2h, . . . , etc., and the corresponding values
of f (a), f (a + h), f (a + 2h), . . . , etc. The independent variable x is often
called the argument and the corresponding value of the dependent variable
is of the function at x = a, and is denoted by ∆f (a). Thus we have
∆f (a) = f (a + h) − f (a),
∆f (a + h) = f (a + h + h) − f (a + h) = f (a + 2h) − f (a + h)
Similarly
71
where h is called the interval of differencing.
Difference Table
It is a convenient method for displaying the successive differences of a func-
tion. The following table is an example to show how the differences are
formed.
x y ∆y ∆2 y ∆3 y ∆4 y ∆5 y
x0 y 0
∆y0
x1 y 1 ∆2 y0
∆y1 ∆3 y0
x2 y 2 ∆2 y1 ∆4 y
3
∆y2 ∆ y1 ∆5 y0
x3 y 3 ∆2 y2 ∆4 y1
∆y3 ∆3 y1
2
x4 y 4 ∆ y3
∆y4
x5 y 5
The above table is called a diagonal difference table. The first term in the ta-
ble is y0 . It is called the leading term. The differences ∆y0 , ∆2 y0 , ∆3 y0 , . . . ∆n y,
are called the leading differences. The differences ∆n yn with a fixed subscript
are called forward differences. In forming such a difference table care must
be taken to maintain correct sign.
Properties of the Operator
1. If c is a constant then ∆c = 0.
5. ∆[f1 (x) + f2 (x) + . . . + fn (x)] = ∆f1 (x) + ∆f2 (x) + . . . + ∆fn (x).
7. ∆[ fg(x)
(x)
]= g(x)∆f (x)−f (x)∆g(x)
g(x)g(x+h)
.
72
Solution:
x y ∆y ∆2 y ∆3 y
1 4
9
2 13 12
21 6
3 34 18
39 6
4 73 24
63
5 136
Theorem 1
Proof Exercise
Example 4.2.2 By constructing a forward difference table and taking the
second order forward differences as constant find the sixth term of the series
8, 12, 19, 29, 42, . . . .
Solution: Let K be the sixth term of the series. The difference table is
x y ∆ ∆2
1 8
4
1 12 3
7
3 19 3
10
4 29 3
13
5 42 k − 55
k−4
6 k
The second differences are constant.
⇒ K − 55 = 3
73
⇒ K = 58.
The sixth term of the series is 58.
Backward Differences
Let y = f (x) be a function given by the values y0 , y1 , . . . yn which it takes
for the equally spaced values x0 , x1 , . . . , xn of the independent variable x.
Then y1 − y0 , y2 − y1 , . . . , yn − yn−1 are called the first backward differences
of y = f (x). They are denoted by 5y0 , 5y1 , . . . , 5yn respectively. Thus we
have
y1 − y0 = 5y1
y2 − y1 = 5y2
..
.
yn − yn−1 = 5yn
where 5 is called the backward difference operator.
x y 5 52 y 53 y 54 y
x0 y0
5y1
x1 y1 52 y 2
5y2 53 y 3
2
x2 y2 5 y3 54 y4
5y3 53 y 4
2
x3 y3 5 y4
5y4
x4 y4
Note: In the above table the differences 5n y with a fixed subscript i, lie
along the diagonal upward sloping.
Alternative notation: Let the function y = f (x) be given at equal spaces
of the independent variable x at x = a, a + h, a + 2h, . . . then we define
5f (a) = f (a) − f (a − h) where 5 is called the backward difference operator,
h is called the interval of differencing.
In general we can define
We observe that
5f (x + h) = f (x + h) − f (x) = ∆f (x)
74
5f (x + 2h) = f (x + 2h) − f (x + h) = ∆f (x + h)
...
5f (x + nh) = f (x + nh) − f (x + (n − 1)h) = ∆f (x + (n − 1)h)
Similarly we get
⇒ 5 = 1 − E −1
or
E−1
5=
E
xr = x0 + rh, r = 0, 1, 2, . . . ,
f (x) ≈ φ(x) ≈ a0 +a1 (x−x0 )+a1 (x−x0 )(x−x1 ) . . . an (x−x0 )(x−x1 ) . . . (x−xn−1 )
(4.7)
75
the constants a0 , a1 , a2 , . . . , an can be determine as follows. Putting x =
x0 in (4.7) we get
f (x0 ) ≈ φ(x0 ) = a0
⇒ y0 = a0
putting x = x1 in (4.7) we get
f (x1 ) ≈ φ(x1 ) = a0 + a1 (x1 − x0 ) = y0 + a1 h
∴ y 1 = y 0 + a1 h
y1 − y0 ∆y0
⇒ a1 = =
h h
Putting x = x2 in (4.7) we get
f (x2 ) ≈ φ(x2 ) = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 )
∆y0
∴ y2 = a0 + a1 (2h) + a2 (2h)(h) = y0 + (2h) + a2 (2h)(h)
h
⇒ y2 = y0 + 2(y1 − y0 ) + a2 (2h2 )
y2 − 2y1 + y0 ∆2 y0
⇒ a2 = =
2h2 2!h2
Similarly by putting x = x3 , x = x4 , . . . , x = xn in (4.7) we get
∆3 y0 ∆4 y0 ∆n y0
a3 = , a 4 = , . . . , a n =
3!h3 4!h4 n!hn
putting the values of a0 , a1 , . . . , an in (4.7) we get
∆y0 ∆2 y0 ∆n y0
f (x) ≈ φ(x) = y0 + (x−x0 )+ (x−x 0 )(x−x 1 )+· · ·+ (x−x0 )(x−x1 ) . . . (x−xn−1 )
h 2!h2 n!hn
(4.8)
x−x0
Writing p = h
, we get x − x0 = ph
x − x1 = x − x0 − (x1 − x0 ) = ph − h = (p − 1)h
x − x2 = x − x1 + x1 − x2 = (x − x1 ) − (x2 − x1 ) = (p − 1)h − h = (p − 2)h
Similarly
x − xn−1 = (p − n + 1)h
Equation (4.1) can be written as
p p(p − 1) 2 p(p − 1)(p − 2) . . . (p − n + 1) n
φ(x) = y0 + ∆y0 + ∆ y0 +· · ·+ ∆ y0
1! 2! n!
The above formula is called Newtons forward interpolation formula.
Note:
76
1. Newton forward interpolation formula is used to interpolate the values
of y near the beginning of a set of tabular values.
2. y0 may be taken as any point of the table, but the formula contains
only those values of y which come after the value chosen as y0 .
Example 4.2.3 Evaluate y = e2x for x = 0.05 using the following table
77
Exercises 4.1 In an examination the number of candidates who obtained
marks between certain limits were as follows:
M arks 30 − 40 40 − 50 50 − 60 60 − 70 70 − 80
N o.of Students 31 42 51 35 31
Find the number of candidates whose scores lie between 45 and 50.
Solution: Fist of all we construct a cumulative frequency table for the given
data.
78
Exercises 4.2 A second degree polynomial passes through the points (1, -1),
(2, -1), (3, 1), (4, 5). Find the polynomial.
f (x) ≈ φ(x) = a0 +a1 (x−xn )+a2 (x−xn )(x−xn−1 )+· · ·+an (x−xn )(x−xn−1 ) . . . (x−x1 )
(4.9)
Putting x = xn is (4.9) we get
f (xn ) ≈ φ(xn ) = a0 .
⇒ y n = a0 .
Putting x = xn−1 in (4.9) we get
⇒ yn−1 = yn + a1 (−h)
⇒ a1 h = yn − yn−1
yn − yn−1 5yn
⇒ a1 = =
h 1!h
Putting x = xn−2 , we get
80
We have xn = 90, x = 84, h = 10 , tn = yn = 304, 5 tn = 5yn =
28, 52 yn = 2
53 yn = 54 yn = 55 yn = 0
x − xn 84 − 90
p= = = −0.6
h 10
From Newtons backward formula
5tn P (p + 1) 2
f (84) = tn + p + 5 tn + . . .
1! 2!
(−0.6)(−0.6 + 1)
f (84) = 304 + (−0.6)(28) + (2)
2!
= 304 − 16.8 − 0.24 = 286.96.
x 1 2 3 4 5 6 7 8
f (x) 1 8 27 64 125 216 343 512
Solution: let x0 = 2, y0 = 3 , x1 = 5 , y1 = 7
x1 − x x − x0 2−x x−2 7
P1 (x) = y0 + y1 = 3( ) + 7( ) = (5 − x) + (x − 2)
x1 − x0 x1 − x0 5−2 5−2 3
In general, if y0 = f (x0 ) and y1 = f (x1 ) for some function f , then
−x
P1 (x) = f (x0 )( xx11−x0
) + f (x1 )( xx−x 0
1 −x0
) is a linear approximation of f (x) for all
x ∈ [x0 , x1 ].
81
Lagrange’s Interpolation formula
Let the data
x x0 x1 x2 ... xn
(4.11)
f (x) f (x0 ) f (x1 ) f (x2 ) . . . f (xn )
(x − x0 ), (x − x1 ), . . . , (x − xi−1 ), (x − xi+1 ), . . . , (x − xn )
where C is a constant.
Now, since li (xi ) = 1, we get
82
Hence
1
C=
(xi − x0 )(xi − x1 )...(xi − xi−1 )(xi − xi+1 )...(xi − xn )
Therefore,
(x − x0 )(x − x1 )...(x − xi−1 )(x − xi+1 )...(x − xn )
li (x) = (4.14)
(xi − x0 )(xi − x1 )...(xi − xi−1 )(xi − xi+1 )...(xi − xn )
Note that the denominator on the right hand side of li (x) is obtained by set-
ting x = xi in the numerator. The polynomial given in (4.12) where li (x) are
defined by (4.13) is called the Lagrange interpolating polynomial and li (x)
are called the Lagrange fundamental polynomials.
We can write the Lagrange fundamental polynomials li (x) in a simple nota-
tion.
Denote
w(x) = (x − x0 )(x − x1 ) . . . (x − xn )
which is the product of all factors. Differentiating w(x) with respect to x
and substituting x = xi we get
since all other terms vanish. Therefore, we can also write li (x) as
w(x)
li (x) = .
(x − xi )(w0 (x)
Linear interpolation
x x0 x1
f (x) f (x0 ) f (x1 )
83
Quadratic interpolation
x x0 x1 x2
f (x) f (x0 ) f (x1 ) f (x2 )
Figure 4.3: A visual depiction of the rationale behind the Lagrange polyno-
mial. This figure shows a second-order case. Each of the three terms in Eq.
(4.14) passes through one of the data points and is zero at the other two. The
summation of the three terms must, therefore, be the unique second-order
polynomial p1 (x) that passes exactly through the three points.
(x − x1 )(x − x2 )
l0 (x) = ,
(x0 − x1 )(x0 − x2 )
(x − x0 )(x − x2 )
l1 (x) =
(x1 − x0 )(x1 − x2
(x − x0 )(x − x1 )
l2 (x) =
x2 − x0 )(x2 − x1 )
84
The Lagrange quadratic interpolation polynomial is given by
x 0 1 3
y 0 1 0
(x − x0 )(x − x2 ) x(x − 3) 1
l1 (x) = = = (3x − x2 )
(x1 − x0 )(x1 − x2 ) (1)(−2) 2
x −1 1 4 7
f (x) −2 0 63 342
Hence, interpolate at x = 5.
86
Remark 4.2 i. The divided difference are symmetrical in their argu-
ments,i.e. independent of the order of the arguments.For it easy to
write
y1 − y0 y0 − y1
[x0 , x1 ] = = = [x1 , x0 ]
x1 − x0 x0 − x1
Similarly
[x0 , x1 , x2 ] = [x1 , x2 , x0 ]or [x2 , x1 , x0 ]
ii. The nth divided differences of a polynomial of the nth degree are con-
stant.
proof:
Let the arguments be equal spaced i.e.
x1 − x0 = x2 − x1 = . . . = xn − xn−1 = h
Then
y1 − y0 ∆y0
[x0 , x1 ] = =
x 1 − x0 h
[x1 , x2 ] − [x0 , x1 ]
[x0 , x1 , x2 ] =
x2 − x0
1 ∆y1 ∆y0 1
= [ − ]= ∆2 y0
2h h h 2!h2
and in general
1
∆n y0
[x0 , x1 , . . . , xn ] =
n!hn
If the tabulated function is nth degree polynomial,then ∆n y0 will be constant
.Hence ,then nth divided differences will also be constant.
87
substituting this values of [x, x0 ] in (4.16) we get
x 5 7 11 13 17
f (x) 150 392 1452 2366 5202
Evaluate f (9) using
i. Newton’s divided difference formula
88
Taking x = 9 in the Newton’s divided difference formula ,we obtain
x -4 -1 0 2 5
f(x) 1245 33 5 9 1335
solution:
The divided difference table is
89
Applying Newton’s divided difference formula
= 1245+(x+4)(−404)+(x+4)(x+1)(94)+(x+4)(x+1)(x)(−14)+(x+4)(x+1)(x)(x−2)(3)
= 3x4 − 5x3 + 6x2 − 14x + 5
90
Chapter 5
∆y0 ∆2 y0 ∆n y0
f (x) = y0 + (x−x0 )+ (x−x 0 )(x−x 1 )+· · ·+ (x−x0 )(x−x1 ) . . . (x−xn−1 )
h 2!h2 n!hn
Set x = x0 + ph. we get
df df dp 1 df
= =
dx dp dx h dp
dp 1
Since dx
= h
df 1 1 1 1
= [∆f0 + (2p−1)∆2 f0 + (3p2 −6p+2)∆3 f0 + (4p3 −18p2 +22p−6)∆4 f0 +. . .]
dx h 2 6 24
(5.2)
91
At x = x0 , that is, at s = 0, we obtain the approximation to the derivative
f 0 (x) as
1 1 1 1
f 0 (x) = [∆f0 − ∆2 f0 + ∆3 f0 − ∆4 f0 + . . .]
h 2 3 4
Differentiating (5.2) with respect to x, we get
d2 f d df dp
= h1 dp
dx2
( dp ) dx
1 1
(5.3)
= h2 [∆ f0 + (p − 1)∆ f0 + 12 (6p2 − 18p + 11)∆4 f0 + · · · ]
2 3
x y ∆y ∆2 y ∆3 y
1 1
7
2 8 12
9 6
3 27 18
37
4 64
We have h = 1, x0 = 1, and x = x0 + sh = 1 + s. For x = 1, we get s = 0.
Therefore,
dy 1 1 1
(1) = (∆f0 − ∆2 f0 + ∆3 f0 )
dx h 2 3
1 1
= 7 − (12) + (6) = 3
2 3
Exercises 5.1 The following data gives the velocity of a particle for 8 sec-
onds at an interval of 2 seconds. Find the initial acceleration using the entire
data.
time(sec) 0 2 4 6 8
velocity(m/sec) 0 172 1304 4356 10288
92
5.1.2 Derivatives using Newton’s Backward Interpola-
tion Formula
Consider the Newtons backward interpolation formula
y = yn + p 5y1!
n
+ P (p+1)
2!
52 yn + p(p+1)(p+2)
3!
53 yn
(5.6)
+ · · · + p(p+1)(p+2)...(p+n−1)
n!
5n y n
dp
where p = x−xh
n
⇒ dx = h1 h being the interval of differencing
Differentiating (5.6) w.r.t. x we get
df df dp 1 df
= =
dx dp dx h dp
df
dx
= h1 [5fn + 21 (2p + 1) 52 fn + 61 (3p2 + 6p + 2) 53 fn + 1
24
(4p3 + 18p2 + 22p + 6) 54 fn
1
+ 120 (5p4 + 40p3 + 105p2 + 100p + 24) 54 fn + · · · ]
(5.7)
At x = xn , we get s = 0. Hence, we obtain the approximation to the first
derivative f (xn ) as
1 1 1 1 1
f 0 (xn ) = [5fn + 52 fn + 53 fn + 54 fn + 55 fn + · · · ]
h 2 3 4 5
Differentiating (5.15) with respect to x again, we get
d2 f
1 d df dp 1 d df
= = 2
dx2 h dp dp dx h dp dp
d2 f 1 1
dx2
= h2
[52 fn + (p + 1) 53 fn + 12
(6p2 + 18p + 11) 54 fn
(5.8)
1
+ 24 (4p3 2 4
+ 24p + 42p + 20) 5 fn + · · · ]
At x = xn , that is, at s = 0, we obtain the approximation to the second
derivative f 00 (x) as
f 00 (xn ) = 1
h2
[52 fn + 53 f n + 11
12
54 f n
(5.9)
+ 56 54 fn + 137
180
55 f n + · · · ]
93
Example 5.1.2 Find f 0 (3) using the Newtons backward difference formula,
for the data
94
Integration Rules Based on Uniform Mesh Spacing
When w(x) = 1 and the nodes xk s are prescribed and are equispaced with
x0 = a, xn = b, where h = (b − a)/n, the methods are called Newton-Cotes
integration rules. The weights λ0k s are called Cotes numbers. We shall now
derive some Newton-Cotes formulas. That is, we derive formulas of the form
Z b n
X
I= f (x)dx = λk f (xk ) (5.10)
a k=0
Rb
We note that, a f (x)dx defines the area under the curve y = f (x), above
the x-axis, between the lines x = a, x = b.
95
1
f (x) = f (x0 ) + (x − x0 )∆f (x0 )
h
where x0 = a, x1 = b and h = b − a. Substituting in
we obtain
Z b Z x1 Z x1
1 x1
Z
I= f (x)dx = f (x)dx = f (x0 ) dx + [ (x − x0 )dx]∆f0
a x0 x0 h x0
1 1
= (x1 − x0 )f (x0 ) + [ (x − x0 )2 ]xx10 ∆f (x0 )
h 2
1
= (x1 − x0 )f (x0 ) + [f (x1 ) − f (x0 )](x1 x0 )2
2h
h
= hf (x0 ) + [f (x1 ) − f (x0 )]
2
h (b − a)
= [f (x1 ) + f (x0 )] = [f (b) + f (a)].
2 2
The trapezium rule is given by
Z b
h b−a
I= f (x)dx = [f (x1 ) + f (x0 )] = [f (b) + f (a)] (5.11)
a 2 2
Hence, the trapezium rule integrates exactly polynomial of degree ≤ 1, and
the method is of order 1.
Composite trapezium rule
Let the interval [a, b] be subdivided into N equal parts of length h.
b−a
That is, h = N
. The nodal points are given by
a = x0 , x1 = x0 + h, x2 = x0 + 2h, ..., xN = x0 + N h = b.
We write
Z b Z xN Z x1 Z x2 Z xN
f (x)dx = f (x)dx = f (x)dx + f (x)dx + · · · + f (x)dx
a x0 x0 x1 xN −1
There are N integrals. Using the trapezoidal rule to evaluate each integral,
we get the composite trapezoidal rule as
Rb
a
f (x)dx = h2 [{f (x0 ) + f (x1 )} + {f (x1 ) + f (x2 )} + · · · + {f (xN −1 ) + f (xN )}]
= h2 [f (x0 ) + 2{f (x1 ) + f (x2 ) + ... + f (xN −1 )} + f (xN )].
(5.12)
96
Figure 5.2: Composite Trapizium rule
(b − a) 2 00 (b − a)3 00
E≈− h f (ξ) = − f (ξ), (5.13)
12 12n2
where
a = x0 < ξ < xn = b.
R1 1
Example 5.2.1 Find the approximate value of I = 0 1+x dx , using the
trapezium rule with 2, 4 and 8 equal subintervals. Using the exact solution,
find the absolute errors.
Solution With N = 2, 4 and 8, we have the following step lengths and nodal
points.
N = 2, h = b−a
N
= 12 the nodes are 0, 0.5, 1.0
N = 4, h = b−a
N
= 14 the nodes are 0, 0.25, 0.5, 0.75, 1.0
N = 8, h = b−a
N
= 18 the nodes are 0, 0.125, 0.25, 0.375, 0.5, 0.675, 0.75, 0.875, 1.0
We have the following tables of values.
97
N = 4: We require the above values. The additional values required are
the following:
x 0.25 0.75
f (x) 0.8 0.571429
N = 8: We require the above values. The additional values required are the
following:
h
N =2: I1 = [f (0)+2f (0.5)+f (1.0)] = 0.25[1.0+2(0.666667)+0.5] = 0.708334.
2
h
N =4: I2 = [f (0) + 2f (0.25) + f (0.5) + f (0.75) + f (1.0)]
2
= 0.125[1.0+20.8 + 0.666667 + 0.571429+0.5] = 0.697024.
h
N =8: I3 = [f (0) + 2(f (0.125) + f (0.25) + f (0.375) + f (0.5)
2
+ f (0.625) + f (0.75) + f (0.875)) + f (1.0)]
= 0.0625[1.0+2(0.888889+0.8+0.727273+0.666667+0.615385
+ 0.571429 + 0.533333) + 0.5] = 0.694122.
The exact value of the integral is I = ln2 = 0.693147. The errors in the
solutions are the following:
98
Solution: With N = 4 and 8, we have the following step lengths and nodal
points. N = 4 : h = b−a
N
= 14 . The nodes are 1, 1.25, 1.5, 1.75, 2.0.
N = 8 : h = b−aN
= 18 . The nodes are 1, 1.125, 1.25, 1.375, 1.5, 1.675, 1.75, 1.875, 2.0.
We have the following tables of values.
N = 4:
x 1.0 1.25 1.5 1.75 2.0
f (x) 0.125 0.11429 0.10526 0.09756 0.09091
N = 8: We require the above values. The additional values required are
the following
99
Exercises 5.3 The velocity of a particle which starts from rest is given by
the following table.
t(sec) 0 2 4 6 8 10 12 14 16 18 20
v(f t/sec) 0 16 29 40 46 51 32 18 8 3 0
Evaluate using trapezium rule, the total distance travelled in 20 seconds.
100
Note that there are N integrals. The limits of each integral contain three
nodal points. Using the Simpsons 1/3 rule to evaluate each integral, we get
the composite Simpsons 1/3 rule as
Rb
a
f (x)dx = h3 [{f (x0 ) + 4f (x1 ) + f (x2 )} + {f (x2 ) + 4f (x3 ) + f (x4 )}
+ . . . + {f (x2N −2 ) + 4f (x2N −1 ) + f (x2 N )}]
= h3 [f (x0 ) + 4{f (x1 ) + f (x3 ) + . . . . + f (x2N −1 )}
+2{f (x2 ) + f (x4 ) + . . . + f (x2N −2 )} + f (x2N )]
(5.15)
The composite Simpsons 1/3 rule is also of order 3.
Remark 5.1 We have noted that the Simpson 1/3 rule and the composite
Simpsons 1/3 rule are of order 3. If f(x) is a polynomial of degree ≤ 3, then
f (4) (x) = 0. This result implies that error is zero and the composite Simpsons
1/3 rule produces exact results for polynomials of degree≤ 3.
R1 1
Example 5.2.3 Find the approximate value of I = 0 1+x dx , using Simp-
son’s 1/3 rule with 2, 4 and 8 equal subintervals. Using the exact solution,
find the absolute errors.
Solution:
With N = 2, 4 and 8, we have the following step lengths and nodal points.
N = 2, h = b−a
N
= 12 the nodes are 0, 0.5, 1.0
N = 4, h = N = 14 the nodes are 0, 0.25, 0.5, 0.75, 1.0
b−a
N = 8, h = b−a
N
= 18 the nodes are 0, 0.125, 0.25, 0.375, 0.5, 0.675, 0.75, 0.875, 1.0
We have the following tables of values.
N =2:x 0 0.5 1.0
f (x) 1.0 0.666667 0.5
N = 4: We require the above values. The additional values required are the
following:
x 0.25 0.75
f (x) 0.8 0.571429
N = 8: We require the above values. The additional values required are the
following:
x 0.125 0.375 0.625 0.875
f (x) 0.888889 0.727273 0.615385 0.533333
Now, we compute the value of the integral
h
N =2: I1 = [f (0) + 4f (0.5) + f (1.0)]
3
101
1
= [1.0 + 4(0.666667) + 0.5] = 0.674444.
6
h
N =4: I2 = [f (0) + 4{f (0.25) + f (0.75)} + 2f (0.5) + f (1.0)]
3
1
= [1.0+4{0.8+0.571429}+2(0.666667)+0.5]
12
= 0.693254.
h
N =8: I3 = [f (0) + 4{f (0.125) + f (0.375) + f (0.625) + f (0.875)}
3
+ 2{f (0.25) + +f (0.5) + f (0.75)} + f (1.0)]
1
= [1.0 + 4{0.888889 + 0.727273 + 0.615385 + 0.533333}
24
+ 2{0.571429 + 0.8 + 0.666667} + 0.5] = 0.693155.
The exact value of the integral is I = ln(2) = 0.693147. The errors in the
solutions are the following:
3
= h(y0 + 3y1 + 3y2 + y3 )
8
similarly Z x0 +6h
3h
f (x)dx = (y3 + 3y4 + 3y5 + y6 )
x0 +3h 8
Composite Simpson’s 3/8 rule
Z x0 +nh
3h
f (x)dx = [y0 +3(y1 +y2 +y4 +y5 +· · ·+yn−1 )+2(y3 +y6 +· · ·+yn−3 )+yn ]
x0 8
where n is a multiple of three which is the number of subintervals.
102
Remark 5.2 Simpsons 3/8 rule has some disadvantages. They are the fol-
lowing:
i. The number of subintervals must be divisible by 3.
ii. It is of the same order as the Simpsons 1/3 rule, which only requires
that the number of nodal points must be odd.
iii. The error constant c in the case of Simpsons 3/8 rule is c = 3/80,
which is much larger than the error constant c = 1/90, in the case of
Simpsons 1/3 rule. Therefore, the error in the case of the Simpsons
3/8 rule is larger than the error in the case Simpson 1/3 rule. Due to
these disadvantages, Simpsons 3/8 rule is not used in practice.
R2 1
Example 5.2.4 Using the Simpsons 3/8 rule, evaluate I = 1 5+3x dx with
3 and 6 subintervals. Compare with the exact solution.
b−a 1
n = 3N = 6 : h= = The nodes are 1, 7/6, 8/6, 9/6, 10/6, 11/6, 2.0
3N 6
We have the following tables of values.
n = 3N = 3:
x 1.0 4/3 5/3 2.0
f (x) 0.125 0.11111 0.10000 0.09091
103
n = 3N = 6 :
3h
I2 = [f (1) + 3{f (7/6) + f (8/6) + f (10/6) + f (11/6)} + 2{f (9/6)} + f (2.0)]
8
1
= [0.125+3{0.11765+0.11111+0.10000+0.09524}+2(0.10526)+0.09091] = 0.10615.
16
The exact value of the integral is I = 31 [log11 − log8] = 0.10615.
The magnitude of the error for n = 3 is 0.00001 and for n = 6 the result
is correct to all places.
x = p + qy
Lower limit x = a corresponding to y = −1
Upper limit x = b corresponding to y = 1 .
Thus
Z b Z 1 Z 1
I= f (x)dx = f (p + qy)qdy = q f (p + qy)dy (5.17)
a −1 −1
104
Therefore
1
x = [a + b + (b − a)y]
2
From (5.24 ) we have
b 1 1
b−a a + b + (b − a)y b−a
Z Z Z
I= f (x)dx = f[ ]dy = φ(y)dy
a 2 −1 2 2 −1
(5.18)
where φ(y) = f [ a+b+(b−a)y
2
]
The general form for the Gauss Quadrature formula is
n
b−aX
I= Ri φ(yi ) (5.19)
2 i=1
Where −1 ≤ y0 ≤ 1 and values of Ri0 s are rounded off to eight decimal digit.
R4
Example 5.2.5 Evaluate 2 (x2 + 2x)dx by Gauss Quadrature formula .
105
Solution: Here a = 2, b = 4, f (x) = x2 + 2x
Let us transform the interval [2, 4] to [−1, 1]by putting
1
x = [(a + b) + (b − a)y]
2
1
x = [(2 + 4) + (4 − 2)y] = 3 + y
2
when x = 2, y = −1 and x = 4, y = 1
dx = dy
and Z 4 Z 1
I= f (x)dx = φ(y)dy
2 −1
where
φ(y) = φ(3 + y)
By taking n = 2 in the Gauss formula
n
b−aX
I= Ri φ(yi ),
2 i=1
we have
I = [R1 φ(y1 ) + R2 φ(y2 )] (5.20)
Where R1 = 1.0 R2 = 1.0, y1 = −0.5773503, y2 = −y1
= 10.714531
φ(y2 ) = (−y1 )2 +8(−y1 )+15 = (0.5773503)2 +8(0.5773503)+15 = 19.952135
From 5.26
I = 30.6666667
R 1.5 −x2
Example 5.2.6 Evaluate 0.2 e dx using Gauss Quadrature formula with
n = 3.
106
Solution:
2
Here a = 0.2, b = 1.5, f (x) = e−x
Let us transform the interval [0.2,1.5] to [-1,1] by putting
1
x = [(a + b) + (b − a)y]
2
Therefore
1
x = [(0.2 + 1.50) + (1.5 − 0.2)]] = 0.85 + 0.65y
2
when x = 0.2, ay = −1, and x = 1.5, y = 1
dx = 0.65dy
and
Z 1.5 Z 1
I= f (x)dx = 0.65 φ(y)dy, whereφ(y) = f (0.85 + 0.65y)
0.2 −1
2
So φ(y) = f (0.85 + 0.65y) = e−(0.85+0.65y)
By taking n = 3 in the Gauss formula
n
b−aX
I= Ri φ(yi ),
2 i=1
we have
I = 0.65[R1 φ(y1 ) + R2 φ(y2 ) + R3 φ(y3 )] (5.21)
Where R1 = 0.5555556, R2 = 08888889, R3 = R1
y1 = −0.7745967, y2 = 0, y3 = −y1
Now
2 2
φ(y1 ) = e−[0.85+0.65(−0.7745967)] = e−[0.85+0.5034878]
2
e−(0.3465121) = e−0.1200706 = 1.1275765
2
φ(y2 ) = e−(0.85+0) = e− 0.7225 = 2.059595757
2 2
φ(y3 ) = e−(0.85+0.65(0.7745967) = e−(1.3534878) = 6.2459259
From 5.27
I = 0.65[0.5555556(1.1275765) + 0.888889(2.0595757) + 0.555556(6.2459259)
= 0.65[0.6264314 + 1.830734 + 3.4699591] = 3.8526309 ≈ 3.8526
R 12
Exercises 5.4 compute the integral 5 x1 dx using Gauss Quadrature for-
mula.
107
5.2.5 Romberg Integration
We modify the Trapezoidal rule to find a better approximation to the value
of an integral. We know that the truncation error in the trapezoidal rule is
nearly proportional to h2 an interval of size h. The error in the Trapezoidal
rule
b − a 00
E=− y (ξ)h2 (5.22)
12
where a < ξ < b If we put
b − a 00
c= y (ξ)
12
then the error in the Trapezoidal rule = ch2 . y 00 (ξ), the second derivative,
is reasonably constant c may be taken to be constant. Consider the evaluation
of the integral Z b
I= ydx
a
by the Trapezoidal rule with two different intervals say h1 , h2 . Let I1 and
I2 denote the approximate values with the corresponding errorsE1 and E2
respectively.
I = I1 + ch21
Then
I = I2 + ch22
and We get
I1 + ch21 = I2 + ch22
or
I1 − I2
⇒c=
h22 − h21
I1 − I2 2
I = I1 + h
h22 − h21 1
I1 h22 − I2 h21
⇒I= (5.23)
h22 − h21
This will be a better approximation to I than I1 or I2 . The above method
is called Richardsons method. If we take h = h1 and h2 = 12 h in (7)
we get
2
I1 h4 − I2 h 4I1 − I2
I = h2 =
4
−h2 − 34
108
Therefore
I2 − I1
I = I2 + (5.24)
3
If we apply the Trapezoidal rule several times successively halving h, every
time the error is reduced by a factor 14 . Let A1 , A2 , A3 , · · · denote the results.
Let the formula (5.24) be applied to each pair of Ai s and denote the results
by B1 , B2 , B3 , · · · etc.
Applying formula (5.24) to each pair of Bi s we get next results C1 , C2 , · · ·
in this process the following array of results is obtained.
A1 A2 A3 A4 ···
B1 B2 B3 ···
C1 C2 ···
The above computation is continued with two successive values are very
close to each other. This refinement of Richardsons method is known as
Romberg integration. The values of the integral, in Romberg integration can
be tabulated as follows.
I(h)
I(h, h2 )
I(h/2) I(h, h/2, h/4)
I(h/2, h/4) I(h, h/2, h/4, h/8)
I(h/4) I(h/2, h/4, h/8)
I(h/4, h/8)
I(h/8)
Where
h 1 h
I(h, ) = [4I( − I(h)]
2 3 2
h h 1 h h
I( , ) = [4I( ) − I( )]
2 4 3 4 2
1
I(h, h/2, h/4) = [4I(h/2, h/4) − I(h, h/2)]
3
1
I(h/2, h/4, h/8) = [4I(h/4, h/8) − I(h/2, h/4)]
3
1
I(h, h/2, h/4, h/8) = [4I(h/2, h/4, h/8) − I(h, h/2, h/4)]
3
b−a
Alternatively since hi = ni . where ni is the number of intervals.
Replacing hi for i = 1, 2 by b−a
ni
in (5.23) we get
n21 I1 − n22 I2
I=
n21 − n22
109
R 1.2 1
Example 5.2.7 Using Rombergs method compute I = 0 1+x
dx correct to
4 decimal places.
Solution:
Solution Here
1
f (x) =
1+x
We can take h = 0.6, 0.3, 0.15
h h
i.e. h = 0.6 , = 0.3, = 0.15
2 4
x 0 0.15 0.30 0.40 0.60 0.75 0.90 1.05 1.20
f(x) 1 0.8695 0.7692 0.6896 0.6250 0.5714 0.5263 0.48780 0.4545
Using Trapezoidal rule with h = 0.6 we get
0.6
I(h) = I(0.6) = I1 = (1 + 0.4545 + 2 × 0.62560) = 0.8113
2
0.6
with h = 2
= 0.3 we get
0.3
I(h/2) = I(0.3) = I2 = [(1+0.4545)+2(0.7692+0.625+0.5263)] = 0.7943,
2
0.6
with h = 4
= 0.15 we get
0.15
I(h/4) = I(0.15) = I3 = [(1 + 0.4545) + 2(0.8695 + 0.7692 + 0.6896)]
2
0.15
+ [2(0.6250 + 0.5714 + 0.5263 + 0.4878)] = 0.7899.
2
Now I(h, h/2) = I(0.6, 0.3)
1
∴ I(0.6, 0.3) = [4 × I(0.3) − I(0.6)]
3
1
= [4 × 0.7943 − 0.8113] = 0.7886,
3
Similarly I(h/2, h/4) = I(0.3, 0.15)
1
∴ I(0.3, 0.15) = [4 × I(0.15) − I(0.3)]
3
1
= [4 × 0.7899 − 0.7943] = 0.7884
3
110
We get I(h, h/2, h/4) = I(0.6, 0.3, 0.15)
1
∴ I(0.6, 0.3, 0.15) = [4 × I(0.15, 0.3) − I(0.3, 0.6)
3
1
= [4 × 0.7884 − 0.7886] = 0.7883
3
The table of these values is
0.8113
0.7886
0.7948
0.7883
0.7884
0.7899
Z 1.2
1
∴I= dx = 0.7883
0 1+x
simpson’s Rule
I ≈ I1
(b − a)5 (4)
=− f (ξ)
90n41
(b − a)5 (4)
⇒ n41 (I − I1 ) = − f (ξ) (5.25)
90
Similarly for n2 number of intervals
(b − a)5 (4)
⇒ n42 (I − I2 ) = − f (ξ) (5.26)
90
From (5.25) and (5.26)
n41 (I − I2 ) = n42 (I − I2 )
n41 I1 − n42 I2
I= (5.27)
n41 − n42
The result is the same using simpson’s 1/3 and 3/8 rule
111
R 1.2 1
Example 5.2.8 Using Rombergs method compute I = 0 1+x
dx correct to
4 decimal places, by simpson’s rule with h=0.6 and h=0.3
Solution:
1
since f (x) = 1+x
and h1 = 0.6 , h2 = 0.3
1.2 − 0 1.2 − 0
⇒ n1 = = 2 and n2 = =4
0.6 0.3
x 0 0.30 0.60 0.90 1.20
f(x) 1 0.769231 0.6250 0.526316 0.454545
h1 0.6
I1 = [f (x0 ) + 4f (x1 ) + f (x2 )] = [1 + 4 × (0.6250) + 0.454545]
3 3
= 0.790909
h2
I2 = [f (x0 ) + 4(f (x1 ) + f (x3 )) + 2f (x2 ) + f (x4 )]
3
0.3
= [1 + 4 × (0.526316 + 0.769231) + 2 × 0.6250 + 0.454545]
3
= 0.7886733
Now applying Ruberg’s Integration formula we have
n41 I1 − n42 I2
I=
n41 − n42
24 × 0.790909 − 44 × 0.7886733
I=
24 − 44
12.654544 − 201.900365
=
16 − 256
= 0.78852425
R1 1
Exercises 5.5 Using Rombergs method prove that 0 1+x dx = 0.6931.
Rπ
Exercises 5.6 Apply Rombergs method to show that 0
2
sinx dx = 1 .
112
Chapter 6
113
derivatives of one or more unknown functions of two or more independent
variables is called a partial differential equation (PDE). Our first example
illustrates several of each type of differential equation.
a The equations
dy d2 y dy dx dy
+5y = ex , − +6y = 0, and, + = 2x+y (2)
dx dx2 dx dt dt
are examples of ordinary differential equations.
∂ 2u ∂ 2u ∂ 2u ∂ 2u ∂u ∂u ∂v
+ = 0, = −2 , =− (3)
∂x2 ∂y 2 ∂x 2 ∂t 2 ∂t ∂y ∂x
Notice in the third equation that there are two unknown functions and
two independent variables in the PDE. This means u and v must be
functions of two or more independent variables.
Classification by Order:
The order of a differential equation (either ODE or PDE) is the order of the
highest derivative in the equation. For example,
114
where F is a real-valued function of n + 2 variables: x, y, y 0 , ..., y (n) . For
both practical and theoretical reasons we shall also make the assumption
hereafter that it is possible to solve an ordinary differential equation in the
form (4) uniquely for the highest derivative y (n) in terms of the remaining
n + 1 variables. The differential equation
dy/dx = f (x, y)
dy d2 y dy d3 x d2 x
+ 5y = ex , 2
− + 6y = 0, + 5 + 3x = sin(t)
dx dx dx dt3 dt2
115
6.2 Order of a differential equation, linear
and nonlinear ODE
Definition: The order of the differential equation (DE) is the order of its
highest derivative.
Definition: The degree of the DE is the degree of the derivative of the
highest order after the equation has been rationalized in derivatives. An
ODE is of two types namely linear and non-linear.
Definition:An ODE is said to be linear if no product of the dependent
variable y(t) with itself or any one of its derivatives occur. Otherwise, it is
non-linear. A linear DE of order m can be expressed in the form
m
X
Φp (t)y p (t) = r(t)
p=0
116
• The dependent variable y and all its derivatives y 0 , y 00 , . . . , y (n) are of
the first degree, that is, the power of each term involving y is 1.
d3 y dy
(y − x)dx + 4xydy = 0, y 00 − 2y 0 + y = 0, x3 3
+ x − 5y = ex
dx dx
are, in turn, linear first-, second-, and third-order ordinary differential equa-
tions. We have just demonstrated that the first equation is linear in the
variable y by writing it in the alternative form 4xy 0 + y = x.
(b) The equations
a. (y 00 )2 = xy
b. y 0 y = −x
c. y 0 = siny
117
6.3 Nature of Solutions of ODE: particular
and general solutions
Definition 6.1 Any function φ, defined on an interval I and possessing at
least n derivatives that are continuous on I, which when substituted into an
nth-order ordinary differential equation reduces the equation to an identity,
is said to be a solution of the equation on the interval.
G(x, y, c1 , c2 , . . . , cn ) = 0.
This means that a single differential equation can possess an infinite num-
ber of solution corresponding to the unlimited number of choices for the
parameter(s). A solution of a differential equation that is free of arbitrary
parameters is called a particular solution.
118
Figure 6.3.1 shows the graphs of some particular solu-
tions in this family for various choices of c. The solution
y = −xcosx, the blue graph in the figure, is a particular
solution corresponding to c = 0.
Figure 6.1: Solution of
DE in Example 6.3.1
119
Figure 6.2: Solution curve of first-orde Figure 6.3: Solution curve of second-
IVP orde IVP
120
y2 1
Thus (1−x2 )− cos2 x = c1 or y 2 (1−x2 )−cos2 x = c (7)
2 2
where 2c1 has been replaced by c. The initial condition y = 2 when x = 0
demands that 4(1) − cos2 (0) = c, and so c = 3. An implicit solution of the
problem is then
y 2 (1 − x2 ) − cos2 x = 3.
Theorem 1
(Existence).
121
Suppose that F (x, y) is a continuous function defined in some region
x 0 − δ1 < x < x 0 + δ1 .
Theorem 2
(Uniqueness)
Suppose that both F (x, y) and ∂F
∂y
(x, y) are continuous functions defined
on a region R as in Theorem 1. Then there exists a number δ2 (possibly
smaller than δ1 ) so that the solution y = f (x) to (1), whose existence
was guaranteed by Theorem 1, is the unique solution to (1) for
x 0 − δ2 < x < x 0 + δ2
For a real number x and a positive value δ, the set of numbers x satisfying
x0 − δ < x < x0 + δ is called an open interval centered at x0 .
Example 6.5.1 Consider the ODE
y 0 = x − y + 1, y(1) = 2.
Solution: In this case, both the function F (x, y) = x − y + 1 and its partial
122
derivative ∂F
∂y
(x, y) = −1 are defined and continuous at all points (x, y). The
theorem guarantees that a solution to the ODE exists in some open interval
centered at 1, and that this solution is unique in some (possibly smaller)
interval centered at 1. In fact, an explicit solution to this equation is
y(x) = x + e1−x .
(Check this for yourself.) This solution exists (and is the unique solution to
the equation) for all real numbers x. In other words, in this example we may
choose the numbers δ1 and δ2 as large as we please.
Example 6.5.2 Discuss the existence and unique solution for the IVP
2y
y0 = , y(x0 ) = y0
x
Solution: Here f (x, y) = 2y/x and ∂f /∂y = 2/x. Clearly both of these
exist and bounded around (x0 , y0 ) if x0 = 0. Hence, unique solution exists
in a interval about x0 for x0 = 0. For x0 = 0, nothing can be said from
the existence and uniquness theorem. Fortunately, we can solve the actual
problem and find y = Ax2 to be the general solution. When x0 = 0, there
exists no solution when y0 = 0. If y0 = 0, then we have infinite number of
solutions y = αx2 (α any real number) that satisfy the IVP
y = 2y/x, y(0) = 0.
Theorem 3
123
uniformly on I.
y 0 = 2x(1 − y) , y(0) = 2
x x
x4
Z Z
y2 (x) = y0 + f (t, y1 (t))dt = 2 + 2t(1 − (2 − t2 ))dt = 2 − x2 +
0 0 2
x x
x2 x4 x6
Z Z
y3 (x) = y0 + f (t, y2 (t))dt = 2+ 2t(1−(2−x2 + ))dt = 2−x2 + −
0 0 2 2 3!
x
x4 x6 x8
Z
y4 (x) = 2 + f (t, y3 (t))dt = 2 − x2 + − +
0 2 3! 4!
By induction it can be shown that
x4 x6 x2n
2 − x2 + − + . . . + (−1)n
2 3! n!
2 2
Hence ,yn (x) → 1+e−x as x → ∞. Now y(x) = 1+e−x is the exact solution
of the given IVP. Thus ,the Picard’s iteration converges to unique solution
of the given IVP.
Comment: Picard iteration has more theoretical value than practical
value. It is used in the proof of existence and uniqueness theorem. On
the other hand, finding approximate solution using this method is almost
impractical for complicated function f (x, y)
124
On the left we can switch to y as the variable of integration. By calculus,
y 0 dx = dy , so that
Z Z
g(y)dy = f (x)dx + c. (3)
y −2 dy = (x + 1)e−x dx.
1
By integration, − y −1 = −(x + 2)e−x + c, ⇒ y=
(x + 2)e−x − c
125
is said to be homogeneous if both coefficient functions M and N are ho-
mogeneous functions of the same degree. In other words, (1) is homogeneous
if
M (tx, ty) = tα M (x, y) and N (tx, ty) = tα N (x, y).
In addition, if M and N are homogeneous functions of degree α, we can also
write
y
M (x, y) = xα M (1, u) and N (x, y) = xα N (1, u), where u = (2)
x
, and
where v = xy . Properties (2) and (3) suggest the substitutions that can
be used to solve a homogeneous differential equation. Specificall , either
of the substitutions y = ux or x = vy, where u and v are new dependent
variables, will reduce a homogeneous equation to a separable first-orde dif-
ferential equation. To show this, observe that as a consequence of (2) a
homogeneous equation M (x, y)dx + N (x, y)dy = 0 can be rewritten as
dx N (1, u)du
or + =0
x M (1, u) + uN (1, u)
At this point we offer the same advice as in the preceding sections: Do not
memorize anything here (especially the last formula); rather, work through
the procedure each time. The proof that the substitutions x = vy and
dx = vdy + ydv also lead to a separable equation follows in an analogous
manner from (3).
126
(x2 + u2 x2 )dx + (x2 − ux2 )[udx + xdu] = 0
x2 (1 + u)dx + x3 (1 − u)du = 0
1−u dx
du + =0
1+u x
2 dx
[−1 + ]du + = 0. ← long division
1+u x
After integration the last line gives
(x + y)2 y
ln| |= or (x + y)2 = cxey/x
cx x
.
Although either of the indicated substitutions can be used for every homoge-
neous differential equation, in practice we try x = vy whenever the function
M (x, y) is simpler than N (x, y). Also it could happen that after using one
substitution, we may encounter integrals that are difficult or impossible to
evaluate in closed form; switching substitutions may result in an easier prob-
lem.
∂u ∂u
du = dx + dy
∂x ∂y
127
or
dy 1 + 2xy 3
y0 = =
dx 3x2 y 2
an ODE that we can solve by going backward. This idea leads to a powerful
solution method as follows. A first-order ODE M (x, y) + N (x, y)y 0 = 0,
written as (use dy = y 0 dx as in Sec. 1.3)
u(x, y) = c. (3)
128
This condition is not only necessary but also sufficient for (1) to be an exact
differential equation. If (1) is exact, the function u(x, y) can be found by in-
spection or in the following systematic way. From (4a) we have by integration
with respect to x
Z
u = M dx + k(y) (6)
To determine l(x) , we derive ∂u/∂x from (6∗ ), use (4a) to get dl/dx , and
integrate. We illustrate all this by the following typical examples.
• Step 1. Test for exactness. Our equation is of the form (1) with
M = cos(x + y), N = 3y 2 + 2y + cos(x + y).
Thus
∂M ∂N
= −sin(x + y) , = −sin(x + y)
∂y ∂x
From this and (5) we see that (7) is exact.
• Step 2. Implicit general solution. From (6) we obtain by integration
Z Z
u= M dx+k(y) = cos(x+y)dx+k(y) = sin(x+y)+k(y). (8)
129
Hence dk/dy = 3y 2 + 2y. By integration, k = y 3 = y 2 + c ∗ . Inserting
this result into (8) and observing (3), we obtain the answer
u(x, y) = sin(x + y) + y 3 + y 2 = c.
y 0 = y or equivalently − ydx + dy = 0
We check simply
∂M ∂N
= −1 6= 0 =
∂y ∂x
But it can be easily solved!
• Approach 1: Remember that (ex )0 = ex itself. Then realize after a
while that this is also true for Cex for any constant C. As we have one
arbitrary constant now, the general solution
y = cex
y0 − y = 0
Recall that
(e−x y)0 = −e−x y + e−x y 0 = e−x (y 0 − y)
Therefore multiplying the equation by e−x makes the left hand side a total
derivative:
integrating factor:
130
Definition 6.2 If the differential equation M (x, y)dx + N (x, y)dy = 0 is not
exact but the differential equation
131
of (c > 0) corresponds to one of these ellipses. Step 1. Find an ODE for
which the given family is a general solution. Of course, this ODE must no
longer contain the parameter c. Differentiating (1), we have x + 2yy 0 = 0.
Hence the ODE of the given curves is
x
y 0 = f (x, y) = − (2)
2y
Step 2. Find an ODE for the orthogonal trajectories yy = y(x). This ODE
Figure 6.6: Electrostatic field between two ellipses (elliptic cylinders in space):
Elliptic equipotential curves (equipotential surfaces) and orthogonal trajectories
(parabolas)
is
1 2y
y0 = − =+ (3)
f (x, y) x
with the same f as in (2). Why? Well, a given curve passing through a point
(x0 , y0 ) has slope f (x0 , y0 ) at that point, by (2). The trajectory through
(x0 , y0 ) has slope − f (x01,y0 ) by (3). The product of these slopes is −1 , as we
see. From calculus it is known that this is the condition for orthogonality
(perpendicularity) of two straight lines (the tangents at (x0 , y0 ) ), hence of
the curve and its orthogonal trajectory at (x0 , y0 ). Step 3. Solve (3) by
separating variables, integrating, and taking exponents:
dy dx
=2 , ln|y| = 2 ln x + c, y = c ∗ x2 .
y x
This is the family of orthogonal trajectories, the quadratic parabolas along
which electrons or other charged particles (of very small mass) would move
in the electric field between the black ellipses (elliptic cylinders).
132
Chapter 7
INTRODUCTION
The most general form of an ordinary differential equation of nth order is
given by
dy d2 y dn y
φ(x, y, , 2 , . . . , n ) = 0. (1)
dx d x d x
A general solution of an ordinary differential equation such as (1) is a relation
between y, x and n arbitrary constants which satisfies the equation and it is
of the form
f (x, y, c1 , c2 , . . . , cn ) = 0 (2)
133
with the initial condition y(x0 ) = y0 , which is called initial value problem.
The general solutions of equation (3) will be obtained in two forms:
We shall now develop numerical methods for solution of the initial value
problem of the form given by (3). We partition the interval [a, b] on which
the solution is derived in finite number of sub- intervals by the points
The points are called Mesh Points. We assume that the points are spaced
uniformly with the relation
xn = x0 + nh.
1. If f (x, y) is a real function defined and continuous in [x0 , b], y ∈ (−∞, +∞),
where x0 , and b are finite.
2. There exists a constant L > 0 called Lipschitzs constant such that for
any two values y = y1 and y = y2
where x ∈ [x0 , b], then for any y(x0 ) = y0 , the initial value problem
(3), has unique solution for x ∈ [x0 , b].
Now we shall discuss the Taylors series method and the Eulers method.
x − x0 0 (x − x0 )2 00
f (x) = f (x0 ) + f (x0 ) + f (x0 ) + · · ·
1! 2!
134
this may be written as
x − x0 0 (x − x0 )2 00
y = f (x) = y0 + y0 + y0 + · · ·
1! 2!
Putting x = x1 = x0 + h, we get
h 0 h2 00 h3
f (x1 ) = y1 = y0 + y + y + + ··· (4)
1! 0 2! 0 3!
Similarly we obtain
h 0 h2 h3
yn+1 = yn + yn + yn00 + + ··· (5)
1! 2! 3!
Equation (5) may be written as
h 0 h2
yn+1 = yn + yn + yn00 + O(h3 ) (6)
1! 2!
where O(h3 ) means that all the succeeding terms containing the third and
higher powers of h. If the terms containing the third and higher powers of h
are neglected then the local truncation error in the solution is kh3 where k
is a constant. For a better approximation terms containing higher powers of
h are considered.
Note: Taylors series method is applicable only when the various deriva-
tives of f (x, y) exist and the value of (x − x0 ) in the expansion of y = f (x)
near x0 must be very small so that the series converge.
dy
Example 7.1.1 Solve dx = x + y, y(1) = 0, numerically up to x = 1.2,
with h = 0.1.
Solution: We have x0 = 1, y0 = 0 and
dy
= y 0 = x + y ⇒ y00 = x0 + y0 = 1 + 0 = 1
dx
d2 y
= y 00 = 1 + y 0 ⇒ y000 = 1 + y00 = 1 + 1 = 2
dx2
d3 y
= y 000 = y 00 ⇒ y0000 = y000 = 2
dx3
d4 y (4)
4
= y (4) = y 000 ⇒ y0 = y0000 = 2
dx
135
d5 y
= y (5) = y (4) ⇒ y (5) = y (4) = 2
dx5
..
.
Substituting the above values in
h 0 h2 00
y2 = y1 + y + y + ···
1! 1 2! 1
0.1 (0.1)2 (0.1)3 (0.1)4 (0.1)5
⇒ y2 = 0.11 + 1.21 + 2.21 + + 2.21 + 2.21 + · · ·
1 2 6 24 120
∴ y2 = 0.24205
∴ y(0.2) = 0.24205
136
dy
Example 7.1.2 Given dx = 1 + xy with the initial condition that y = 1, x =
0. Compute y(0.1) correct to four places of decimal by using Taylors series
method.
dy
Solution: Given dx
= 1 + xy and y(0) = 1
∴ y 0 (0) = 1 + 0 × 1 = 1
Example 7.1.3 Apply the Taylors series method to find the value of y (1.1)
dy 1
and y (1.2) correct to three decimal places given that dx = xy 3 , y(1) = 1
taking the first three terms of the Taylors series expansion.
Solution Given
dy 1
= xy 3 , y0 = 1, x0 = 1 and h = 0.1
dx
1 1
⇒ y00 = x0 y03 = (1)(1) 3 = 1
137
differentiating the given equation w.r.t. x we get
d2 y 1 −2 dy 1
2
= xy 3 + y3
dx 3 dx
1 −2 1 1 1 −1 1
= xy 3 (xy 3 ) + y 3 = x2 y 3 + y 3
3 3
1 4
⇒ y000 = (1)(1) + 1 =
3 3
Taking the first three terms of the Taylors formula we get
h2 00
y1 = y0 + hy00 + y (7)
2 0
substituting the values in (7)
0.12 4
y1 = y(1.1) = 1 + (0.1)(1) + = 1.1066
2 3
∴ y(1.1) = 1.1066
x1 = x0 + h = 1 + 0.1 = 1.1
1 1
⇒ y10 (1.1) = xy 3 = (1.1)(1.1066) 3 = 1.138
1 −1 1
y100 = x21 y1 3 + y13
3
1 1 1
y100 (1.1) = (1.1)2 (1.1066)− 3 + (1.1066) 3
3
= 1.4249
Substituting in
h2 00
y2 = y1 + hy10 + y
2 1
we get
0.12
y2 = y(1.2) = 1.1066 + 0.11138 + × 1.4249
2
= 1.2275245 ≈ 1.228
∴ y2 = y(1.2) = 1.228
dy 1
Exercises 7.1 Given dx = x2 +y
, y(4) = 4 find y(4.2) by Taylors series
method, taking h = 0.1.
138
dy
Exercises 7.2 Solve dx = 3x + y 2 , y = 1, when x = 0, numerically up to
x = 0.1 by Taylors series method.
y1 = y(x1 ) = y0 + hf (x0 , y0 )
y2 = y(x2 ) = y1 + hf (x1 , y1 )
139
..
.
yn = y(xn ) = yn−1 + hf (xn−1 , yn−1 )
Note: Eulers method has limited usage because of the large error that is
accumulated as the process proceeds. The process is very slow and to obtain
reasonable accuracy with Eulers method we have to take a smaller value of h.
Further, the method should not be used for a larger range of x as the values
found by this method go on becoming farther and farther away from the true
values. To avoid this difficulty one can choose Eulers modified method to
solve the equation (3).
dy
Example 7.2.1 Solve the equation dx = 1 − y, with the initial condition
x = 0, y = 0, using Eulers algorithm and tabulate the solutions at x =
0.1, 0.2, 0.3.
dy
Solution Given dx = 1 − y , with the initial condition x = 0, y = 0
∴ f (x, y) = 1 − y
h = 0.1
we have
∴ x0 = 0, y0 = 0
x1 = x0 + h = 0 + 0.1 = 0.1
x2 = 0.2, x3 = 0.3
Taking n = 0 in
yn+1 = yn + hf (xn , yn )
y1 = y0 + hf (x0 , y0 ) = 0 + 0.1(1 − 0) = 0.1
we get ∴ y1 = 0.1 , i . e ., y(0.1) = 0.1,
y2 = y1 + hf (x1 , y1 )
y2 = 0.1 + 0.1(1 − 0.1) = 0.19
∴ y2 = y(0.2) = 0.19
y3 = y2 + hf (x2 , y2 )
⇒ y3 = 0.19 + (0.1)(1 − y2 )
= 0.19 + (0.1)(0.81) = 0.271
∴ y3 = y(0.3) = 0.271.
140
x Solution by Eulers method
0 0
0.1 0.1
0.2 0.19
0.3 0.271
dy
Example 7.2.2 Given dx
= x3 + y, y(0) = 1, compute y(0.2) by Eulers
method taking h = 0.01.
Solution:Given
dy
= x3 + y
dx
with the initial condition y(0) = 1. We have
f (x, y) = x3 + y
x0 = 0, y0 = 1, h = 0.01
x1 = x0 + h = 0 + 0.01 = 0.01,
x2 = x0 + 2h = 0 + 2(0.01) = 0.02.
Applying Eulers formula we get
y1 = y0 + hf (x0 , y0 )
y1 = 1 + (0.01)(x30 + y0 )
= 1 + (0.01)(03 + 1) = 1.01
∴ y1 = y(0.01) = 1.01
y2 = y1 + hf (x1 , y1 )
= 1.01 + (0.01)[x31 + y1 ]
= 1.01 + (0.01)[(0.01)3 + 1.01] = 1.0201
∴ y2 = y(0.02) = 1.0201
Exercises 7.5 Solve by Eulers method the following differential equation x
dy
= 0.1 correct to four decimal places dx = y−x
x−y
with the initial condition y(0)
= 1.
Exercises 7.6 Find y(1) by Eulers method from the differential equation
dy −y
dx
= − 1+x , when y(0.3) = 2. Convert up to four decimal places taking step
length h = 0.1.
Exercises 7.7 Solve y 0 = x − y 2 , by Eulers method for x = 0.2 to 0.6 with
h = 0.2 initially x = 0 , y = 1.
141
7.3 Eulers modified method
From Eulers iteration formula we h known that
Let y(xr ) = yr denote the initial value using (9) an approximate value of yr0
can be calculated Z xr
(0)
yr = yr−1 + f (x, y)dx
xr−1
142
we get
(0)
∴ y1 = y0 + hf (x0 , y0 )
= 1 + 0.01[x20 + y0 ] = 1 + 0.01[02 + 1] = 101
(0)
y1 = 1.01
Applying Eulers modified formula we get
(1) h (0)
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )]
2
0.01 2
=1+ [0 + 1 + 0.012 + 1.01] = 1.01005
2
(1)
∴ y1 = 1.01005
(2) 2 (1)
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 ]
2
0.01 2
=1+ [0 + 1 + 0.012 + 1.01005] = 1.01005
2
(2)
⇒ y1 = 1.01005
(1) (2)
∴ y1 = y1 = 1.01005
(0)
y2 = y1 + hf (x1 , y1 )
= 1.01005 + 0.01(x21 + y1 )
= 1.01005 + 0.01((0.01)2 + 1.01005) = 1.02015
(1) h (0)
y2 = y1 + [f (x1 , y1 ) + f (x2 , y2 )]
2
0.01
= 1.01005 + [(0.01)2 + 1.01005 + (0.02)2 + 1.02015]
2
= 1.020204
(2) h (1)
y2 = y1 + [f (x1 , y1 ) + f (x2 , y2 )]
2
0.01
= 0.01 + [(0.01)2 + 1.01005 + (0.02)2 + 1.020204] = 1.020204
2
∴ y2 = y(0.02) = 1.020204
Exercises 7.8 Find y(4.4), by Eulers modified method taking h = 0.2 from
dy 2
the differential equation dx = 2−y
5x
, y = 1 when x = 4.
143
Exercises 7.9 Using Eulers modified method, solve numerically the equation
dy √
dx
= x + | y| with boundary condition y = 1 at x = 0 for the range 0 < x <
0.4 in steps of 0.2.
dy
Exercises 7.10 solve dx = 1y with y = 0 when x = 0 in the range 0 < x <
0.2 by taking h = 0.1 (apply Eulers modified formula).
144