Course Materials_Numerical Methods-3
Course Materials_Numerical Methods-3
D EPARTMENT OF M ATHEMATICS
1 N UMERICAL M ETHODS
Definition 1.1. To round-off a number to n significant digits, discard all digits to the right of the nth
digit, and if this discarded number is
3. exactly half a unit, increase the nth digit if it is odd; otherwise, leave it unchanged.
Rules of Significant Figures: To measure the significant figures of a calculated measurement, there are
certain rules that need to be followed and remembered.
All the digits except zero are always significant. For example, 894621 contains six significant digits.
Any zeros placed in between any two non-zero digits are significant. For example, 10.007 contains five
significant digits.
If zeros are placed both on the right of a decimal point and left of a non-zero digit, they are not significant.
For example, 0.0012 contained two significant digits.
If zeros are placed on the right of the decimal and not have a non-zero digit after that, then it is significant.
For example, 80.00 contains four significant digits.
Zeros placed on the right of the last non-zero digit after the decimal point are significant. For example,
0.00153100 contains six significant digits.
Zeros that are placed on the right of the last non-zero digit are significant when they come from a mea-
surement. For example, 3560 m contains four significant digits. There are 4 significant digits in the
number 0.00003400
Example 1.1. The numbers given below are rounded-off to four significant figures:
1
Before After Before After
1.6583 1.658 0.0015472 0.001547
30.0567 30.06 700.1512 700.2
0.859378 0.8594 897846 8978
3.14159 3.142 526752 5268
At n = 12, it is seen that the difference two successive iteratives is 0.0005, which is less than 0.001. Thus
the required root is 2.09 (correct upto 3 significant figures).
Exercise 1.1. Show that f (x) = x3 + 4x2 − 10 has a root in [1, 2] and use the Bisection method to
determine an approximation to the root that is accurate to at least within 10−4 . Ans: 1.3651123
2
We present here one example as follows:
Exercise 1.2. Use the Newton-Raphson Method to find a real root of the equation x3 − 2x − 5 = 0.
Solution: Here f (x) = x3 − 2x − 5 and f ′ (x) = 3x2 − 2. Hence from the above formula
x3n − 2xn − 5
xn+1 = xn − .
3x2n − 2
n xn f (xn ) xn+1
0 2 -1 2.1
1 2.1 0.061 2.094568
2 2.094568 0.0001859 2.094551
3 2.094551 -0.000053
Note 1. Suppose that we want to find the pth root of N . Then consider f (x) = xp − N . The New-
ton–Raphson formula yields
f (xn ) (p − 1)xpn + N
xn+1 = xn − = , n ≥ 0.
f ′ (xn ) pxp−1
n
Remark 1.1. It’s an interesting fact to note that this method will work for complex differentiable func-
tions too. In fact, we do exactly the same thing as in the real case, namely repeat the following operation:
f (zn )
zn+1 = zn − .
f ′ (zn )
The only difference is that this time the fraction may have complex numerator and denominator. If
f : R → R, then N-R method started from a real x0 produces real iterates, and hence it cannot converge
to complex (non-real) roots. So you need to start from a non-real x0 to find non-real roots. For instance,
check it for f (x) = x2 + 1 with real initial approximation.
Limitations of Newton–Raphson Method Method: It may not converge if the initial guess is not close
enough to the root. It may converge to a local minimum or maximum instead of the desired root. It
requires the calculation of the derivative, which may be difficult or time-consuming for some functions.
On the other hand, if the value of f ′ (x) is small in the neighbourhood of the root, then the computation
of the root shall be a slow process. Thus, Newton–Raphson method should not be used when the graph
of f is nearly horizontal where it crosses the x−axis. Further, the method fails if f ′ (x) = 0 in the
neighbourhood of the root.
Exercise 1.3. Obtain a root, using the Bisection Method or the Newton-Raphson Method, correct up to
three decimal places, for the following equations:
3
(i) x3 + x2 + x + 7 = 0 Ans:
(ii) x3 − 4x − 9 = 0 Ans: 2.706
(iii) cos x = 3x − 1 Ans: x0 = 0.5, root = 0.607
(iv) x3 − 5x + 3 = 0 Ans: x0 = 1, root = .657
(v) x3 − 18 = 0 Ans:
1
(vi) x = (5 − x) 3 Ans:
(vii) x3 − x2 − 1 = 0 Ans:
(viii) x3 + x2 − 1 = 0 Ans:
(ix) x3 − 3x − 5 = 0 Ans:
(x) x3 − x − 1 = 0 Ans: x0 = 1, root = .657
(xi) ex = 5x Ans: x0 = 1, root = 1.3247
(xii) log x = cos x Ans: You can see f(1) and f(1.5) and take x0 = 1.3, answer = 1.303.
2 I NTERPOLATION
The process of finding the curve passing through the points (x0 , y0 ), (x1 , y1 ), . . . , (xn , yn ) is called as
Interpolation and the curve obtained is called as Interpolating curve. In this context, we are interested to
find interpolating polynomial passing through the given set of points.
Let x0 , x1 , ..., xn be given set of observations and y = f (x) be the given function, then the method to
find f (x), where x0 ≤ x ≤ xn is called as an Interpolation.
Theorem 2.1. If x0 , x1 , ..., xn are given set of observations with common difference h and let y0 , y1 , ..., yn
are their corresponding values, where y = f (x) be the given function then
u u 2 u
f (x) = y0 + ∆y0 + ∆ y0 + ... + ∆n y0
1 2 n
x−x0
where u = h .
Exercise 2.1. Compute f (0.5) and f (1.5) for the data by using Newton’s forward interpolation.
x 0 1 2 3 4
.
f (x) 1 7 23 55 109
Exercise 2.2. Compute f (2.5) and f (1.5) for the data by using Newton’s forward interpolation.
x 0 1 2 3 4 5 6
.
f (x) 0 1 16 81 256 625 1296
4
Solutions:
xi yi ∆yi ∆2 yi ∆3 y ∆4 yi ∆5 yi
0 0
1
1 1 14
15 36
2 16 50 24
65 60 0
3 81 110 24
175 84 0
4 256 194 24
369 108
5 625 302
671
6 1296
Here x = 2.5, x0 = 2, h = 1, then x = x0 + uh, i.e., 2.5 = 2 + u × 1, i.e., u = 0.5
Now we can write
5
Theorem 2.2. If x0 , x1 , ..., xn are given set of observations with common difference h and let y0 , y1 , ..., yn
are their corresponding values, where y = f (x) be the given function then
Exercise 2.3. Compute f (0.45) by using Newton’s backward interpolation from the data:
6
Exercise 2.4. Compute the approximate value of sin x for x = 0.54 and x = 1.36 from the data:
x 20 25 30 35 40 45
.
f (x) 354 332 291 260 231 204
Solutions:
xi yi ∇yi ∇2 yi ∇3 yi ∇4 yi ∇5 yi
20 354
−22
25 332 −19
−41 29
30 291 10 -37
−31 -8 45
35 260 2 8
-29 0
40 231 2
−27
45 204
Here x = 41, xn = 40, h = 5, then x = xn + uh, i.e., 41 = 40 + u × 5, i.e., u = 0.2
Now we can write
f (x) = fs = f (xn + uh)
u(u + 1) 2 u(u + 1)(u + 2) 3 u(u + 1)(u + 2)(u + 3) 4
= fn + u∇fn + ∇ fn + ∇ fn + ∇ fn
2! 3! 4!
0.2(0.2 + 1) 0.2(0.2 + 1)(0.2 + 2)
⇒ f (41) = 231 + 0.2 × (−29) + ×2+ × (−8)
2! 3!
0.2(0.2 + 1)(0.2 + 2)(0.2 + 3)
+ × (−37)
4!
= 222.1312
Remark 2.1. Newton’s forward difference formula is used for interpolating the values of the function
near the beginning of a set of tabulated values.
Newton’s backward difference formula is used for interpolating the values of the function near the end
of a set of tabulated values.
7
Example 2.1. Find the unique Lagrange’s interpolating polynomial P (x) of order 2 from the following
data:
x 1 3 4
.
P (x) 1 27 64
Exercise 2.6. Find the cubic Lagrange’s interpolating polynomial from the following data:
x 0 1 2 5
.
y 2 3 11 143
Exercise 2.7. Compute f (0.3) for the data given below by using Lagrange Interpolation Formula.
x 0 1 3 4 7
.
f (x) 1 3 49 129 813
Observation 2.4. Lagrange interpolation formula is used for both equally spaced and unequally spaced
arguments.
3 N UMERICAL I NTEGRATION
The basic problem in numerical integration is to compute an approximate solution to a definite integral
Z b
f (x) dx
a
to a given degree of accuracy. We approximate the integrand f by functions that can easily be integrated.
8
Observation 3.1. Suppose we have a function f defined on an interval [a, b] and a partition {xi }ni=0 of
[a, b]. If we approximate f by its secant on each subinterval and approximate the integral of f by the
integral of the resulting piecewise linear approximation, we obtain the approximation
n−1
Z b " #
f (a) + f (b) X
f (x)dx ≈ h + f (xi ) .
a 2
i=1
Definition 3.2 (Error Bound). Suppose that f and its first four derivatives are continuous on the interval
[a, b], and that the integral of f on [a, b] is approximated by Simpson’s rule with ‘n′ subintervals of equal
width h. Then the error is bounded by
h2 h2
−(b − a) max f ′′ (x) ≤ E(f ) ≤ −(b − a) min f ′′ (x).
12 x∈[a,b] 12 x∈[a,b]
Observation 3.3. Suppose f is a function defined on the interval [a, b], and let {xi }2n i=0 be a uniform
partition of [a, b] with step length h. The Simpson’s one-third rule approximates the integral of f by
n−1 n
Z b " #
h X X
f (x)dx ≈ f (a) + f (b) + 2 f (x2i ) + 4 f (x2i−1 ) .
a 3
i=1 i=1
Theorem 3.4 (Error Bound). Suppose that f and its first four derivatives are continuous on the interval
[a, b], and that the integral of f on [a, b] is approximated by Simpson’s rule with ‘2n′ subintervals of equal
width h. Then the error is bounded by
h4 h4
−(b − a) max f (4) (x) ≤ E(f ) ≤ −(b − a) min f (4) (x).
180 x∈[a,b] 180 x∈[a,b]
R2 2
Example 3.1. Use the Trapezoidal rule to estimate the integral 0 ex dx taking the number 10 intervals.
2
Solution 3.1. Let y = f (x) = ex , h = 0.2, n = 10 and yi = f (xi ). The values of x and y are as
follows: By the Trapezoidal rule, we have
x 0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
y 1 1.0408 1.1735 1.4333 1.8964 2.1782 4.2206 7.0993 12.9358 25.5337 54.5981
yi y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10
9
Z 2
2 h
ex dx = [(y0 + y10 ) + 2(y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8 + y9 )]
0 2
0.2
= [(1 + 54.5981) + 2(1.0408 + 1.1735 + 1.8964 + 2.1782 + 4.2206 + 7.0993 + 12.9358 + 25.533
2
= 17.0621
R1 x2
Example 3.2. Evaluate the integral 0 dx using Simpson’s 1/3 rule. Compare the error with the
1 + x3
exact value.
x2
Solution 3.2. Let us divide the interval (0, 1) into 4 equal parts so that h = 0.25. Taking y = ,
1 + x3
we have By Simpson’s 1/3 rule, we have
1
x2
Z
h
dx = [(y0 + y4 ) + 2y2 + 4(y1 + y3 )]
0 1 + x3 3
0.25
= [(0 + 0.5) + (2 × 0.22222) + 4(0.06153 + 0.3956)]
3
0.25
= [0.5 + 0.44444 + 1.82852] = 0.23108
3
x2
R1 1 3 1
Also, 0 1 + x3 dx = 3 ln(1 + x )|0 = 0.23105. Thus the error = 0.23105 − 0.23108 = −0.00003.
R6 1
Exercise 3.1. Evaluate 0 dx by using
1 + x2
a) Trapezoidal rule,
10
4 N UMERICAL D IFFERENTIATION
This chapter deals with numerical approximations of derivatives. The first questions that comes up to
mind is: why do we need to approximate derivatives at all? After all, we do know how to analytically dif-
ferentiate every function. Nevertheless, there are several reasons as of why we still need to approximate
derivatives:
• Even if there exists an underlying function that we need to differentiate, we might know its values
only at a sampled data set without knowing the function itself.
• There are some cases where it may not be obvious that an underlying function exists and all that
we have is a discrete data set. We may still be interested in studying changes in the data, which
are related, of course, to derivatives.
• There are times in which exact formulas are available but they are very complicated to the point
that an exact computation of the derivative requires a lot of function evaluations. It might be
significantly simpler to approximate the derivative instead of computing its exact value.
• When approximating solutions to ordinary (or partial) differential equations, we typically represent
the solution as a discrete approximation that is defined on a grid. Since we then have to evaluate
derivatives at the grid points, we need to be able to come up with methods for approximating the
derivatives at these points, and again, this will typically be done using only values that are defined
on a lattice. The underlying function itself (which in this cased is the solution of the equation) is
unknown.
11
4.2 E ULER M ETHOD
Let’s start with a general first order IVP
dy
= f (x, y), y(x0 ) = y0 .
dx
Euler’s method is based on approximating the graph of a solution y(x) with a sequence of tangent line
approximations computed sequentially, in “steps”. The general iterative formula for this method is
Figure 4.1: (a) A single tangent line approximation for the Euler method, and (b) the approximation of the solution curve generated by five
steps of Euler’s method
Solution 4.1. Let us consider f (t, y) = 2 − e−4t − 2y. Also note that t0 = 0, y0 = 1. We can now start
doing some computations.
So, the approximation to the solution at t1 = 0.1 is y1 = 0.9. At the next step we have,
Therefore, the approximation to the solution at t2 = 0.2 is y2 = 0.852967995. Similarly solve the rest.
Exercise 4.1. Several initial-value problems are given below, along with values for two of the three pa-
rameters in Euler’s method: step size h, number of steps N . For each, find the corresponding numerical
solution using Euler’s method with the indicated parameter values.
dy y 1
1. = , y(1) = −1, h= , N = 3. Ans: -2
dx x 3
12
dy
2. = −8xy, y(0) = 10, h = 0.2, N = 4. 0.09791999999
dx
dy
3. = y 2 − 4x, y(0) = 10, h = 0.2, N = 4. Ans: 1.626697378334
dx
dy √
4. = 2x + y, y(0) = 0, h = 0.5, N = 6. Ans: 5.048767106
dx
dy
5. = cos y, y(0) = 0, h = 0.2, N = 5. Ans: 0.894410093
dx
dy
6. = yx, y(1) = 2, h = 0.1, N = 5. Ans: 3.58535897
dx
Exercise 4.2. For the IVP
dy 1 t t
= y − e 2 sin 5t + 5e 2 cos 5t, y(0) = 0, h = 0.2
dt 2
use Euler’s Method to find the approximation to the solution at t = 1.
Solution hint.:
Exercise 4.3. Find y(0.9), by Euler’s method, from the differential equation
dy y
=− ,
dx 1+x
when y(0.3) = 2, correct upto 4-decimal places, taking step length h = 0.1.
Solution hint.:
13
4.3 P REDICTOR -C ORRECTOR OR M ODIFIED E ULER M ETHOD
The Euler forward scheme may be very easy to implement but it can’t give accurate solutions. A very
small step size is required for any meaningful result. In this scheme, since, the starting point of each sub
interval is used to find the slope of the solution curve, the solution would be correct only if the function
is linear. So an improvement over this is to take the arithmetic average of the slopes at xi and xi+1 (that
is, at the end points of each sub-interval. The scheme so obtained is called modified Euler’s method. It
works first by approximating a value to yi+1 and then improving it by making use of average slope.
h ′ ′
yi+1 = yi + yi + yi+1
2
h
= yi + [f (xi , yi ) + f (xi+1 , yi+1 )]
2
If Euler’s method is used to find the first approximation of yi+1 then
h
yi+1 = yi + [fi + f (xi+1 , yi + hfi )] .
2
On the other hand, we can do the calculations by the following steps:
Step-I: First the value is predicted for a step (here i+1) as
yi+1,p = yi + hfi .
h3 ′′′ h4 (4)
Truncation error is − y − yi + . . . . Hence the order of this method is 2.
12 i 24
Exercise 4.4. Find y(1.0) accurate upto four decimal places using Modified Euler’s method by solving
the IVP y ′ = −2xy 2 , y(0) = 1 with step length 0.2. Ans: 0.49808799
(x − y)
Exercise 4.5. Find y in [0, 3] by solving the initial value problem y ′ = , y(0) = 1. Compare
2
1 1 1
solutions for h = , , .
2 4 8
Exercise 4.6. Find y(0.1) for y ′ = x − y 2 , y(0) = 1 (correct upto four decimal places). Ans: 0.91475
Exercise 4.7. Find y at x = 1.1 and 1.2 by solving y ′ = x2 + y 2 , y(1) = 2.3. Ans: 3.0938, 4.54585
Exercise 4.8. Find y at x = 1 by solving y ′ = y − 2x2 + 1, y(0) = .5, h = .2.
Solution hint.:
14