Lecture Notes All 2
Lecture Notes All 2
Maksat Ashyraliyev
Associate Professor, Dr.
MAT2045
Bahcesehir University
1
1 Introduction, Error Analysis, O nota-
tion
Mathematical problems are used to simulate real life phenomena. Some
of these problems can be solved analytically. For instance, the following
algebraic equation
x3 − x2 − 3x + 3 = 0
can be solved by hand. However, most of the mathematical prob-
lems are difficult or even impossible to solve analytically.
Therefore, numerical methods are needed to solve those problems with
the use of computers. Here are some examples of problems which can-
not be solved by hand:
• Nonlinear algebraic equation 2x + 3 cos x − ex = 0.
• System of linear algebraic equations Ax = b, where A is a very
large matrix.
Zπ p
• Definite integral 1 + cos2 xdx.
0
dy = ex2 ,
• etc.
Computers can only perform four arithmetic operations (addition,
subtraction, multiplication, division) and one logical operation (com-
parison). Numerical methods are techniques by which mathemat-
ical problems are formulated so that they can be solved with these
arithmetic and logical operations only.
Numerical result is always an approximation, while ana-
lytical result is exact. Numerical result can be as accurate as
needed but not exact!
2
Lecture Notes - Numerical Methods M.Ashyraliyev
Ex = |x − x̂|. (1.1)
3
Lecture Notes - Numerical Methods M.Ashyraliyev
4
Lecture Notes - Numerical Methods M.Ashyraliyev
where
f (n+1) (ξ)
Rn (x) = (x − x0 )n+1 (1.5)
(n + 1)!
Remark 1.1. If the remainder term Rn (x) in (1.3) is small enough then
function f (x) can be approximated with Taylor polynomial Pn (x). So
that
f (x) ≈ Pn (x). (1.6)
Then, the error in this approximation is the magnitude of the remain-
der term Rn (x), since E = |f (x) − Pn (x)| = |Rn (x)|. In numerical
analysis, remainder term (1.5) is usually called a truncation error of
approximation (1.6).
6
Lecture Notes - Numerical Methods M.Ashyraliyev
Now, let us find the order of Taylor polynomial that should be used to
approximate f (1) so that the error is less than 10−6 . We have
eξ e 3
Rn (1) = ≤ < < 10−6 =⇒ n ≥ 9.
(n + 1)! (n + 1)! (n + 1)!
So, analyzing the remainder term we can say that 9-th order Taylor
polynomial is certain to give an approximation with error less than
10−6 . Indeed, we have
1 1 1 1 1 1 1 1 1
P9 (1) = 1+ + + + + + + + + = 2.718281525573 . . .
1! 2! 3! 4! 5! 6! 7! 8! 9!
for which |f (1) − P9 (1)| = 0.000000302886 . . . < 10−6 .
x3 x5 x7 x9
1/2
= x+ + + + =
3 10 42 216 0
1 1 1 1 1
= + + + + = 0.54498672 . . . = p̂
2 3 · 23 10 · 25 42 · 27 216 · 29
7
Lecture Notes - Numerical Methods M.Ashyraliyev
Example 1.4. What is the maximum possible error in using the ap-
proximation
x3 x5
sin x ≈ x − +
3! 5!
when −0.3 ≤ x ≤ 0.3?
Solution: Using Taylor’s theorem for function f (x) = sin x with
x0 = 0, we have
x3 x5
sin x = x − + + R6 (x),
3! 5!
where
f (7) (ξ) 7 x7
R6 (x) = x = − cos (ξ)
7! 7!
Then for −0.3 ≤ x ≤ 0.3 we have
|x|7 0.37
|R6 (x)| ≤ ≤ ≈ 4.34 × 10−8 .
7! 7!
8
Lecture Notes - Numerical Methods M.Ashyraliyev
9
Lecture Notes - Numerical Methods M.Ashyraliyev
We observe that the values obtained from rounding method have less
errors than the values obtained from chopping method.
Remark 1.4. The error that results from replacing a number with
its floating-point form is called round-off error regardless of whether
the rounding or chopping method is used. However, rounding method
results in less error than chopping method and that’s why it is preferred
generally.
and
Q̂(2.19) = (2.19 − 3) · 2.19 + 3 · 2.19 − 1 =
Note that the polynomials P (x) and Q(x) are the same and
P (2.19) = Q(2.19) = 1.685159. Then, the absolute errors in approx-
imations of P (2.19) and Q(2.19), when three-digits arithmetic with
rounding method is used, are as following:
12
Lecture Notes - Numerical Methods M.Ashyraliyev
to grow up. Let us illustrate this issue on the base of two arithmetic
operations, addition and multiplication of two numbers.
Let p̂ be an approximation of number p and q̂ be an approximation
of number q. Then
p = p̂ + p and q = q̂ + q
where p and q are the errors in the approximations p̂ and q̂, respec-
tively. Assume that both p and q are positive. Then
p + q = p̂ + q̂ + (p + q ).
Therefore, approximation of p+q with p̂+ q̂ has an error p +q . So, the
absolute error in the sum p + q can be as large as the sum of absolute
errors in p and q.
Assuming that p ≈ p̂ and q ≈ q̂, we have
pq − p̂q̂ p̂q + q̂p + p q q p
Rpq = = ≈ + = Rq + Rp .
pq pq q p
So, the relative error in the product pq is approximately the sum of
relative errors in p and q.
1.3 O notation
Definition 1.2. Suppose {pn }∞ ∞
n=1 and {qn }n=1 are sequences of real
numbers. If there exist positive constants C and N such that
|pn | ≤ C|qn | for all n ≥ N,
then we say that {pn } is of order {qn } as n → ∞ and we write
pn = O(qn ).
13
Lecture Notes - Numerical Methods M.Ashyraliyev
Definition 1.3. Let f (x) and g(x) be two functions defined in some
open interval containing point a. If there exist positive constants C
and δ such that
|f (x)| ≤ C|g(x)| for all x with |x − a| < δ,
then we say that f (x) is of order g(x) as x → a and we write
f (x) = O(g(x)).
14
Lecture Notes - Numerical Methods M.Ashyraliyev
a) p = 3.1415927, p̂ = 3.1416
√
b) p = 2, p̂ = 1.414
c) p = 8!, p̂ = 39900
Problem 1.2. Find the fourth order Taylor polynomial for the func-
tion f (x) = cos x about x0 = 0.
Problem 1.3. Find the third order Taylor polynomial for the function
f (x) = x3 − 21x2 + 17 about x0 = 1.
a) Find the fifth order Taylor polynomial P5 (x) for given function
f (x) about x0 = 0
√
Problem 1.5. Let f (x) = x + 4.
a) Find the third order Taylor polynomial P3 (x) for given function
f (x) about x0 = 0
√ √
b) Use P3 (x) to approximate 3.9 and 4.2
15
Lecture Notes - Numerical Methods M.Ashyraliyev
Problem 1.6. Determine the order of Taylor polynomial Pn (x) for the
function f (x) = ex about x0 = 0 that should be used to approximate
e0.1 so that the error is less than 10−6 .
Problem 1.7. Determine the order of Taylor polynomial Pn (x) for the
function f (x) = cos x about x0 = 0 that should be used to approximate
cos (0.2) so that the error is less than 10−5 .
16
Lecture Notes - Numerical Methods M.Ashyraliyev
p
Problem 1.13. Consider two functions f (x) = x + 1 − x2 + x + 1
x
and g(x) = √ .
x + 1 + x2 + x + 1
a) Use four-digit arithmetic with rounding method to approximate
f (0.1) and find the relative error in obtained result.
(Note that the true value is f (0.1) = 0.0464346247 . . .)
17
Lecture Notes - Numerical Methods M.Ashyraliyev
ex − e−x
Problem 1.14. Let f (x) = .
x
a) Evaluate f (0.1) using four-digit arithmetic with rounding method
and find the relative error of obtained value.
(Note that the true value is f (0.1) = 2.0033350004 . . .)
b) Find the third order Taylor polynomial P3 (x) for given function
f (x) about x0 = 0.
x x2 x3 x4
(You can use the formula e = 1 + x + + + + . . .)
2! 3! 4!
c) For approximation of f (0.1) evaluate P3 (0.1) using four-digit
arithmetic with rounding method and find the relative error of
obtained value.
√
Problem 1.15. For which values of x the expression 2x2 + 1 − 1
would cause the loss of accuracy and how would you avoid the loss of
accuracy?
Problem 1.18. For each of the following functions, find the largest
possible value of α such that f (x) = O (xα ) as x → 0.
1 − cos x ex − e−x
a) f (x) = sin x−x b) f (x) = c) f (x) =
x x
18
2 Numerical Solution of Nonlinear Alge-
braic Equations
Consider a nonlinear algebraic equation
f (x) = 0. (2.1)
• Bracketing methods:
– Bisection method
– False Position method
• Open methods:
19
Lecture Notes - Numerical Methods M.Ashyraliyev
Remark 2.1. Open methods are usually more efficient than bracketing
methods. However, open methods may fail to converge to a root while
bracketing methods always converge.
20
Lecture Notes - Numerical Methods M.Ashyraliyev
|pn+1 | |qn+1 |
For simplicity we assume that ≈ 0.5 and ≈ 0.5 for all n.
|pn | |qn |2
Then
|pn | ≈ 0.5 · |pn−1 | ≈ 0.52 · |pn−2 | ≈ . . . ≈ 0.5n · |p0 | = 0.5n
and
n n n
−1 −1
|qn | ≈ 0.5 · |qn−1 |2 ≈ 0.53 · |qn−2 |4 ≈ . . . ≈ 0.52 · |q0 |2 = 0.52 .
Table below shows first few terms of these sequences. We can see that
quadratic convergence is much faster than the linear convergence.
n pn qn
1 5 × 10−1 5 × 10−1
2 2.5 × 10−1 1.25 × 10−1
3 1.25 × 10−1 7.8125 × 10−3
4 6.25 × 10−2 3.0518 × 10−5
5 3.125 × 10−2 4.6566 × 10−10
6 1.5625 × 10−2 1.0842 × 10−19
f (x) = 0, (2.2)
where f (x) is continuous function on interval [a, b] and f (a)f (b) < 0.
Then by using Theorem 2.1, there is at least one root p of equation
(2.2) in interval [a, b]. We assume for simplicity of our discussion that
the root p in interval [a, b] is unique.
To begin the Bisection method, we set a1 = a and b1 = b, as
shown in Figure 1. Let p1 be the midpoint of the interval [a1 , b1 ]. So,
a1 + b1
p1 = .
2
If f (p1 ) = 0, then p1 is the root of equation (2.2) and we can stop the
search. If f (p1 ) 6= 0, then f (p1 ) has the same sign as either f (a1 ) or
f (b1 ).
• If f (a1 ) and f (p1 ) have opposite signs, then root p must be in
the interval [a1 , p1 ] and we set
a2 = a1 and b2 = p1 .
a2 = p 1 and b2 = b1 .
22
Lecture Notes - Numerical Methods M.Ashyraliyev
such that
a1 ≤ a2 ≤ a3 ≤ . . . ≤ an−1 ≤ an ≤ p ≤ bn ≤ bn−1 ≤ . . . ≤ b3 ≤ b2 ≤ b1 .
p1 , p2 , p3 , . . . , pn−1 , pn
23
Lecture Notes - Numerical Methods M.Ashyraliyev
an + b n
where pn = .
2
24
Lecture Notes - Numerical Methods M.Ashyraliyev
interval has length one half of the length of preceding interval, we have
bn−1 − an−1 bn−2 − an−2 b1 − a1 b−a
b n − an = = = . . . = = .
2 22 2n−1 2n−1
an + bn
Then, since pn = and p ∈ [an , bn ], we get
2
b n − an b−a
|p − pn | ≤ = n
2 2
which completes the proof of this theorem.
Remark 2.5. (Advantages/disadvantages of Bisection method)
Results of Theorem 2.2 imply two obvious advantages of Bisection
method. First of all, Bisection method always converges. Moreover,
inequality (2.3) gives us an upper bound for the error when Bisection
b−a
method is used. So, the error after n iterations is less than .
2n
However, there is one important disadvantage of Bisection method.
It has very slow convergence. In fact, one can easily show that the
Bisection method has a linear convergence.
Remark 2.6. (Stopping conditions for Bisection method)
Suppose we want to obtain approximation pn of the root p within some
accuracy T OL, so that we expect |p − pn | < T OL to be satisfied for
some n. If the exact value of the root p is known in advance then at
each step of Algorithm 1 we can directly check the condition:
|p − pn | < T OL.
If the exact value of the root p is not known then we can use (2.3) to
guarantee the desired accuracy without knowing the value of p itself.
So, for stopping condition in Algorithm 1 we can use:
b−a
< T OL. (2.4)
2n
If after n iterations condition (2.4) is satisfied, then from (2.3) we have
b−a
|p − pn | ≤ < T OL =⇒ |p − pn | < T OL
2n
25
Lecture Notes - Numerical Methods M.Ashyraliyev
a1 + b1 0+1
1 step: We have p1 = = = 0.5.
2 2
Then f (p1 ) = f (0.5) = −0.625 < 0.
Since f (b1 )f (p1 ) < 0, we set a2 = p1 = 0.5 and b2 = b1 = 1.
Accuracy = |p − p1 | ≈ 0.0858 > 10−2 , so we continue with the
next step.
a2 + b2 0.5 + 1
2 step: We have p2 = = = 0.75.
2 2
Then f (p2 ) = f (0.75) = 0.984375 > 0.
Since f (a2 )f (p2 ) < 0, we set a3 = a2 = 0.5 and b3 = p2 = 0.75.
Accuracy = |p − p2 | ≈ 0.1642 > 10−2 , so we continue with the
next step.
a3 + b3 0.5 + 0.75
3 step: We have p3 = = = 0.625.
2 2
Then f (p3 ) = f (0.625) = 0.259765625 > 0.
Since f (a3 )f (p3 ) < 0, we set a4 = a3 = 0.5 and b4 = p3 = 0.625.
Accuracy = |p − p3 | ≈ 0.0392 > 10−2 , so we continue with the
next step.
26
Lecture Notes - Numerical Methods M.Ashyraliyev
a4 + b 4 0.5 + 0.625
4 step: We have p4 = = = 0.5625.
2 2
Then f (p4 ) = f (0.5625) = −0.161865234375 < 0.
Since f (b4 )f (p4 ) < 0, we set a5 = p4 = 0.5625, b5 = b4 = 0.625.
Accuracy = |p − p4 | ≈ 0.0233 > 10−2 , so we continue with the
next step.
a5 + b 5 0.5625 + 0.625
5 step: We have p5 = = = 0.59375.
2 2
Then f (p5 ) = f (0.59375) = 0.05404663085938 > 0.
Accuracy = |p − p5 | ≈ 0.0080 < 10−2 , so we can stop the itera-
tions.
27
Lecture Notes - Numerical Methods M.Ashyraliyev
a1 + b1 0+1
1 step: We have p1 = = = 0.5.
2 2
Then f (p1 ) = f (0.5) = 0.33070426790407 . . . > 0.
Since f (a1 )f (p1 ) < 0, we set a2 = a1 = 0 and b2 = p1 = 0.5.
b−a
Upper bound of error = = 0.5 > 10−1 , so we continue with
2
the next step.
a2 + b2 0 + 0.5
2 step: We have p2 = = = 0.25.
2 2
Then f (p2 ) = f (0.25) = −0.28662145743322 . . . < 0.
Since f (b2 )f (p2 ) < 0, we set a3 = p2 = 0.25 and b3 = b2 = 0.5.
b−a
Upper bound of error = 2
= 0.25 > 10−1 , so we continue
2
with the next step.
a3 + b3 0.25 + 0.5
3 step: We have p3 = = = 0.375.
2 2
Then f (p3 ) = f (0.375) = 0.03628111446785 . . . > 0.
Since f (a3 )f (p3 ) < 0, we set a4 = a3 = 0.25 and b4 = p3 = 0.375.
b−a
Upper bound of error = 3
= 0.125 > 10−1 , so we continue
2
with the next step.
a4 + b 4 0.25 + 0.375
4 step: We have p4 = = = 0.3125.
2 2
Then f (p4 ) = f (0.3125) = −0.12189942659342 . . . < 0.
b−a
Upper bound of error = 4
= 0.0625 < 10−1 , so we can stop
2
the iterations.
28
Lecture Notes - Numerical Methods M.Ashyraliyev
Note that the last column of Table 2 shows the upper bound of
error in approximation pn . The actual errors can be less than these
upper bounds. Indeed, the exact value of the root of the equation
(2.6) is p = 0.360421680476 . . . and the accuracy of approximation p4
is |p − p4 | ≈ 0.0479 which is less than the upper bound of error being
0.0625.
f (x) = 0, (2.7)
where f (x) is continuous function on interval [a, b] and f (a)f (b) < 0.
We begin the False Position method by setting a1 = a and
b1 = b. The line that passes through points a1 , f (a1 ) and b1 , f (b1 )
29
Lecture Notes - Numerical Methods M.Ashyraliyev
has an equation:
f (b1 ) − f (a1 )
y = f (a1 ) + (x − a1 ). (2.8)
b1 − a1
The intersection of this line with x-axis, we take as a first approxima-
tion of the root, denoted by p1 . Then, putting y = 0 and x = p1 in
(2.8) and solving it for p1 , we obtain
a1 f (b1 ) − b1 f (a1 )
p1 = .
f (b1 ) − f (a1 )
If f (p1 ) = 0, then p1 is the root of equation (2.7) and we can stop the
search. If f (p1 ) 6= 0, then f (p1 ) has the same sign as either f (a1 ) or
f (b1 ).
• If f (a1 ) and f (p1 ) have opposite signs, then root p must be in
the interval [a1 , p1 ] and therefore we set a2 = a1 and b2 = p1 .
a1 ≤ a2 ≤ a3 ≤ . . . ≤ an−1 ≤ an ≤ p ≤ bn ≤ bn−1 ≤ . . . ≤ b3 ≤ b2 ≤ b1 .
p1 , p2 , p3 , . . . , pn−1 , pn
where pn ∈ [an , bn ].
30
Lecture Notes - Numerical Methods M.Ashyraliyev
31
Lecture Notes - Numerical Methods M.Ashyraliyev
error is known from inequality (2.9). Finally, most of the time the False
Position method has faster convergence than the Bisection method
(but not always). However, convergence of False Position method is
still slow in comparison with more powerful Newton-Raphson method
which will be discussed later.
|p − pn | < T OL.
If the exact value of the root p is not known then we can use (2.9) to
guarantee the desired accuracy without knowing the value of p itself.
So, for stopping condition in Algorithm 2 we can use:
1. |f (pn )| < T OL
32
Lecture Notes - Numerical Methods M.Ashyraliyev
33
Lecture Notes - Numerical Methods M.Ashyraliyev
a4 f (b4 ) − b4 f (a4 )
4 step: We have p4 = = 0.59249466308157 . . .
f (b4 ) − f (a4 )
Then f (p4 ) = 0.04557101018090 . . . > 0.
Accuracy = |p − p4 | ≈ 0.0067 < 10−2 , so we can stop the itera-
tions.
34
Lecture Notes - Numerical Methods M.Ashyraliyev
a1 f (b1 ) − b1 f (a1 )
1 step: We have p1 = = 0.47098959459630 . . .
f (b1 ) − f (a1 )
Then f (p1 ) = 0.26515881591031 . . . > 0.
Since f (a1 )f (p1 ) < 0, we set a2 = a1 = 0 and
b2 = p1 = 0.47098959459630 . . .
Accuracy = |p − p1 | ≈ 0.1106 > 10−1 , so we continue with the
next step.
a2 f (b2 ) − b2 f (a2 )
2 step: We have p2 = = 0.37227705223507 . . .
f (b2 ) − f (a2 )
Then f (p2 ) = 0.02953366933827 . . . > 0.
Accuracy = |p − p2 | ≈ 0.0119 < 10−1 , so we can stop the itera-
tions.
35
Lecture Notes - Numerical Methods M.Ashyraliyev
f (x) = 0 (2.13)
Remark 2.11. Since (2.13) and (2.14) are equivalent, the fixed point
of function g(x) turns out to be a root of equation (2.13).
Remark 2.12. Note that the fixed point of function g(x) is the inter-
section of the line y = x and the graph of y = g(x).
36
Lecture Notes - Numerical Methods M.Ashyraliyev
Proof. Since assumptions of Theorem 2.4 are satisfied, g(x) has at least
one fixed point in [a, b]. Let us prove that the fixed point is unique.
Suppose g(x) has two different fixed points p and r in interval [a, b]
and r < p. So, g(p) = p and g(r) = r. The Mean Value Theorem
implies that there exists ξ ∈ (r, p) for which
g(p) − g(r) p − r
g 0 (ξ) = = =1
p−r p−r
which contradicts to assumption that |g 0 (x)| < 1 for all x ∈ (a, b). This
contradiction proves that the fixed point is unique.
x2 − 1
Example 2.6. Show that function g(x) = has a unique fixed
3
point in interval [−1, 1].
37
Lecture Notes - Numerical Methods M.Ashyraliyev
So, g(x) ∈ [−1, 1] for all x ∈ [−1, 1]. In addition, for all x ∈ (−1, 1)
we have
2x 2
|g 0 (x)| = ≤ < 1.
3 3
Then by Theorem 2.5 it follows that the given function g(x) has a
unique fixed point in interval [−1, 1]. Indeed,
p2 − 1
g(p) = p =⇒ = p =⇒ p2 − 3p − 1 = 0
3
√
3 − 13
which has only one root p = ≈ −0.303 in the interval [−1, 1].
2
Example 2.7. Consider the function g(x) = 3−x in the interval [0, 1].
Since g 0 (x) = −3−x ln 3 < 0 on [0, 1], the function g(x) is decreasing
on [0, 1]. So,
1
g(1) = ≤ g(x) ≤ 1 = g(0)
3
for 0 ≤ x ≤ 1. Thus, for x ∈ [0, 1] we have g(x) ∈ [0, 1], and from
Theorem 2.4 it follows that g(x) has a fixed point in interval [0, 1].
However,
g 0 (0) = − ln 3 = −1.098612289 . . .
so g 0 (x) 6< 1 on (0, 1) and Theorem 2.5 cannot be used to determine
uniqueness. But g(x) is always decreasing, and it is clear from the
graph of g(x) = 3−x in [0, 1] that the fixed point must be unique.
38
Lecture Notes - Numerical Methods M.Ashyraliyev
39
Lecture Notes - Numerical Methods M.Ashyraliyev
40
Lecture Notes - Numerical Methods M.Ashyraliyev
Remark 2.14. The inequality (2.16) gives us the upper bound for the
error involved in using pn to approximate fixed point p. As we can see
from (2.16), the rate of convergence of sequence {pn }∞
n=0 to fixed point
n
p depends on the factor k . The smaller the value of k, the faster the
convergence will be. However, the convergence may be very slow if k
is close to 1.
x2 − 2x − 3 = 0
So, g(x) ∈ [2, 4] for all x ∈ [2, 4]. In addition, for all x ∈ (2, 4) we have
1 1
g 0 (x) = √ ≤ √ < 1.
2x + 3 7
Then from Theorem 2.6 it follows that for any number p0 ∈ [2, 4] the
sequence {pn }∞n=0 defined by (2.15) must converge to the unique fixed
point p = 3 in interval [2, 4]. If we start with p0 = 4, successive fixed
point iterates are
p
p1 = g(p0 ) = 2p0 + 3 ≈ 3.316625,
p
p2 = g(p1 ) = 2p1 + 3 ≈ 3.103748,
p
p3 = g(p2 ) = 2p2 + 3 ≈ 3.034385,
p
p4 = g(p3 ) = 2p3 + 3 ≈ 3.011440,
p
p5 = g(p4 ) = 2p4 + 3 ≈ 3.003811
41
Lecture Notes - Numerical Methods M.Ashyraliyev
43
Lecture Notes - Numerical Methods M.Ashyraliyev
44
Lecture Notes - Numerical Methods M.Ashyraliyev
Then
|pn+1 − p| |f 00 (p)|
lim = K, where K =
n→∞ |pn − p|2 2|f 0 (p)|
which by definition means quadratic convergence.
|p − pn | < T OL.
If the exact value of the root p is not known then we can measure
relative or absolute precision. So, for stopping condition in Algorithm 4
we can use:
or
|pn+1 − pn |
< T OL (for relative precision)
|pn+1 |
46
Lecture Notes - Numerical Methods M.Ashyraliyev
47
Lecture Notes - Numerical Methods M.Ashyraliyev
48
Lecture Notes - Numerical Methods M.Ashyraliyev
49
Lecture Notes - Numerical Methods M.Ashyraliyev
a) Verify that the given equation has a root in the interval [0, 1].
b) Use the Bisection method to find first 3 approximations to the
root of given equation in the interval [0, 1].
c) Use the False Position method to find first 3 approximations to
the root of given equation in the interval [0, 1].
x3 − 2x2 − 5 = 0
Problem 2.3. Show that each of the following functions has a unique
fixed point in interval [0, 1]
50
Lecture Notes - Numerical Methods M.Ashyraliyev
Problem 2.5. Use the Fixed-Point iteration method with the starting
value p0 = 1 to approximate the root p = 1.94712296670701 . . . of the
equation
x4 − 3x2 − 3 = 0
within an accuracy 10−2 . Hint: first rearrange
the given equation to
the appropriate fixed-point form x = g(x)
x3 − 2x2 − 5 = 0
in interval [2, 3] within an accuracy of 10−4 . (You can use the exact
value of the root p = 2.69064744802878 . . .)
x(x2 + 2) = 4
51
3 Solutions of Linear Systems of Equa-
tions with Gaussian Elimination Method
Solving systems of linear equations is the most frequently used numer-
ical procedure when real-world situations are modeled. For instance,
numerical methods for solving ordinary ordinary and partial differen-
tial equations depend on them.
When a system of linear equations has many equations, it is difficult
to discuss them without using matrices and vectors. So, we first give
a brief overview of main concepts and terminology which are needed
later.
vn
Lowercase letters, such as u, v, a, b, x, . . . are used to denote vectors.
52
Lecture Notes - Numerical Methods M.Ashyraliyev
Definition 3.3. A matrix with the same number of rows and columns
is called a square matrix.
a11 a12 . . . a1n
a21 a22 . . . a2n
A= ... .. .. is a square matrix of size n × n.
. .
an1 an2 . . . ann
Definition 3.4. If all elements of square matrix below the main di-
agonal are 0 then the matrix is called an upper-triangular matrix.
For instance,
u11 u12 . . . u1n
0 u22 . . . u2n
U= ... .. .. (3.1)
. .
0 0 . . . unn
is an upper-triangular matrix.
Definition 3.5. If all elements of square matrix above the main diag-
onal are 0 then the matrix is called a lower-triangular matrix. For
instance,
l11 0 . . . 0
l21 l22 . . . 0
L= ... .. .. (3.2)
. .
ln1 ln2 . . . lnn
is a lower-triangular matrix.
53
Lecture Notes - Numerical Methods M.Ashyraliyev
Definition 3.6. A square matrix in which all the main diagonal ele-
ments are 1’s and all the remaining elements are 0’s is called an iden-
tity matrix.
1 0 ... 0
0 1 ... 0
In = ... ... .. is an identity matrix of size n
.
0 0 ... 1
54
Lecture Notes - Numerical Methods M.Ashyraliyev
1 2 1 0 1 −1 2 1
Example 3.2. · =
3 4 −1 1 0 −1 4 3
Remark 3.3. Finding the inverse of very large square matrix is com-
putationally expensive.
a11 a12
For instance, = a11 a22 − a12 a21 and
a21 a22
a11 a12 a13
a21 a22 a23 = a11 a22 a33 +a21 a32 a13 +a12 a23 a31 −a31 a22 a13 −a32 a23 a11 −a21 a12 a33 .
a31 a32 a33
55
Lecture Notes - Numerical Methods M.Ashyraliyev
Ax = b, (3.4)
x1
x2
where x =
... is the vector of unknowns,
xn
56
Lecture Notes - Numerical Methods M.Ashyraliyev
a11 a12 . . . a1n
a21 a22 . . . a2n
A=
... .. .. is given matrix of coefficients and
. .
a an2 . . . ann
n1
b1
b2
b=
...
is given right-hand side vector.
bn
does not have a solution and therefore it is inconsistent. Note that the
determinant of the matrix of coefficients is 0 for this system.
has infinitely many solutions. Note that the determinant of the matrix
of coefficients is 0 for this system.
57
Lecture Notes - Numerical Methods M.Ashyraliyev
The methods which are used to solve the system of linear equa-
tions can be classified into two classes: direct methods and iterative
methods. Here is the list of some of these methods:
• Direct methods
• Iterative methods
– Jacobi method
– Gauss-Seidel method
– SOR method (will not be studied in this course)
58
Lecture Notes - Numerical Methods M.Ashyraliyev
10
Solution: From the last equation we have x3 = = 5. Then from
2
the second equation we get
−1 − x3 −1 − 5
x2 = = = −1.
6 6
Finally, from the first equation we obtain
−3 − 3x2 + 2x3 −3 + 3 + 10
x1 = = = 2.
5 5
Remark 3.7. All elimination methods used for solving the system
(3.4), including the Gaussian elimination method, have a general strat-
egy which consists of two steps:
59
Lecture Notes - Numerical Methods M.Ashyraliyev
3.3.1 Triangularization
Definition 3.17. Matrix
a11 a12 . . . a1n b1
a21 a22 . . . a2n b2
[A|b] =
... .. .. ..
. . .
an1 an2 . . . ann bn
60
Lecture Notes - Numerical Methods M.Ashyraliyev
(1) (1)
where aij = aij and bi = bi for all i and j.
(1)
At the first step a11 is called a pivot element and the first row
(1)
is called a pivot row. Assume that a11 6= 0.
(1)
ai1
For each i = 2, 3, . . . , n we calculate mi1 = (1)
and then apply
a11
(2) (1) (1)
aij = aij − mi1 a1j , j = 2, 3, . . . , n
(3.6)
(2) (1) (1)
bi = bi − mi1 b1
(2)
2 step At the second step a22 is a pivot element and the second row
(2)
is a pivot row. Assume that a22 6= 0.
(2)
ai2
For each i = 3, 4, . . . , n we calculate mi2 = (2)
and then apply
a22
(3) (2) (2)
aij = aij − mi2 a2j , j = 3, 4, . . . , n
(3.7)
(3) (2) (2)
bi = bi − mi2 b2
61
Lecture Notes - Numerical Methods M.Ashyraliyev
−3 4
We first find m21 = = −3 and m31 = = 4.
1 1
Then we apply the following row operations: R2 = R2 + 3R1 and
R3 = R3 − 4R1 . This operations reduce the augmented matrix
to new form:
1 −1
3 13
0 −4 13 47
0 2 −11 − 37
62
Lecture Notes - Numerical Methods M.Ashyraliyev
2
2 step We first find m32 = = −0.5. Then the following row oper-
−4
ation R3 = R3 + 0.5R2 reduces the augmented matrix to new
form:
1 −1
3 13
0 −4 13 47
0 0 −4.5 − 13.5
So, the given system is equivalent to the following system in an upper-
triangular form:
x1 −
x2 + 3x3 = 13
−4x2 + 13x3 = 47
− 4.5x3 = −13.5
3.3.2 Pivoting
Gaussian Elimination method for triangularization has two pitfalls.
If at some step of the algorithm a zero is encountered on the main
diagonal then we cannot use that row to eliminate the coefficients
below that zero element. The following example illustrates this issue.
Example 3.8. Consider the system of equations:
x1 − x2 + 2x3 − x4 = −8
2x −
1 2x2 + 3x3 − 3x4 = −20
x1 + x2 + x3 = −2
x −
1 x2 + 4x3 + 3x4 = 4
63
Lecture Notes - Numerical Methods M.Ashyraliyev
Now, the pivot element for the second step is 0 and therefore the
procedure cannot continue in the present form.
So, trivial pivoting strategy suggests that for system in Example 3.8
after the first step of Gaussian Elimination algorithm we need to switch
the second and the third rows. That will change the augmented matrix
64
Lecture Notes - Numerical Methods M.Ashyraliyev
to the form:
1 −1 2 −1 −8
0 2 −1 1 6
0 0 −1 −1 −4
0 0 2 4 12
and now the algorithm can be continued with the next step.
5.291
The first pivot element is m21 = = 1763.6666 . . . which rounds
0.003
to m̂21 = 1764. Then, applying the row operation R2 = R2 − 1764R1
with four-digit rounding arithmetic reduces the augmented matrix to
new form:
0.003 59.14 59.17
0 −104300 − 104400
So, the given system by using the Gaussian Elimination Algorithm
with four-digit rounding arithmetic is reduced to the following system
65
Lecture Notes - Numerical Methods M.Ashyraliyev
in an upper-triangular form:
0.003x1 + 59.14x2 = 59.17
− 104300x2 ≈ −104400
• locate row r in which the element has the largest absolute value,
so n o
(k) (k) (k) (k)
|ark | = max |akk |, |ak+1,k |, . . . , |ank |
66
Lecture Notes - Numerical Methods M.Ashyraliyev
Example 3.10. Let us consider the system from the previous example:
0.003x1 + 59.14x2 = 59.17
5.291x1 − 6.130x2 = 46.78
and apply this time Gaussian Elimination method with partial pivoting
using four-digit arithmetic with rounding.
Solution: We start with the same augmented matrix
0.003 59.14 59.17
5.291 −6.130 46.78
Since 5.291 > 0.003, the partial pivoting strategy suggests that we
need to switch the rows. That will change the augmented matrix to
the form:
5.291 −6.130 46.78
0.003 59.14 59.17
0.003
Now, the first pivot element is m21 = = 0.000567000567 . . .
5.291
which rounds to m̂21 = 0.000567. Then, applying the row operation
R2 = R2 − 0.000567R1 with four-digit rounding arithmetic reduces the
augmented matrix to new form:
5.291 −6.130 46.78
0 59.14 59.14
So, the given system this time is reduced to the following system in an
upper-triangular form:
5.291x1 − 6.130x2 = 46.78
59.14x2 ≈ 59.14
Now, we can use the back-substitution method to find the solution of
the resulting system. From the second equation we immediately have
x̂2 = 1 which is the same as the actual value x2 = 1. Then, from the
first equation by using four-digit rounding arithmetic we obtain
46.78 + 6.130x2 46.78 + 6.130x̂2 46.78 + 6.130 52.91
x1 = ≈ = = = 10
5.291 5.291 5.291 5.291
67
Lecture Notes - Numerical Methods M.Ashyraliyev
So, x̂1 = 10 which is the same as the actual value x1 = 10. We see that
with partial pivoting we eliminated the round-off errors completely.
Solution: Let us solve the problem with the use of augmented matrix.
1 1 −1
0 1 1 2
1
!
Pivoting
1 1 −1 1 =⇒ =⇒ 0 1 1 2 =⇒
R1 ↔ R2
2 −1 −1 0 2 −1 −1 0
2 1 1 −1
1
=⇒ m31 = 1 = 2 =⇒ 0 1 1 2 =⇒
R3 = R3 − 2R1 0 −3 1 −2
−3 1 −1
1 1
=⇒ m32 = 1 = −3 =⇒ 0 1 1 2
R3 = R3 + 3R2 0 0 4 4
x2 + x3 = 2
4x3 = 4
Now with the back-substitution method we get x3 = 1, x2 = 1, x1 = 1.
68
Lecture Notes - Numerical Methods M.Ashyraliyev
4 −6 −4
1 3 2 5
2
!
Pivoting
2 4 −6 −4 =⇒ =⇒ 1 3 2 5 =⇒
R1 ↔ R2
1 5 3 10 1 5 3 10
1 4 −6 −4
2
=⇒ m21 = 2 = 0.5 =⇒ 0 1 5 7 =⇒
R2 = R2 − 0.5R1 1 5 3 10
1 4 −6 −4
2
=⇒ m31 = 2 = 0.5 =⇒ 0 1 5 7 =⇒
R3 = R3 − 0.5R1 0 3 6 12
4 −6 −4
2
!
Pivoting
=⇒ =⇒ 0 3 6 12 =⇒
R2 ↔ R3
0 1 5 7
1 4 −6 −4
2
m32 =
=⇒ 3 =⇒ 0 3 6 12
R3 = R3 − (1/3)R2 0 0 3 3
So, the given system is equivalent to the following system in an upper-
triangular form:
2x1 + 4x2 − 6x3 = −4
3x2 + 6x3 = 12
3x3 = 3
69
Lecture Notes - Numerical Methods M.Ashyraliyev
x1 − x2 + 3x3 = 2
3x1 − 3x2 + x3 = −1
x1 + x2 = 3
70
Lecture Notes - Numerical Methods M.Ashyraliyev
71
Lecture Notes - Numerical Methods M.Ashyraliyev
72
4 Solutions of Linear Systems of Equa-
tions with LU Factorization Method
Assume that A is nonsingular matrix and it can be written as
A=L·U (4.1)
Then to solve the given system, we first use the forward substitution
procedure for the lower triangular system
1 0 0
y1
7
Ly = b =⇒ − 1 1 0 · y2 = 2 =⇒
1 −1 1 y3 10
73
Lecture Notes - Numerical Methods M.Ashyraliyev
y1 = 7
=⇒ − y1 + y2 = 2 =⇒ y1 = 7, y2 = 9, y3 = 12.
y1 − y2 + y3 = 10
Next, we use the backward substitution procedure for the upper trian-
gular system
1 1 6
x1
7
Ux = y =⇒ 0 3 15 · x2 = 9 =⇒
0 0 12 x3 12
x1 + x2 + 6x3 = 7
=⇒ 3x2 + 15x3 = 9 =⇒ x3 = 1, x2 = −2, x1 = 3.
12x3 = 12
(k)
where all mij and aij are obtained from the Gaussian Elimination
procedure.
4 3 −1
A = − 2 −4 5 = 0 1 0 · − 2 −4 5 =
1 2 6 0 0 1 1 2 6
m21 = −0.5
3 −1
1 0 0
4
R2 = R2 + 0.5R1
= = − 0.5 1 0 · 0 −2.5 4.5 =
m31 = 0.25
0.25 0 1 0 1.25 6.25
R3 = R3 − 0.25R1
3 −1
1 0 0
4
!
m32 = −0.5
= = − 0.5 1 0 · 0 −2.5 4.5 = L·U
R3 = R3 + 0.5R2
0.25 −0.5 1 0 0 8.5
Example 4.3. Solve the following linear system:
x1 − x2 + 3x3 = 13
3x1 + x2 − 4x3 = −8
4x1 − 2x2 + x3 = 15
A = 3 1 −4 = 0 1 0 · 3 1 −4 =
4 −2 1 0 0 1 4 −2 1
75
Lecture Notes - Numerical Methods M.Ashyraliyev
m21 = 3
1 −1
1 0 0
3
R2 = R2 − 3R1
= = 3 1 0 · 0 4 −13 =
m 31 = 4
4 0 1 0 2 −11
R3 = R3 − 4R1
1 −1
1 0 0
3
!
m32 = 0.5
= = 3 1 0 · 0 4 −13 = L·U
R3 = R3 − 0.5R2
4 0.5 1 0 0 −4.5
Then to solve the given system, we first use the forward substitution
procedure for the lower triangular system
1 0 0
y1
13
Ly = b =⇒ 3 1 0 · y2 = − 8 =⇒
4 0.5 1 y3 15
y1
= 13
3y1 + y2 = −8 =⇒ y1 = 13, y2 = −47, y3 = −13.5
4y1 + 0.5y2 + y3 = 15
Next, we use the backward substitution procedure for the upper trian-
gular system
1 −1
3
x1
13
Ux = y =⇒ 0 4 −13 · x2 = − 47 =⇒
0 0 −4.5 x3 − 13.5
x1 − x2 + 3x3 =
13
4x2 − 13x3 = −47 =⇒ x3 = 3, x2 = −2, x1 = 2.
− 4.5x3 = −13.5
76
Lecture Notes - Numerical Methods M.Ashyraliyev
A = 4 8 −1 = 0 1 0 · 4 8 −1 =
−2 3 5 0 0 1 −2 3 5
m21 = 4
1 0 0
1 2 6
R2 = R2 − 4R1
= m = −2 =
4 1 0 · 0 0 −25
31
−2 0 1 0 7 17
R3 = R3 + 2R1
and we cannot continue without pivoting.
Example 4.4. Let us consider again the matrix A from Remark 4.1
1 2 6
A = 4 8 −1
−2 3 5
We have shown already that we cannot obtain for this matrix LU
factorization without pivoting. For this matrix A there exists the
permutation matrix P such that PA can be factored as LU. Indeed,
with
0 1 0
P = 0 0 1
1 0 0
we have
4 8 −1
0 1 0
1 2 6
P·A = 0 0 1 · 4 8 −1 = − 2 3 5 =
1 0 0 −2 3 5 1 2 6
m21 = −0.5
4 8 −1
1 0 0
R2 = R2 + 0.5R1
= 0 1 0 · −2 3 5 =
m31 = 0.25
0 0 1 1 2 6
R3 = R3 − 0.25R1
4 8 −1
1 0 0
= − 0.5 1 0 · 0 7 4.5 = L · U
0.25 0 1 0 0 6.25
78
Lecture Notes - Numerical Methods M.Ashyraliyev
A = 6 4 12 , x = x2 , b = 2
8 −3 2 x3 0
4 11 −1
1 0 0
1 0 0
!
Pivoting
0 1 0 ·A = 0 1 0 · 6 4 12 =⇒ =⇒
R1 ↔ R3
0 0 1 0 0 1 8 −3 2
8 −3 2
0 0 1
1 0 0
!
Row
0 1 0 ·A = 0 1 0 · 6 4 12 =⇒ =⇒
operations
1 0 0 0 0 1 4 11 −1
8 −3
0 0 1
1 0 0
2
!
Pivoting
0 1 0 ·A = 0.75 1 0 · 0 6.25 10.5 =⇒ =⇒
R2 ↔ R3
1 0 0 0.5 0 1 0 12.5 −2
8 −3
0 0 1
1 0 0
2
!
Row
1 0 0 ·A = 0.5 1 0 · 0 12.5 −2 =⇒ =⇒
operation
0 1 0 0.75 0 1 0 6.25 10.5
79
Lecture Notes - Numerical Methods M.Ashyraliyev
8 −3
0 0 1
1 0 0
2
1 0 0 ·A = 0.5 1 0 · 0 12.5 −2 =⇒ P·A = L·U
0 1 0 0.75 0.5 1 0 0 11.5
where
8 −3
0 0 1
1 0 0
2
P = 1 0 0 , L = 0.5 1 0 , U = 0 12.5 −2 .
0 1 0 0.75 0.5 1 0 0 11.5
Ax = b =⇒ PAx = Pb =⇒ LUx = b̃
where
0 0 1
27
0
b̃ = Pb = 1 0 0 · 2 = 27
0 1 0 0 2
Then to solve the system LUx = b̃, we first use the forward substitu-
tion procedure for the lower triangular system
1 0 0
y1
0
Ly = b̃ =⇒ 0.5 1 0 · y2 = 27 =⇒
0.75 0.5 1 y3 2
y1 = 0
0.5y1 + y2 = 27 =⇒ y1 = 0, y2 = 27, y3 = −11.5
0.75y1 + 0.5y2 + y3 = 2
8 −3
2
x1
0
Ux = y =⇒ 0 12.5 −2 · x2 = 27 =⇒
0 0 11.5 x3 − 11.5
80
Lecture Notes - Numerical Methods M.Ashyraliyev
8x1 −
3x2 + 2x3 = 0
12.5x2 − 2x3 = 27 =⇒ x3 = −1, x2 = 2, x1 = 1.
11.5x3 = −11.5
81
Lecture Notes - Numerical Methods M.Ashyraliyev
−x1 + 2x2 − x3 = −3
− x2 + 2x3 = 1
2x1 − x2
= 3
82
Lecture Notes - Numerical Methods M.Ashyraliyev
83
5 Iterative Methods for Linear Systems
Definition 5.1. A square matrix A of size n × n is called strictly
diagonally dominant if
6 −2 1
A = −2 7 2
1 2 −5
84
Lecture Notes - Numerical Methods M.Ashyraliyev
Ax = b =⇒ (D + L + U)x = b =⇒ Dx = b − (L + U)x =⇒
=⇒ x = D−1 b − D−1 (L + U)x =⇒ x = Tx + b̃,
x(k+1) = Tx(k) + b̃
86
Lecture Notes - Numerical Methods M.Ashyraliyev
kx(k+1) − x(k) k
• < T OL for relative precision
kx(k+1) k
Here kxk denotes the norm of the vector x. One of the most commonly
used norms, which we will use here, is the maximum norm defined as
87
Lecture Notes - Numerical Methods M.Ashyraliyev
(k) (k)
(k+1) 7 + x2 − x3
x1 =
4
(k) (k)
(k+1) 21 + 4x1 + x3
x2 =
8
(k) (k)
(k+1) 15 + 2x1 − x2
x3 =
5
1 step: We have
(0) (0)
(1) 7 + x2 − x3 7+2−2
x1 = = = 1.75
4 4
(0) (0)
(1) 21 + 4x1 + x3 21 + 4 · 1 + 2
x2 = = = 3.375
8 8
(0) (0)
(1) 15 + 2x1 − x2 15 + 2 · 1 − 2
x3 = = =3
5 5
So,
1.75
(1)
kx(1) − x(0) k∞
x = 3.375 =⇒ ≈ 0.41 > 0.1
kx(1) k∞
3
2 step: We have
(1) (1)
(2) 7 + x2 − x3 7 + 3.375 − 3
x1 = = = 1.84375
4 4
(1) (1)
(2) 21 + 4x1 + x3 21 + 4 · 1.75 + 3
x2 = = = 3.875
8 8
(1) (1)
(2) 15 + 2x1 − x2 15 + 2 · 1.75 − 3.375
x3 = = = 3.025
5 5
88
Lecture Notes - Numerical Methods M.Ashyraliyev
So,
1.84375
kx(2) − x(1) k∞
x(2) =
3.875 =⇒ ≈ 0.13 > 0.1
kx(2) k∞
3.025
3 step: We have
(2) (2)
(3) 7 + x2 − x3 7 + 3.875 − 3.025
x1 = = = 1.9625
4 4
(2) (2)
(3) 21 + 4x1 + x3 21 + 4 · 1.84375 + 3.025
x2 = = = 3.925
8 8
(2) (2)
(3) 15 + 2x1 − x2 15 + 2 · 1.84375 − 3.875
x3 = = = 2.9625
5 5
So,
1.9625
(3)
kx(3) − x(2) k∞
x = 3.925 =⇒ ≈ 0.03 < 0.1
kx(3) k∞
2.9625
89
Lecture Notes - Numerical Methods M.Ashyraliyev
Note that it is the same system as the one in Example 5.1 with different
order of equations. Now, the Jacobi iterations have the form
(k) (k)
(k+1) x + 5x3 − 15
x1 = 2
2
(k) (k)
(k+1) 21 + 4x1 + x3
x2 =
8
(k+1) (k) (k)
x3 = 7 − 4x1 + x2
Let’s start with the same initial values as we had in Example 5.1
(0)
x1 1
(0)
x(0) =
x2 = 2
(0)
x3 2
1 step: We have
(0) (0)
(1) x + 5x3 − 15 2 + 5 · 2 − 15
x1 = 2 = = −1.5
2 2
(0) (0)
(1) 21 + 4x1 + x3 21 + 4 · 1 + 2
x2 = = = 3.375
8 8
(1) (0) (0)
x3 = 7 − 4x1 + x2 = 7 − 4 · 1 + 2 = 5
2 step: We have
(1) (1)
(2) x + 5x3 − 15 3.375 + 5 · 5 − 15
x1 = 2 = = 6.6875
2 2
(1) (1)
(2) 21 + 4x1 + x3 21 + 4 · (−1.5) + 5
x2 = = = 2.5
8 8
(2) (1) (1)
x3 = 7 − 4x1 + x2 = 7 − 4 · (−1.5) + 3.375 = 16.375
90
Lecture Notes - Numerical Methods M.Ashyraliyev
91
Lecture Notes - Numerical Methods M.Ashyraliyev
92
Lecture Notes - Numerical Methods M.Ashyraliyev
1 step: We have
(0) (0)
(1) 7 + x2 − x3 7+2−2
x1 = = = 1.75
4 4
(1) (0)
(1) 21 + 4x1 + x3 21 + 4 · 1.75 + 2
x2 = = = 3.75
8 8
(1) (1)
(1) 15 + 2x1 − x2 15 + 2 · 1.75 − 3.75
x3 = = = 2.95
5 5
So,
1.75
(1)
kx(1) − x(0) k∞
x = 3.75 =⇒ ≈ 0.47 > 0.1
kx(1) k∞
2.95
2 step: We have
(1) (1)
(2) 7 + x2 − x3 7 + 3.75 − 2.95
x1 = = = 1.95
4 4
(2) (1)
(2) 21 + 4x1 + x3 21 + 4 · 1.95 + 2.95
x2 = = = 3.96875
8 8
(2) (2)
(2) 15 + 2x1 − x2 15 + 2 · 1.95 − 3.96875
x3 = = = 2.98625
5 5
So,
1.95
(2)
kx(2) − x(1) k∞
x = 3.96875 =⇒ ≈ 0.055 < 0.1
kx(2) k∞
2.98625
93
Lecture Notes - Numerical Methods M.Ashyraliyev
6x1 − 2x2 + x3 = 11
− 2x1 + 7x2 + 2x3 = 5
x1 + 2x2 − 5x3 = −1
x1 − 5x2 − x3 = 8
4x1 + x2 − x3 = 13
2x1 − x2 − 5x3 = −1
94
Lecture Notes - Numerical Methods M.Ashyraliyev
6x1 − 2x2 + x3 = 11
− 2x1 + 7x2 + 2x3 = 5
x1 + 2x2 − 5x3 = −1
x1 − 5x2 − x3 = = 8
4x1 + x2 − x3 = 13
2x1 − x2 − 5x3 = −1
95
6 Newton’s Method for Systems of Non-
linear Equations
We have seen the Newton-Raphson method for numerical solution of
nonlinear algebraic equation. In this section we will study the gener-
alization of that method for systems of nonlinear equations.
Consider the system of n nonlinear equations
f1 (x1 , x2 , x3 , . . . , xn ) = 0
f2 (x1 , x2 , x3 , . . . , xn ) = 0
f3 (x1 , x2 , x3 , . . . , xn ) = 0 (6.1)
........................
fn (x1 , x2 , x3 , . . . , xn ) = 0
97
Lecture Notes - Numerical Methods M.Ashyraliyev
kx(k+1) − xk
• < T OL for relative accuracy
kxk
If the exact solution is not known then the following conditions for
precision can be used to stop the Newton’s iterations:
kx(k+1) − x(k) k
• < T OL for relative precision
kx(k+1) k
98
Lecture Notes - Numerical Methods M.Ashyraliyev
Solution: Let
" # " #
x1 x21 − 2x1 − x2 + 0.5
x= and F(x) =
x2 x21 + 4x22 − 4
1 step: We have
22 − 2 · 2 − 0.25 + 0.5
" # " #
0.25
F(x(0) ) = =
22 + 4 · 0.252 − 4 0.25
" # " #
2·2−2 −1 2 −1
J(x(0) ) = =
2·2 8 · 0.25 4 2
Then
(
(0) (0)
(0) (0) (0) 24x1 − 4x2 = −0.25
J(x )·4x = −F(x ) =⇒ (0) (0)
44x1 + 24x2 = −0.25
99
Lecture Notes - Numerical Methods M.Ashyraliyev
−0.25 −1
(0)
− 0.25 2 −0.75
4x1 = = = −0.09375
2 −1 8
4 2
2 −0.25
(0)
4 −0.25 0.5
4x2 = = = 0.0625
2 −1 8
4 2
Then
" # " # " #
2 −0.09375 1.90625
x(1) = x(0) + 4x(0) = + =
0.25 0.0625 0.3125
2 step: We have
100
Lecture Notes - Numerical Methods M.Ashyraliyev
Then " #
1.90069054307116
x(2) = x(1) + 4x(1) =
0.31121254681648
1 step: We have
0.53 + 0.5 − 1
" # " #
−0.375
F(x(0) ) = =
0.53 − 0.5 + 1 0.625
" # " #
3 · 0.52 1 0.75 1
J(x(0) ) = =
−1 3 · 0.52 − 1 0.75
101
Lecture Notes - Numerical Methods M.Ashyraliyev
Then
J(x(0) ) · 4x(0) = −F(x(0) ) =⇒
(
(0) (0)
0.754x1 + 4x2 = 0.375
=⇒ (0) (0)
− 4x1 + 0.754x2 = −0.625
Solving this linear system with Cramer’s rule we get
0.375 1
(0)
− 0.625 0.75 0.90625
4x1 = = = 0.58
0.75 1 1.5625
− 1 0.75
0.75 0.375
(0)
− 1 −0.625 −0.09375
4x2 = = = −0.06
0.75 1 1.5625
− 1 0.75
Then
" # " # " #
0.5 0.58 1.08
x(1) = x(0) + 4x(0) = + =
0.5 − 0.06 0.44
" # " # " #
1.08 1 0.08
x(1) −x = − = =⇒ kx(1) −xk∞ = 0.44 > 0.05
0.44 0 0.44
2 step: We have
1.083 + 0.44 − 1
" # " #
0.699712
F(x(1) ) = =
0.443 − 1.08 + 1 0.005184
" # " #
3 · 1.082 1 3.4992 1
J(x(1) ) = =
−1 3 · 0.442 − 1 0.5808
102
Lecture Notes - Numerical Methods M.Ashyraliyev
Then
J(x(1) ) · 4x(1) = −F(x(1) ) =⇒
(
(1) (1)
3.49924x1 + 4x2 = −0.699712
=⇒ (1) (1)
− 4x1 + 0.58084x2 = −0.005184
Then " #
0.94768985551783
x(2) = x(1) + 4x(1) =
0.20326765757202
" #
−0.05231014448217
x(2) −x = =⇒ kx(2) −xk∞ ≈ 0.20 > 0.05
0.20326765757202
3 step: We have
" #
0.05440313884529
F(x(2) ) =
0.06070870483311
" #
2.69434818675420 1
J(x(2) ) =
−1 0.12395322184444
Then
J(x(2) ) · 4x(2) = −F(x(2) ) =⇒
(
(2) (2)
2.69434818675424x1 + 4x2 = −0.05440313884529
=⇒ (2) (2)
− 4x1 + 0.123953221844444x2 = −0.06070870483311
103
Lecture Notes - Numerical Methods M.Ashyraliyev
Then " #
0.98814438862387
x(3) = x(2) + 4x(2) =
0.03986592080647
" #
−0.01185561137613
x(3) −x = =⇒ kx(3) −xk∞ ≈ 0.04 < 0.05
0.03986592080647
(0) (0)
Use Newton’s method with the starting values x1 , x2 = (1.2, 0.7)
(1) (1) (2) (2)
and compute first two approximations x1 , x2 and x1 , x2 .
(0) (0)
Use Newton’s method with the starting values x1 , x2 = (6, −3) to
approximate solution of given system within relative precision 10−3 .
104
Lecture Notes - Numerical Methods M.Ashyraliyev
105
7 Interpolation and Polynomial Approx-
imations
We have seen already how Taylor polynomials can be used to approx-
imate functions. Taylor polynomials of function f (x) about point x0
give accurate approximation only near that point. A good approxima-
tion polynomial needs to provide a relatively accurate result over large
intervals. Another disadvantage of using Taylor polynomials is that
derivatives of f (x) must be available.
In this section we will study the interpolation methods to approx-
imate functions with polynomials that exactly represents a collection
of data points. Suppose function y = f (x) is known at n + 1 points,
i.e. its graph passes through points:
where
Pn (x) = Ln,0 (x)y0 + Ln,1 (x)y1 + Ln,2 (x)y2 + · · · + Ln,n (x)yn (7.2)
106
Lecture Notes - Numerical Methods M.Ashyraliyev
where
(x − x0 )(x − x1 ) · · · (x − xk−1 )(x − xk+1 ) · · · (x − xn )
Ln,k (x) =
(xk − x0 )(xk − x1 ) · · · (xk − xk−1 )(xk − xk+1 ) · · · (xk − xn )
Remark 7.2. Assume that we have only two data points (x0 , y0 ) and
(x1 , y1 ). Using formula (7.2), the first order Lagrange interpolating
polynomial that passes through these two points has the form
x − x1 x − x0
P1 (x) = y0 + y1 .
x0 − x1 x1 − x0
Remark 7.3. Assume that we have three data points (x0 , y0 ), (x1 , y1 )
and (x2 , y2 ). Using formula (7.2), the second order Lagrange interpo-
lating polynomial that passes through these three points has the form
(x − x1 )(x − x2 ) (x − x0 )(x − x2 ) (x − x0 )(x − x1 )
P2 (x) = y0 + y1 + y2 .
(x0 − x1 )(x0 − x2 ) (x1 − x0 )(x1 − x2 ) (x2 − x0 )(x2 − x1 )
Remark 7.4. Assume that we have four data points (x0 , y0 ), (x1 , y1 ),
(x2 , y2 ) and (x3 , y3 ). Using formula (7.2), the third order Lagrange
107
Lecture Notes - Numerical Methods M.Ashyraliyev
interpolating polynomial that passes through these four points has the
form
(x − x1 )(x − x2 )(x − x3 ) (x − x0 )(x − x2 )(x − x3 )
P3 (x) = y0 + y1 +
(x0 − x1 )(x0 − x2 )(x0 − x3 ) (x1 − x0 )(x1 − x2 )(x1 − x3 )
(x − x0 )(x − x1 )(x − x3 ) (x − x0 )(x − x1 )(x − x2 )
+ y2 + y3 .
(x2 − x0 )(x2 − x1 )(x2 − x3 ) (x3 − x0 )(x3 − x1 )(x3 − x2 )
f (n+1) (ξ)
En (x) = (x − x0 )(x − x1 )(x − x2 ) · · · (x − xn )
(n + 1)!
is the error term.
xk 0 20 40
yk 3.85 0.8 0.12
108
Lecture Notes - Numerical Methods M.Ashyraliyev
and
15 − 20 15 − 0
f (15) ≈ P1 (15) = · 3.85 + · 0.8 = 1.5625
0 − 20 20 − 0
Now, suppose that we want to construct the second order Lagrange
polynomial to approximate f (15). We have to use all three data points.
Then
(x − 20)(x − 40) (x − 0)(x − 40)
P2 (x) = · 3.85 + · 0.8+
(0 − 20)(0 − 40) (20 − 0)(20 − 40)
(x − 0)(x − 20)
+ · 0.12
(40 − 0)(40 − 20)
and
(15 − 20)(15 − 40) (15 − 0)(15 − 40)
f (15) ≈ P2 (15) = · 3.85 + · 0.8+
(0 − 20)(0 − 40) (20 − 0)(20 − 40)
(15 − 0)(15 − 20)
+ · 0.12 = 1.3403125
(40 − 0)(40 − 20)
xk −1 0 1 2 3
yk 2 1 2 −7 10
and
(0.5 − 0)(0.5 − 1)(0.5 − 2)
f (0.5) ≈ P3 (0.5) = · 2+
(−1 − 0)(−1 − 1)(−1 − 2)
(0.5 + 1)(0.5 − 1)(0.5 − 2)
+ · 1+
(0 + 1)(0 − 1)(0 − 2)
(0.5 + 1)(0.5 − 0)(0.5 − 2)
+ · 2+
(1 + 1)(1 − 0)(1 − 2)
(0.5 + 1)(0.5 − 0)(0.5 − 1)
+ · (−7) =
(2 + 1)(2 − 0)(2 − 1)
=2
110
Lecture Notes - Numerical Methods M.Ashyraliyev
f [xk ] = f (xk ), k = 0, 1, . . . , n
f [xk ] − f [xk−1 ]
f [xk−1 , xk ] = , k = 1, 2, . . . , n
xk − xk−1
f [xk−1 , xk ] − f [xk−2 , xk−1 ]
f [xk−2 , xk−1 , xk ] = , k = 2, 3, . . . , n
xk − xk−2
f [xk−2 , xk−1 , xk ] − f [xk−3 , xk−2 , xk ]
f [xk−3 , xk−2 , xk−1 , xk ] = , k = 3, 4, . . . , n
xk − xk−3
......................................................
f [x1 , x2 , . . . , xn ] − f [x0 , x1 , . . . , xn−1 ]
f [x0 , x1 , x2 , . . . , xn ] =
xn − x0
Example 7.3. Construct the third order Newton polynomial for the
data given in the following table:
xk 1 2 3 4
f (xk ) −3 0 15 48
111
Lecture Notes - Numerical Methods M.Ashyraliyev
112
Lecture Notes - Numerical Methods M.Ashyraliyev
113
Lecture Notes - Numerical Methods M.Ashyraliyev
Problem 7.7. Let P3 (x) be the interpolating polynomial for the data
(0, 0), (1, A), (2, 4), and (4, 2). Find A if the coefficient of x3 in P3 (x)
5
is 12 .
115
8 Spline Interpolation
Polynomial interpolation for a set of n + 1 points
(x0 , y0 ), (x1 , y1 ), (x2 , y2 ), . . . , (xn , yn )
is often unsatisfactory when n is large, since high-degree polynomials
can have oscillations. Here we will discuss an alternative approach,
piecewise interpolation method, using lower-degree polynomials which
interpolate between nodes (xk , yk ) and (xk+1 , yk+1 ).
The simplest piecewise polynomial interpolation, called linear splines,
joins the data points (xk , yk ) and (xk+1 , yk+1 ) by a straight line segment.
116
Lecture Notes - Numerical Methods M.Ashyraliyev
a0 + b0 (x − x0 ) + c0 (x − x0 )2 + d0 (x − x0 )3 , if x ∈ [x0 , x1 )
a1 + b1 (x − x1 ) + c1 (x − x1 )2 + d1 (x − x1 )3 , if x ∈ [x1 , x2 )
S(x) =
.......................................
an−1 + bn−1 (x − xn−1 ) + cn−1 (x − xn−1 )2 + dn−1 (x − xn−1 )3 , x ∈ [xn−1 , xn ]
(8.2)
117
Lecture Notes - Numerical Methods M.Ashyraliyev
118
Lecture Notes - Numerical Methods M.Ashyraliyev
Finally, from given boundary condition S+0 (1) = S−0 (3) we have
1
3 + 4(1 − 1) − 3(1 − 1)2 = b + 2c(3 − 2) + 3d(3 − 2)2 =⇒ d= .
3
So,
119
Lecture Notes - Numerical Methods M.Ashyraliyev
Problem 8.2. Determine all unknown coefficients for which the fol-
lowing function
(
a + bx + 2x2 − 2x3 , x ∈ [0, 1)
S(x) =
1 + c(x − 1) + d(x − 1)2 + e(x − 1)3 , x ∈ [1, 2]
is the clamped cubic spline on interval [0, 2] with the derivative bound-
ary conditions S 0 (0) = 0 and S 0 (2) = 11.
121
Lecture Notes - Numerical Methods M.Ashyraliyev
Problem 8.3. Find the natural cubic spline S(x) that passes through
data points given in the table:
xk 1 2 3
yk 2 3 5
Problem 8.4. Find the clamped cubic spline S(x) that passes through
data points given in the table:
xk −1 0 1
yk 1 2 −1
Problem 8.5. Determine all unknown coefficients for which the fol-
lowing function
2 3
a + bx − 2x + x ,
x ∈ [0, 1)
S(x) = c + (x − 1)2 + d(x − 1)3 , x ∈ [1, 2)
t − (x − 2) − 2(x − 2)2 + r(x − 2)3 , x ∈ [2, 3]
is the clamped cubic spline that passes through data points given in
the table:
xk 0 1 2 3
yk 1 1 1 0
122
9 Curve Fitting
Assume that we have the set of paired observations
(x1 , y1 ), (x2 , y2 ), . . . , (xn , yn ) (9.1)
We have already seen the interpolation methods when the approximat-
ing function is constructed such that its graph passes though all data
points. Interpolation assumes that there is some function f (x) such
that yk = f (xk ) for all values of k. However, in practice it is unrea-
sonable to require that the approximating function agree exactly with
the given data due to the presence of errors in the data. For instance,
in the left plot of Figure 5 points represent the data values and it ap-
pears that y depends linearly on x. In this case, data can represented
by ”best” (in some sense) approximating line (or some other curve for
the data in the right plot of Figure 5). The problem of finding that
”best” approximating curve to represent the data is called the curve
fitting problem.
123
Lecture Notes - Numerical Methods M.Ashyraliyev
Definition 9.2. To measure the quality of the fit, we define the quan-
tity called Root Mean Square (RMS) defined as following
v
u n
u1 X 2
RM S = t f (xk ) − yk . (9.3)
n
k=1
Theorem 9.1. The coefficients of least squares line are the solutions
of so-called normal equations:
Xn Xn X n
2
A xk + B xk = xk yk
k=1 k=1 k=1 (9.5)
Pn Pn
x +B·n=
A
k y k
k=1 k=1
Proof. The values of parameters A and B in least squares line minimize
the sum (9.4). For a minimum to occur, we need
n
∂S X
= 2 Axk + B − yk xk = 0,
∂A
k=1
n
∂S X
= 2 Axk + B − yk = 0.
∂B
k=1
124
Lecture Notes - Numerical Methods M.Ashyraliyev
Example 9.1. Find the least squares line for the data given in the
following table
xk −1 0 1 2 3 4 5 6
yk 10 9 7 5 4 3 0 −1
xk yk x2k xk yk
−1 10 1 −10
0 9 0 0
1 7 1 7
2 5 4 10
3 4 9 12
4 3 16 12
5 0 25 0
6 −1 36 −6
8 8 8 8
x2k = 92
P P P P
xk = 20 yk = 37 xk yk = 25
k=1 k=1 k=1 k=1
45 121
Solving this system, we obtain A = − and B = . So, the least
28 14
squares line for the given data has the form:
45 121
y=− x+ .
28 14
125
Lecture Notes - Numerical Methods M.Ashyraliyev
Example 9.2. Find the least squares line for the data given in the
following table
xk −2 −1 0 1 2
yk 1 2 3 3 4
and calculate the RMS.
Solution: We first construct the table to calculate all necessary sums
which appear in the normal equations (9.5)
xk yk x2k x k yk
−2 1 4 −2
−1 2 1 −2
0 3 0 0
1 3 1 3
2 4 4 8
5 5 5 5
x2k
P P P P
xk = 0 yk = 13 = 10 x k yk = 7
k=1 k=1 k=1 k=1
So, the least squares power curve for the given data has the form:
y = f (x) = 1.686581163 · x2
5.1 · (2.0)3 + 7.5 · (2.3)3 + 10.6 · (2.6)3 + 14.4 · (2.9)3 + 19.0 · (3.2)3
B= =
(2.0)6 + (2.3)6 + (2.6)6 + (2.9)6 + (3.2)6
1292.1517
= ≈ 0.59015381571791
2189.51681
So, the least squares power curve for the given data has the form:
y = g(x) = 0.59015381571791 · x3
Since RM Sg < RM Sf , the curve y = g(x) gives a better fit than the
curve y = f (x).
128
Lecture Notes - Numerical Methods M.Ashyraliyev
Theorem 9.3. The coefficients of least squares parabola are the solu-
tions of corresponding normal equations:
n n n n
X X X X
4 3 2
yk x2k
A xk + B xk + C xk =
k=1 k=1 k=1 k=1
n n n n
3 2 (9.9)
P P P P
A x k + B x k + C x k = yk xk
k=1 k=1 k=1 k=1
n n n
x2k + B
P P P
A xk + C · n = yk
k=1 k=1 k=1
Example 9.4. Find the least squares parabola for the data given in
the following table
xk −3 0 2 4
yk 3 1 1 3
129
Lecture Notes - Numerical Methods M.Ashyraliyev
130
Lecture Notes - Numerical Methods M.Ashyraliyev
131
Lecture Notes - Numerical Methods M.Ashyraliyev
A 1
y= +B x̃ = y = Ax̃ + B
x x
1 1
y= ỹ = ỹ = Ax + B
Ax + B y
1 1
y= ỹ = √ ỹ = Ax + B
(Ax + B)2 y
y = CxA ỹ = ln y, x̃ = ln x, B = ln C ỹ = Ax̃ + B
y
Ax
y = Cxe ỹ = ln , B = ln C ỹ = Ax + B
x
D 1 D
y= x̃ = xy, A = − , B = y = Ax̃ + B
x+C C C
132
Lecture Notes - Numerical Methods M.Ashyraliyev
Find the least squares parabola y = Ax2 + Bx + C for given data and
calculate RMS.
133
Lecture Notes - Numerical Methods M.Ashyraliyev
134
10 Eigenvalues, Scaled Power Method, Sin-
gular Value Decomposition
10.1 Eigenvalues and Eigenvectors of a Matrix
Definition 10.1. Number λ is called an eigenvalue of the square
matrix A if
Av = λv (10.1)
for some nonzero vector v. Vector v in this case is called an eigen-
vector of matrix A associated with eigenvalue λ.
To find the eigenvalues and eigenvectors of the square matrix A of
size n × n, we first rewrite equation (10.1) in the form
(A − λIn )v = 0, (10.2)
where In is an identity matrix. Given λ, (10.2) is a system of n homo-
geneous linear equations. By a standard theorem of linear algebra, it
has a nonzero solution v if and only if the determinant of its coefficient
matrix vanishes; that is, if and only if
a11 − λ a12 ... a1n
a21 a22 − λ . . . a2n
|A − λIn | = = 0. (10.3)
... ... ... ...
an1 an2 . . . ann − λ
135
Lecture Notes - Numerical Methods M.Ashyraliyev
Example 10.1.
Find
eigenvalues and corresponding eigenvectors of
1 3
matrix A = .
4 5
Solution: The characteristic equation of given matrix is
1−λ 3
|A − λI2 | = = (1 − λ)(5 − λ) − 12 = λ2 − 6λ − 7 = 0,
4 5−λ
Since the two scalar equations in this system are equivalent, it has
infinitely many nonzero solutions. We can choose a arbitrarily (but
nonzero) and then solve
" #for b. For instance, the choice a = 1 yields
1
b = 2, and thus v1 = is an eigenvector associated with eigenvalue
2
λ1 = 7. " #
c
Let v2 = be an eigenvector associated with eigenvalue λ2 = −1.
d
Substitution of λ2 and v2 in (10.2) yields the system
" #" # " # (
2 3 c 0 2c + 3d = 0,
= =⇒
4 6 d 0 4c + 6d = 0.
" #
−3
The choice c = −3 yields d = 2, and thus v2 = is an eigenvector
2
associated with eigenvalue λ2 = −1.
136
Lecture Notes - Numerical Methods M.Ashyraliyev
Ak = VDk V−1 ,
where
λk1 0 . . . 0
k
0 λk2 . . . 0
D =
... ... ..
.
0 0 . . . λkn
Additionally, it allows to find the inverse of A,
where
1
λ10 ... 0
0 1 ... 0
D−1 = .. λ..2
. . .
.
.
0 0 . . . λ1n
137
Lecture Notes - Numerical Methods M.Ashyraliyev
Avk
vk+1 = for k = 0, 1, 2, . . . (10.5)
||Avk ||∞
Then the approximations for the dominant eigenvalue λ1 are defined
as following
(Avk+1 )T vk+1
αk+1 = T v
for k = 0, 1, 2, . . . (10.6)
vk+1 k+1
2 step: We have
Av1 1
v2 = = 12 ,
||Av1 ||∞ 13
139
Lecture Notes - Numerical Methods M.Ashyraliyev
63
" #
3 2 1 13 63
Av2 = 12 = =⇒ ||Av2 ||∞ = .
2 3 13
62 13
13
So
63 62
1
13 13 12 744 63
(Av2 )T v2 + 169
13 1563 13
α2 = = = 144 = = 4.99361 . . .
v2T v2
12
1 1 + 169 313
1 13 12
13
Since
|α2 − α1 |
≈ 0.03 < 0.05,
|α2 |
we can stop the iterations. α2 ≈ 4.99361 gives an approximation
to the dominant eigenvalue of given matrix within relative pre-
cision 0.05. Note that the exact value of dominant eigenvalue is
λ1 = 5.
A = VDVT ,
140
Lecture Notes - Numerical Methods M.Ashyraliyev
141
Lecture Notes - Numerical Methods M.Ashyraliyev
142
Lecture Notes - Numerical Methods M.Ashyraliyev
143
Lecture Notes - Numerical Methods M.Ashyraliyev
1 √1
results in p2 = q 2 = r2 = 3 and q = r = −p. The choice r = 3
yields
144
Lecture Notes - Numerical Methods M.Ashyraliyev
q= √1 and p = − √13 . So
3
√2 0 − √13
6
U=
√1 − √12 √1
6 3
√1 √1 √1
6 2 3
Finally, the SVD (10.7) for given matrix A takes the form
√
√2 0 − √1
6 3 3 0 " 1 #T
√ √1
2 2
A = UΣVT = √16 − √12 √1
0 1
3
√1 − √12
1 1 1 2
√
6
√
2
√
3
0 0
7 −2 0
Problem 10.2. Let A = −2 6 −2 . Use Scaled Power method
0 −2 5
1
with initial vector v0 = 0 to approximate the dominant eigenvalue
0
of matrix A within relative precision 10−2 . Compare your results to
the exact value of the dominant eigenvalue.
145
Lecture Notes - Numerical Methods M.Ashyraliyev
146
11 Numerical Differentiation, Numerical
Integration
11.1 Numerical Differentiation
Here we will learn the methods to approximate the first and the second
derivatives of function. These methods are often needed for approxi-
mating the solutions of differential equations. Approximation formulas
are based on the Taylor’s formula. Let us recall the Taylor’s theorem.
Theorem 11.1. (Taylor’s Theorem)
Suppose function f has continuous n + 1 derivatives on interval [a, b].
Then for any points x and x0 from [a, b], there exists a number ξ
between x and x0 such that
0 f 00 (x0 )
f (x) = f (x0 ) + f (x0 )(x − x0 ) + (x − x0 )2 +
2!
(11.1)
f (n) (x0 ) n f (n+1) (ξ)
+ ... + (x − x0 ) + (x − x0 )n+1 .
n! (n + 1)!
147
Lecture Notes - Numerical Methods M.Ashyraliyev
h2 00
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + f (ξ),
2!
which gives us immediately (11.3).
f (x0 ) − f (x0 − h)
f 0 (x0 ) ≈ , (11.5)
h
which is called the backward difference formula. The truncation
error in the approximation (11.5) is also O(h).
Theorem 11.3. If f 000 (x) is continuous on the interval [a, b], then for
any points x0 − h and x0 + h from [a, b] we have
h2 00 h3
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + f (x0 ) + f 000 (ξ2 ), (11.7)
2! 3!
148
Lecture Notes - Numerical Methods M.Ashyraliyev
0h2 00 h3 000
f (x0 − h) = f (x0 ) − hf (x0 ) + f (x0 ) − f (ξ1 ), (11.8)
2! 3!
where ξ1 is some point between x0 −h and x0 . Subtracting from equality
(11.7) the equality (11.8) side by side, we get
0 h3 000 000
f (x0 + h) − f (x0 − h) = 2hf (x0 ) + f (ξ1 ) + f (ξ2 ) ,
6
from which we obtain
149
Lecture Notes - Numerical Methods M.Ashyraliyev
f (2 + h) − f (2)
f 0 (2) ≈ .
h
f (2 + h) − f (2 − h)
f 0 (2) ≈ .
2h
150
Lecture Notes - Numerical Methods M.Ashyraliyev
0 h2 00 h3 000 h4 (4)
f (x0 +h) = f (x0 )+hf (x0 )+ f (x0 )+ f (x0 )+ f (ξ2 ), (11.12)
2! 3! 4!
151
Lecture Notes - Numerical Methods M.Ashyraliyev
0 h2 00 h3 000 h4 (4)
f (x0 −h) = f (x0 )−hf (x0 )+ f (x0 )− f (x0 )+ f (ξ1 ), (11.13)
2! 3! 4!
where ξ1 is some point between x0 − h and x0 . Adding the equalities
(11.12) and (11.13) side by side, we get
Example 11.2. Let f (x) = xex . Approximate f 00 (2) using the central
difference formula (11.15) with h = 0.1, h = 0.01 and h = 0.001. Find
the errors in obtained approximations.
152
Lecture Notes - Numerical Methods M.Ashyraliyev
f (2 − h) − 2f (2) + f (2 + h)
f 00 (2) ≈ .
h2
When h = 0.1, we have
f (1.9) − 2f (2) + f (2.1)
= 29.5931861 . . .
0.01
f (1.9) − 2f (2) + f (2.1)
with the error f 00 (2) − ≈ 0.037.
0.01
When h = 0.01, we have
f (1.99) − 2f (2) + f (2.01)
= 29.55659385 . . .
0.0001
f (1.99) − 2f (2) + f (2.01)
with the error f 00 (2) − ≈ 3.7 × 10−4 .
0.0001
When h = 0.001, we have
f (1.999) − 2f (2) + f (2.001)
= 29.55622809 . . .
0.000001
f (1.999) − 2f (2) + f (2.001)
with the error f 00 (2) − ≈ 3.7 × 10−6 .
0.000001
153
Lecture Notes - Numerical Methods M.Ashyraliyev
where h = x1 − x0 .
hh i h3
= f (x0 ) + f (x1 ] − f 00 (ξ).
2 12
154
Lecture Notes - Numerical Methods M.Ashyraliyev
Zb
b−a
Now, consider the integral f (x)dx. Let h = , where n is a
n
a
positive integer. We denote
x0 = a, x1 = a + h, x2 = a + 2h, . . . , xn = a + nh = b.
is called the Trapezoidal Sum for function f (x) over interval [a, b].
Theorem 11.6. If f 00 (x) is continuous on the interval [a, b], then there
exists a point ξ between a and b such that
Zb
h2
f (x)dx = Tn − (b − a)f 00 (ξ), (11.18)
12
a
hh i
= f (x0 ) + 2f (x1 ) + 2f (x2 ) + . . . + 2f (xn−1 ) + f (xn ) −
2
h3 00 00 00 00
− f (ξ1 ) + f (ξ2 ) + . . . + f (ξn−1 ) + f (ξn ) =
12
h3 00 h2
= Tn − nf (ξ) = Tn − (b − a)f 00 (ξ).
12 12
which is called the Trapezoidal Rule. Note that the truncation error
in the approximation (11.19) is O(h2 ).
Z1
Example 11.3. Approximate the integral x4 dx using the Trape-
0
zoidal sum with n = 10 and find the error in the obtained approxima-
tion.
1−0
Solution: We denote f (x) = x4 . Since h = = 0.1, we have
10
xk = hk = 0.1k for k = 0, 1, 2, . . . , 10. Then
9
hh X i
T10 = f (x0 ) + 2 f (xk ) + f (x10 ) =
2
k=1
0.1 4
h
4 4 4 4
4
i
= 0 + 2 0.1 + 0.2 + 0.3 + . . . + 0.9 + 1 =
2
h i
= 0.05 0 + 2 · 1.5333 + 1 = 0.20333.
156
Lecture Notes - Numerical Methods M.Ashyraliyev
Z1
1
Note that the exact value of given integral is x4 dx = = 0.2 and
5
0
therefore the error in the approximation of integral by T10 is
E = |T10 − 0.2| = |0.20333 − 0.2| = 0.00333.
where h = x1 − x0 = x2 − x1 .
Proof. The proof of (11.20) uses the second order Lagrange interpo-
lating polynomial and is similar to the proof of (11.16). So, we leave
it for the self-study.
Zb
Now, consider again the integral f (x)dx. Let n be even number.
a
b−a
We define h = and xk = a + kh for k = 0, 1, 2, . . . , n. Then the
sum n
hh i
Sn = f (x0 )+4f (x1 )+2f (x2 )+4f (x3 )+2f (x4 )+. . .+4f (xn−1 )+f (xn )
3
or
n/2 (n/2)−1
hh X X i
Sn = f (x0 ) + 4 f (x2k−1 ) + 2 f (x2k ) + f (xn ) (11.21)
3
k=1 k=1
is called the Simpson’s Sum for function f (x) over interval [a, b].
157
Lecture Notes - Numerical Methods M.Ashyraliyev
Theorem 11.8. If f (4) (x) is continuous on the interval [a, b], then
there exists a point ξ between a and b such that
Zb
h4
f (x)dx = Sn − (b − a)f (4) (ξ), (11.22)
180
a
Zb Zx2 Zx4 x
Zn−2 Zxn
f (x)dx = f (x)dx + f (x)dx + . . . + f (x)dx + f (x)dx =
a x0 x2 xn−4 xn−2
h h5
= f (x0 ) + 4f (x1 ) + f (x2 ) − f (4) (ξ1 )+
3 90
h h5
+ f (x2 ) + 4f (x3 ) + f (x4 ) − f (4) (ξ2 ) + . . . +
3 90
h h5
+ f (xn−4 ) + 4f (xn−3 ) + f (xn−2 ) − f (4) (ξ n2 −1 )+
3 90
h h5
+ f (xn−2 ) + 4f (xn−1 ) + f (xn ) − f (4) (ξ n2 ) =
3 90
hh i
= f (x0 ) + 4f (x1 ) + 2f (x2 ) + 4f (x3 ) + 2f (x4 ) + . . . + 4f (xn−1 ) + f (xn ) −
3
h5 (4) (4) (4) n (4) n
− f (ξ1 ) + f (ξ2 ) + . . . + f (ξ 2 −1 ) + f (ξ 2 ) =
90
h5 n (4) h4
= Sn − f (ξ) = Sn − (b − a)f (4) (ξ).
90 2 180
158
Lecture Notes - Numerical Methods M.Ashyraliyev
an approximation formula
Zb n/2 (n/2)−1
hh X X i
f (x)dx ≈ f (x0 ) + 4 f (x2k−1 ) + 2 f (x2k ) + f (xn ) ,
3
a k=1 k=1
(11.23)
which is called the Simpson’s Rule. Note that the truncation error
in the approximation (11.23) is O(h4 ).
Z1
Example 11.4. Approximate the integral x4 dx using the Simpson’s
0
sum with n = 10 and find the error in the obtained approximation.
1−0
Solution: We denote f (x) = x4 . Since h = = 0.1, we have
10
xk = hk = 0.1k for k = 0, 1, 2, . . . , 10. Then
5 4
hh X X i
S10 = f (x0 ) + 4 f (x2k−1 ) + 2 f (x2k ) + f (x10 ) =
3
k=1 k=1
0.1 h 4
0 + 4 0.14 + 0.34 + 0.54 + 0.74 + 0.94 +
=
3
i
4 4 4 4 4
+ 2 0.2 + 0.4 + 0.6 + 0.8 + 1 =
0.1 h i 0.1
= 0 + 4 · 0.9669 + 2 · 0.5664 + 1 = · 6.0004 = 0.2000133 . . .
3 3
The error in the approximation of given integral by S10 is
159
Lecture Notes - Numerical Methods M.Ashyraliyev
160
Lecture Notes - Numerical Methods M.Ashyraliyev
Z2
Problem 11.6. Approximate the integral x ln xdx using
1
(a) Trapezoidal sum with n = 4 and find the error in the obtained
approximation.
(b) Simpson’s sum with n = 4 and find the error in the obtained
approximation.
Zπ
Problem 11.7. Approximate the integral x2 cos xdx using
0
(a) Trapezoidal sum with n = 6 and find the error in the obtained
approximation.
(b) Simpson’s sum with n = 6 and find the error in the obtained
approximation.
Z2
2
Problem 11.8. Approximate the integral ex dx using
0
161