Professional Documents
Culture Documents
FMA 0126
Mathematics Department
Copyright © 2021 UPNM
1 NUMERICAL METHODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Introduction 5
1.2 Location of Roots in an Interval 5
1.2.1 Graphical Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.2 Change of Sign Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.3 The Newton-Raphson Method . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3 Euler’s Method 18
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Books 25
Articles 25
1. NUMERICAL METHODS
Learning Outcomes
Upon completion of this chapter, students will be able to:
1. locate a root of an equation approximately, by graphically or searching
for a sign change.
2. approximate the root of an equation by Newton-Raphson method.
3. approximate the solution of y′ = f (x, y), y(a) = b using Euler’s
method.
1.1 Introduction
Many problems in science and engineering can not be solved analytically, that is, by
a method that uses known rules and logic to get to an exact solution. A numerical
method is used to approximate a solution, or at worst, bound where a solution would
lie.
This chapter we will focus on root finding and solving y′ = f (x, y), y(a) = b.
1
x3 − 5x + 10 = ln x, sin x + e2x x = 1, 2e−x = .
2−x
So numerical methods will need to be used to give you solutions which are close
to the exact solution. Numerical errors arise during computations due to round-off
errors and truncation errors. One way to reduce these errors is introducing a good
starting interval. This good interval able to speed up the process of finding solutions
and this helps to reduce errors.
The interval for a root of an equation in the form of f (x) = 0 can be determined
by using graphical method or the change of sign method.
Solution 1.1
40
35
30
3x2 + 2x − 3 25
20
15
10 x3
5
−5 −4 −3 −2 −1 1 2 3 4 5
−5
a. −10
■ Example 1.2 Find the interval(s) where the root(s) of the equation ex −x2 +3x = 2
lie by using graphical method.
■
Solution 1.2
6
ex
4
2 x2 − 3x + 2
−5 −4 −3 −2 −1 1 2 3 4 5
−2
Graphs of g(x) and h(x) are intersect in the interval (0, 1).
■Example 1.3 Find the interval(s) where the root(s) of the equation x = 2 sin x lie
by using graphical method.
■
Solution 1.3
Splits the equation into two simpler equations. g(x) = x and h(x) = 2 sin(x).
2
1.5
1
x
0.5
2 sin x
−5 −4 −3 −2 −1 1 2 3 4 5
−0.5
−1
−1.5
−2
Graphs of g(x) and h(x) are intersect in the interval (−2, −1) and (1, 2) and
origin.
8 Chapter 1. NUMERICAL METHODS
f (a) f (b)
a x0 b a x0 b
(x − 3)2
f (b) f (a)
(a) Change of signs from postive to nega- (b) Change of signs from negatie to posi-
tive tive
20 20
15
f (x) 15
10
5 10
−5 −4 −3 −2 −1 1 2 3 4 5 5
−5
−10
−15 −2 −1 1 2 3 4 5 6 7
−20 −5
(a) (b)
Figure 1.2a shows the curve cuts the x-axis at 3 different points which in-
dicates that f (x) has 3 different roots. These roots locate in the interval
(−4, −3), (−1, 0) and (0, 1).
1.2 Location of Roots in an Interval 9
If we were trying to find a root for f (x) and chose the interval (−1, 1). It
would appear that there isn’t a root between these values. The signs of f (−1)
and f (1) both be positive. But, from the Figure 1.2 shows that in the interval
(−1, 1) has 2 roots.
Solution 1.4
Substitute x = −1.2 and x = −1.1 into f (x):
f (−1.2) = (−1.2)3 − 3(−1.2)2 − 2(−1.2) + 3 = −0.648
f (−1.1) = (−1.1)3 − 3(−1.1)2 − 2(−1.1) + 3 = 0.239
f (−1.2) and f (−1.1) have different signs and f (x) is a continuous function,
so there is a solution in the interval −1.2 ≤ x ≤ −1.1.
■ Example 1.5 Show that function f (x) = x4 − 5x + 1 has a solution x = 1.64 for
f (x) = 0 correct to 2 decimal places. ■
Solution 1.5
The exact root must lie in the interval [1.635,1.645) because all values in
this interval round to 1.64.
f (1.635) = (1.635)4 − 5(1.635) + 1 = −0.0289
f (1.645) = (1.645)4 − 5(1.645) + 1 = 0.0976
Since f (1.635) and f (1.645) have different signs and all values in this
interval round to 1.64 (correct to 2 decimal places).So, x = 1.64 is the
solution for f (x) = x4 − 5x + 1 = 0.
■ Example 1.6
a. Complete the table below for y = x3 − 7x2 + 14x − 6.
b Hence, state the interval in which the roots of the equation x3 − 7x2 + 14x −
6 = 0 lies.
■
Solution 1.6
Solution 1.7
Let f (x) = ex − x2 + 3x − 2
f (−0.5) = e−0.5 − (−0.5)2 + 3(−0.5) − 2 = −3.143
f (0.5) = e0.5 − (0.5)2 + 3(0.5) − 2 = 0.899
Since f (−0.5) < 0 and f (0.5) > 0, the equation ex − x2 + 3x = 2 has a root
between x = −0.5 and x = 0.5, that is close to 0
Remark: x = 0.5 and x = −0.5 are one of the many choices. You
can choose any pairs close to x = 0. For example, x = −0.1 and x = 0.2 or
x = 0.5 and x = −0.2. As long as the pair is bracketing the x = 0.
Solution 1.8
a. f (1.5) = (1.5) − 2 sin(1.5) = −0.495
f (2.0) = (2.0) − 2 sin(2.0) = 0.184
(Remark: calculate trigonometry in radian)
(x1 , f (x1 ))
(x2 , f (x2 ))
(x3 , f (x3 ))
f (xn ) ′
xn+1 = xn − , f (x0 ) ̸= 0, n = 1, 2, 3... (1.1)
f ′ (xn )
■ Example 1.9 Find the roots of the equation x3 − 3x2 − 2x + 3 = 0 using Newton-
Raphson method correct to 2 decimal places with
12 Chapter 1. NUMERICAL METHODS
a. x = −1
b. x = 1
c. x = 3
d. x = 0
as a first approximation. ■
Solution 1.9
a. x0 = −1
f (x) = x3 − 3x2 − 2x + 3;
f (x0 ) = f (−1) = (−1)3 − 3(−1)2 − 2(−1) + 3 = 1
f ′ (x) = 3x2 − 6x − 2;
f ′ (x0 ) = f ′ (−1) = 3(−1)2 − 6(−1) − 2 = 7
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
1
x1 = −1 − = −1.1429
7
= −1.143(correct to 3 decimal places)
f (x1 )
x2 = x1 − ′
f (x1 )
−0.1257
x2 = −1.1429 − = −1.1286
8.7760
= −1.129(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
−0.0016
x3 = −1.1286 − = −1.1288
8.5928
= −1.129(correct to 3 decimal places)
b. x0 = 1
f (x) = x3 − 3x2 − 2x + 3;
f (x0 ) = f (1) = (1)3 − 3(1)2 − 2(1) + 3 = −1
f ′ (x) = 3x2 − 6x − 2;
f ′ (x0 ) = f ′ (1) = 3(1)2 − 6(1) − 2 = −5
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
1.2 Location of Roots in an Interval 13
−1
x1 = 1 − = 0.8
−5
f (x1 )
x2 = x1 − ′
f (x1 )
−0.008
x2 = 0.8 − = 0.7984
−4.88
= 0.798(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
−0.0002
x3 = 0.798 − = 0.7984
−4.8781
= 0.798(correct to 3 decimal places)
Since, x2 = x3 , the iteration is stop. An approximation to the root is
0.80 (correct to 2 decimal places)
c. x0 = 3
f (x) = x3 − 3x2 − 2x + 3;
f (x0 ) = f (3) = (3)3 − 3(3)2 − 2(3) + 3 = −3
f ′ (x) = 3x2 − 6x − 2;
f ′ (x0 ) = f ′ (3) = 3(3)2 − 6(3) − 2 = 7
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
−3
x1 = 3 − = 3.4286
7
= 3.429(correct to 3 decimal places)
f (x1 )
x2 = x1 − ′
f (x1 )
1.1862
x2 = 3.429 − = 3.3356
12.7001
= 3.336(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
0.0673
x3 = 3.336 − = 3.3301
11.3707
= 3.330(correct to 3 decimal places)
f (x3 )
x4 = x3 − ′
f (x3 )
14 Chapter 1. NUMERICAL METHODS
−0.0007
x4 = 3.33 − = 3.3301
11.2867
= 3.330(correct to 3 decimal places)
d. x0 = 0
f (x) = x3 − 3x2 − 2x + 3;
f (x0 ) = f (0) = (0)3 − 3(0)2 − 2(0) + 3 = 3
f ′ (x) = 3x2 − 6x − 2;
f ′ (x0 ) = f ′ (0) = 3(0)2 − 6(0) − 2 = −2
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
3
x1 = 0 − = 1.5
−2
f (x1 )
x2 = x1 − ′
f (x1 )
−3.3
x2 = 1.5 − = 0.5222
−3.375
= 0.522(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
1.2808
x3 = 0.522 − = 0.8189
−4.3146
= 0.819(correct to 3 decimal places)
f (x3 )
x4 = x3 − ′
f (x3 )
−0.1.009
x4 = 0.819 − = 0.7984
−4.9017
= 0.798(correct to 3 decimal places)
f (x4 )
x5 = x4 − ′
f (x4 )
0.0018
x5 = 0.798 − = 0.7984
−4.8776
= 0.798(correct to 3 decimal places)
■ Example 1.10 By taking 0.5 as a first approximation to the root of the equation
ex − x2 + 3x = 2, using the Newton-Raphson method, find this root correct to 2
decimal places. ■
Solution 1.10
Solution 1.11
a. Let f (x) = ln(x) + x − 2 = 0, g(x) = ln(x) and h(x) = 2 − x.
2
1.5 ln(x)
1
0.5
−0.5 1 2 3 4 5
−1 −x + 2
−1.5
−2
Graphs of g(x) and h(x) are intersect in the interval (1, 2).
b. Choose x0 = 1.5
f (x) = ln(x) + x − 2;
f (x0 ) = f (1.5) = ln(1.5) + (1.5) − 2 = −0.0945
f ′ (x) = 1x + 1;
f ′ (x0 ) = f ′ (1.5) = 1.5
1
+ 1 = 1.6667
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
−0.0945
x1 = 1.5 − = 1.5567
1.6667
= 1.558(correct to 3 decimal places)
f (x1 )
x2 = x1 − ′
f (x1 )
0.0014
x2 = 1.558 − = 1.5571
1.6418
= 1.557(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
−0.0002
x3 = 1.557 − = 1.5571
1.6423
= 1.557(correct to 3 decimal places)
Since, x3 = x2 , the iteration is stop. An approximation to the root is
1.56 (correct to 2 decimal places).
■ Example 1.12 Show that the equation x5 − 4x3 + 1 = 0 has a root in the interval
(0, 1). By using Newton-Raphson method to approximate the root correct to 2
decimal places. ■
Solution 1.12
f (x) = x5 − 4x3 + 1
f (0) = (0)5 − 4(0)3 + 1 = 1 > 0
f (1) = (1)5 − 4(1)3 + 1 = −2 < 0
Since f (0) > 0 and f (1) < 0, the equation x5 − 4x3 + 1 has a root in the
interval (0, 1).
Choose x0 = 0.5
f (x) = x5 − 4x3 + 1;
f (x0 ) = f (0.5) = (0.5)5 − 4(0.5)3 + 1 = 0.5313
f ′ (x) = 5x4 − 12x2 ;
f ′ (x0 ) = f ′ (0.5) = 5(0.5)4 − 12(0.5) = −2.6875
So,
f (x0 )
x1 = x0 −
f ′ (x0 )
0.5313
x1 = 0.5 − = 0.6977
−2.6875
= 0.698(correct to 3 decimal places)
f (x1 )
x2 = x1 − ′
f (x1 )
−0.1976
x2 = 0.698 − = 0.6562
−4.6896
= 0.656(correct to 3 decimal places)
f (x2 )
x3 = x2 − ′
f (x2 )
−0.0077
x3 = 0.656 − = 0.6542
−4.2381
= 0.654(correct to 3 decimal places)
f (x3 )
x4 = x3 − ′
f (x3 )
0.0007
x4 = 0.654 − = 0.6542
−4.2179
= 0.654(correct to 3 decimal places)
18 Chapter 1. NUMERICAL METHODS
Exercise 1.1
1. Show equation x7 + 4 = 0 has a root in the interval (−2, 0).
2. Find all the interval(s) contains the root(s) of the equation sin(x) = x2 − 2.
√
3. Sketch the function y = x2 − 1 and y = x on the same set of axes. Hence,
√
deduce the interval(s) where the solution of the equation x − x2 + 1 = 0
located.
4. Sketch the function f (x) = x − 3 and g(x) = ln x, x > 0 and find the inter-
val(s) where the root(s) of the equation x − 3 − ln x = 0 lie.
dy
= f (x, y), f (x0 ) = y0 .
dx
where f (x, y) is a smooth function on the interval [a, b].
b−a
Subdivide the interval [a, b] into n subintervals and let h = .
n
In summary, Euler’s method for approximating the solution to the initial-value
problem
dy
= f (x, y), f (x0 ) = y0 .
dx
at the points xn+1 = x0 + nh (n = 0, 1, ...) is
yn+1 = yn + h f (xn , yn ), n = 0, 1, ..
■ Example 1.13 Find y(1.0) accurates up to four decimal places using Euler’s
Solution 1.13
y′ = x2 − 0.2y, y(−2) = −1
on the interval [−2, 3] using the Euler’s method with the step size h = 1.0. (correct
to three decimal place) ■
Solution 1.14
We have
yn+1 = yn + h f (xn , yn ), n = 0, 1, ..
n = 0, x0 = −2, h = 1.0,
y0 = −1, f (xn , yn ) = xn2 − 0.2yn
x1 = −1.0, y1 = y0 + f (x0 , y0 )
= −1 + 1(−2)2 (−1)
= 3.2
x2 = 0.0, y2 = y1 + f (x1 , y1 )
= 3.2 + 1(−1)2 (3.2)
= 3.56
1.3 Euler’s Method 21
x3 = 1.0, y3 = y2 + f (x2 , y2 )
= 3.56 + 1(0)2 (3.56)
= 2.848
x4 = 2.0, y4 = y3 + f (x3 , y3 )
= 2.848 + 1(1)2 (2.848)
= 3.2784
x5 = 3.0, y5 = y4 + f (x4 , y4 )
= 3.278 + 1(1)2 (3.278)
= 6.6227
y(3.0) = 6.623(correct to 3d.p)
3y − 2x
■ Example 1.15 Solve y′ = , y(3) = 2
x+y
on the interval [3, 6] using the Euler’s method with the step size h = 0.5. (correct to
three decimal place) ■
Solution 1.15
yn+1 = yn + h f (xn , yn ), n = 0, 1, ..
n = 0, x0 = 3, h = 0.5,
3y − 2x
y0 = 2, f (xn , yn ) =
x+y
x1 = 3.5, y1 = y0 + f (x0 , y0 )
3(2) − 2(3)
= 2.0 + 0.5
(3) + (2)
=2
x2 = 4.0, y2 = y1 + f (x1 , y1 )
3.5(2) − 2(3.5)
= 2.0 + 0.5
(3.5) + (2)
= 1.9091
x3 = 4.5, y3 = y2 + f (x2 , y2 )
4(1.9091) − 2(4)
= 1.9091 + 0.5
(4) + (1.9091)
= 1.7168
22 Chapter 1. NUMERICAL METHODS
x4 = 5.0, y4 = y3 + f (x3 , y3 )
4(1.7168) − 2(4.5)
= 1.7168 + 0.5
(4.5) + (1.7168)
= 1.4072
x5 = 5.5, y5 = y4 + f (x4 , y4 )
4(1.4072) − 2(5.0)
= 1.4072 + 0.5
(5.0) + (1.4072)
= 0.9563
x5 = 6.0, y6 = y5 + f (x5 , y5 )
4(0.9563) − 2(5.5)
= 0.9563 + 0.5( )
(5.5) + (0.9563)
= 0.3266
y(6.0) = 0.327(correct to 3d.p)
Exercise 1.2
1. Find the first two approximations using Euler’s method for the initial value
dy
problem dx = y + 2 cos x, y(1) = 2, starting at x = 1 with step size h = 0.1.
Correct to 3 decimal places.
2. Use Euler’s method with step size 0.2 to estimate y(1.0) , where is the
solution of y′ = y + xy, y(0) = 1. Correct to 3 decimal places.
dy
4. Given the differential equation dx = yt with y(1) = 2 estimate y(1.5) using
Euler’s method with five equal steps. Correct to 3 decimal places.
dy
5. Given the differential equation dx = x + 2 and y(0) = 3. Find an approxi-
mation for y(1) by using Euler’s method with two equal steps. Correct to
2 decimal places.
dy 1
6. Given the differential equation dx = x+2 and y(0) = 1. Find an approxi-
mation of y(1) using Euler’s method with step size, h = 0.5. Correct to 2
decimal places.
dy
7. The curve passing through (2, 0) satifies the differential equation dx =
4x + y. Find an approximation to y(3) using Euler’s method with step size,
h = 0.2. Correct to 3 decimal places.
1.3 Euler’s Method 23
8. Assume that f and f ′ have the values given in the table. Use Euler’s
method with two equal steps to approximate the value of f (4.4). Correct
to 3 decimal places.
x 4 4.2 4.4
f ′ (x) -0.5 -0.3 -0.1
f (x) 2
Answer
1. 2.630 5. 5.25
2. 3.419 6. 1.45
3. 1.941 7. 13.860
4. 2.284 8. 1.90,1.84
1. By sketching the function f (x) = x − 1 − sin x show that there is a simple root
near x = 2. Use two iterations of the Newton-Raphson method to obtain a
better estimate of the root.
2. Sketch the function f (x) = x3 − x2 + 3 and confirm that there is a simple root
between x = −2 and x = −1. Use x0 = −2 as an initial estimate to obtain the
value to 2 d.p.
7. For the initial condition y(0) = 3, using Euler’s method with a step size
h = 0.1 to estimate the value of y at x = 0.5 for y′ − 2xy = 1.
8. Find the first two approximations using Euler’s method for the differential
dy
equation dx = 2y, y(1) = 2, starting at x = 1 with h = 0.1.
1
1. 1.935 5. b. f ′ (x) = 2x + √ +3
2. -1.17 2x − 1
c. 1.724
3. -0.669,0.882
6. 2.883
4. a.-1.159
7. 4.206
b.0.701
8. 2.88
c.0.701
9. a.1
b.13.5
Bibliography
Books
Articles