0% found this document useful (0 votes)
15 views14 pages

Course Materials_Numerical Methods-3

Uploaded by

midjourney450
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
15 views14 pages

Course Materials_Numerical Methods-3

Uploaded by

midjourney450
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

NATIONAL I NSTITUTE OF T ECHNOLOGY D URGAPUR

D EPARTMENT OF M ATHEMATICS

Course Material for Numerical Methods

Lakshmi Kanta Dey


November 11, 2024

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

1. less than half a unit, leave the nth digit unaltered;

2. greater than half a unit, increase the nth digit by unity;

3. exactly half a unit, increase the nth digit if it is odd; otherwise, leave it unchanged.

The number thus rounded-off is said to be correct to n significant figures.

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

1.0.1 B ISECTION M ETHOD


The bisection method in mathematics is a root-finding method that repeatedly bisects an interval and
then selects a subinterval in which a real root must lie for further processing. This method based on the
Intermediate Value Theorem (IVT) in real analysis and note that we can find only real root of an equation
(continuous). It is a very simple and robust method, but it is also relatively slow. We demonstrate this
method by one example below:
Example 1.2. Suppose we have to find a real root of f (x) = x3 − 2x − 5. Since this is a polynomial
equation, it is continuous on R and f (2).f (3) < 0, so there exists atleast one real root in between 2 and
3 (This is due to IVT). We take x0 = 2+32 = 2.5. Since f (x0 ) = 5.6250, we choose [2, 2.5] as the new
interval. Then x1 = 2+2.5
2 = 2.25 and f (x1 ) = 1.890625. Proceeding in this way, the following table is
obtained.
n a b x f (x)
1 2 3 2.5 5.56250
2 2 2.5 2.25 1.8906
3 2 2.25 2.125 0.3457
4 2 2.125 2.0625 -0.3513
5 2.0625 2.125 2.09375 -0.0089
6 2.09375 2.125 2.10938 0.1668
7 2.09375 2.10938 2.10156 0.07856
8 2.09375 2.10156 2.09766 0.03471
9 2.09375 2.09766 2.09570 0.01286
10 2.09375 2.09570 2.09473 0.00195
11 2.09375 2.09473 2.09424 -0.0035
12 2.09424 2.09473

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

1.0.2 T HE N EWTON -R APHSON M ETHOD


In numerical analysis, Newton-Raphson method, named after Isaac Newton and Joseph Raphson, is a
method for finding successively better approximations to the roots of a real-valued function. Newton’s
method is an extremely powerful technique, in general, the convergence is quadratic. We can find any
root of an equation f (x) = 0, provided f (x) is differentiable sufficiently may times. This method based
on the Taylor’s series expansion of the function near the exact root also we have to make sure that initial
approximation has to be sufficiently close to the exact root. The iteration scheme of this method is as
follows:
xn+1 = xn − ff′(x n)
(xn ) ; n = 0, 1, 2, . . .

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

Choosing x0 = 2, we get the following table:

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

Thus the required root is 2.09 (correct up to 3 significant figures).

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.

2.0.1 N EWTON ’ S FORWARD INTERPOLATION


Forward differences are now defined as follows:

∆fi = ∆yi ≡ fi+1 − fi = yi+1 − yi (F irst order f orward dif f erence)

∆2 fi = ∆2 yi ≡ ∆fi+1 − ∆fi (Second order f orward dif f erence and so on...)

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

f (x) = fs = f (x0 + uh)


u(u − 1) 2 u(u − 1)(u − 2) 3 u(u − 1)(u − 2)(u − 3) 4
= f0 + u∆f0 + ∆ f0 + ∆ f0 + ∆ f0
2! 3! 4!
0.5(0.5 − 1) 0.5(0.5 − 1)(0.5 − 2)
⇒ f (2.5) = 16 + 0.5 × 65 + × 110 + × 84
2! 3!
0.5(0.5 − 1)(0.5 − 2)(0.5 − 3)
+ × 24
4!
= 39.0625

Note: When x = 2.5, x0 = 0, h = 1, then x = x0 + uh, i.e., 2.5 = 0 + u × 1, i.e., u = 2.5


Now we can write

f (x) = fs = f (x0 + uh)


u(u − 1) 2 u(u − 1)(u − 2) 3 u(u − 1)(u − 2)(u − 3) 4
= f0 + u∆f0 + ∆ f0 + ∆ f0 + ∆ f0
2! 3! 4!
2.5(2.5 − 1) 2.5(2.5 − 1)(2.5 − 2)
⇒ f (2.5) = 0 + 2.5 × 1 + × 14 + × 36
2! 3!
2.5(2.5 − 1)(2.5 − 2)(2.5 − 3)
+ × 24
4!
= 39.0625

2.0.2 N EWTON ’ S BACKWARD INTERPOLATION


For interpolating the value of the function y = f (x) near the end of table of values, and to extrapolate
value of the function a short distance forward from yn , Newton’s backward interpolation formula is used.
Backward differences are now defined as follows:

∇fi = ∇yi ≡ fi − fi−1 = yi − yi−1 (F irst order backward dif f erence)

∇2 fi = ∇2 yi ≡ ∇fi − ∇fi−1 (Second order backward dif f erence and so on...)

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

u(u + 1) 2 u(u + 1)...(u + n − 1) n


f (x) = yn + u∇yn + ∇ yn + ... + ∇ yn
2! n!
x−x0
where u = h .

Exercise 2.3. Compute f (0.45) by using Newton’s backward interpolation from the data:

x 0.1 0.2 0.3 0.4 0.5


.
f (x) 0.09983 0.19867 0.29552 0.38942 0.47943

6
Exercise 2.4. Compute the approximate value of sin x for x = 0.54 and x = 1.36 from the data:

x 0.5 0.7 0.9 1.1 1.3 1.5


.
sin x 0.47943 0.64422 0.78333 0.89121 0.96356 0.99749

Ans: 0.51386 & 0.977849


Exercise 2.5. Compute f (41) by using Newton’s backward interpolation 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.

2.0.3 L AGRANGE I NTERPOLATION F ORMULA


Theorem 2.3. The unique polynomial f (x) of degree less or equal to n − 1 which passes through the
points (x1 , y1 ), (x2 , y2 ), ..., (xn , yn ) where x′i s are distinct but not necessarily equidistant is given by:
k=n
X (x − x1 )(x − x2 )...(x − xk−1 )(x − xk+1 )...(x − xn )
f (x) = yk . .
(xk − x1 )(xk − x2 )...(xk − xk−1 )(xk − xk+1 )...(xk − xn )
k=1

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

Solution: By Lagrange Interpolation formula, we can write

(x − x1 )(x − x2 ) (x − x0 )(x − x2 ) (x − x0 )(x − x1 )


P (x) = P (x0 ) + P (x1 ) + P (x2 )
(x0 − x1 )(x0 − x2 ) (x1 − x0 )(x1 − x2 ) (x2 − x0 )(x2 − x1 )
(x − 3)(x − 4) (x − 1)(x − 4) (x − 1)(x − 3)
= ×1+ × 27 + × 64
(1 − 3)(1 − 4) (3 − 1)(3 − 4) (4 − 1)(4 − 3)
1 27 64
= (x2 − 7x + 12) − (x2 − 5x + 4) + (x2 − 4x + 3)
6 2 3
2
= 8x − 19x + 12

Exercise 2.6. Find the cubic Lagrange’s interpolating polynomial from the following data:

x 0 1 2 5
.
y 2 3 11 143

and verify the data. Hint. Ans: 11/10x3 + 1/5x2 − 3/10x + 2.

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.

3.1 T RAPEZOIDAL RULE


Rb
The approximation to the integral a f (x)dx is equal to the sum of the areas of the n trapeziums that are
made by partitioning the interval [a, b] ‘n′ number of times. Firstly, the area of each strip (trapezium) is
found separately then we take their sum. This method is one of the simplest techniques and it calculates
the integral of a function f (x) as the area under the curve representing f (x) by approximating it with the
sum of trapeziums.

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]

3.2 S IMPSON ’ S ONE - THIRD RULE

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

x 0 0.25 0.50 0.75 1.00


y 0 0.06153 0.22222 0.39560 0.5 .
y0 y1 y2 y3 y4

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,

b) Simpson’s 1/3 rule.


R 0.6 2
Exercise 3.2. Use Simpson’s 1/3 rd rule to find 0 e−x dx by taking seven ordinates. Ans: 0.5352
Exercise 3.3. Find an approximate value of ln 5 by calculating to four decimal places, by Simpson’s 1/3
R5 1
rule, 0 dx dividing the range into ten equal parts.
4x + 5
R 5.2
Exercise 3.4. Evaluate 4 ln xdx by Trapezoidal rule and Simpson’s 1/3 rule by using the following
data:
x 4.0 4.2 4.4 4.6 4.8 5.0 5.2
.
ln x 1.3863 1.4351 1.4816 1.5261 1.5686 1.6094 1.6487

Exercise 3.5. Numerically find an approximate value of the integral


Z 1
log(1 + x2 )
dx
0 1 + x2

using the Simpson’s 31 rd rule with 10 equal sub-intervals. [Ans: 0.1730]

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.

4.1 BASIC C ONCEPTS


A simple approximation of the first derivative is
f (x + h) − f (x)
f ′ (x) ≈ , (4.1)
h
where we assume that h > 0. The approximation (4.1) is called a forward differencing or one-sided
differencing. The approximation of the derivative at x that is based on the values of the function at x − h
and x, i.e.,
f (x) − f (x − h)
f ′ (x) ≈ , (4.2)
h
is called a backward differencing (which is obviously also a one-sided differencing formula). Let’s
compute the approximation error. We write a Taylor expansion of f (x + h) about x, i.e.,
h2 ′′
f (x + h) = f (x) + hf ′ (x) + f (ξ), ξ ∈ (x, x + h)
2
f (x + h) − f (x) h ′′
=⇒ f ′ (x) = − f (ξ), ξ ∈ (x, x + h). (4.3)
h 2
The second term on the right-hand-side of (4.3) is the error term. Since the approximation (4.1) can be
thought of as being obtained by truncating this term from the exact formula (4.3), this error is called the
truncation error. The small parameter h denotes the distance between the two points x and x+h. As this
distance tends to zero, i.e., h → 0, the two points approach each other and we expect the approximation
(4.1) to improve. This is indeed the case if the truncation error goes to zero, which in turn is the case if
f ′′ (ξ) is well defined in the interval (x, x + h). The “speed” in which the error goes to zero as h → 0
is called the rate of convergence. When the truncation error is of the order of O(h), we say that the
method is a first order method. We refer to a methods as a pth -order method if the truncation error is
of the order of O(hp ).

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

yi+1 = yi + hf (xi , yi ) (i.e., = yi + hfi ).

The formula is formed by the tangent line approximation in each step.

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

Example 4.1. For the IVP


y ′ + 2y = 2 − e−4t , y(0) = 1
Use Euler’s Method with a step size of h = 0.1 to find approximate values of the solution at t =
0.1, 0.2, 0.3, 0.4, 0.5. Compare them to the exact values of the solution at these points.

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.

f0 = f (0, 1) = −1, y1 = y0 + hf0 = 0.9

So, the approximation to the solution at t1 = 0.1 is y1 = 0.9. At the next step we have,

f1 = f (0.1, 0.9) = −0.470320046


y2 = y1 + hf1 = 0.852967995

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.:

xi yi xi+1 yi+1 = yi + hfi


0 0 .2 1
.2 1 .4 1.7041
.4 1.7041 .6 1.4256
.6 1.4256 .8 .3553
.8 .3553 1 -0.4358

So the final value of y at x = 1 is y = −0.4358 corrected up to 4 places of decimal.

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.:

xi yi xi+1 yi+1 = yi + hfi


.3 2 .4 1.84615
.4 1.84615 .5 1.7143
.5 1.7143 .6 1.6
.6 1.6 .7 1.5
.7 1.5 .8 1.4118
.8 1.4118 .9 1.3333

So the final value of y at x = .9 is y = 1.3333 corrected up to 4 places of decimal.

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 .

Step-II: Then the predicted value is corrected:


h
yi+1,c = yi + [fi + f (xi+1 , yi+1,p )].
2

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.:

xi yi xi+1 yi+1,p = yi + hfi yi+1,c = yi + h2 [fi + f (xi+1 , yi+1,p )]


0 .5 .2 .8 .82444
.2 .82444 .4 1.17333 1.18543
.4 1.18543 .6 1.55852 1.55553
.6 1.55553 .8 1.92263 1.9012
.8 1.9012 1 2.22544 2.18147

So the final value of y at x = 1 is y = 2.1815 corrected up to 4 places of decimal.

14

You might also like