Introduction To Numerical Analysis: Arithmetic Operations
Introduction To Numerical Analysis: Arithmetic Operations
References :
1. Phạm Kỳ Anh, Giải tích số, Nhà xuất bản Đại học Quốc gia Hà Nội, 2008
2. J. Stoer and R. Bulirsch, Introduction to Numerical Analysis, Third
Edition, Springer 2002.
3. Endre Suli and David F. Mayers, An Introduction To Numerical Analysis,
Cambridge University Press, 2003
5/19/22 1
Introduction to Numerical Analysis
5/19/22 2
Numerical Analysis: Chapter 1
Interpolation
x
x0 x1 x2 x* x3 x4 x5 x6
5/19/22 4
Polynomial Interpolation
Objective : We will find a general polynomial P of degree m
Pm(x) = a0 + a1x + . . . + am-1xm-1 + amxm
that interpolates the given data: P(xi) = yi, for i = 0,1,...,n.
y
P
x
x0 x1 x2 x* x3 x4 x5 x6
(i) It can be shown that for the matrix X in the above system
det( X ) = Õ
0£ j <i £ n
( xi - x j )
5/19/22 7
Polynomial Interpolation
(ii) By a standard theorem of linear algebra, the system Xa = y has
a unique solution if and only if the homogeneous system Xb =
0 has only the trivial solution b = 0. Therefore, assume Xb = 0
for some b. Using b, define
P(x) = b0 + b1x + . . . + bn-1xn-1 + bnxn
5/19/22 8
Solving system of linear equations for the
interpolating polynomial
Example 1: Find the interpolating polynomial of the function y = 3x
on [-1, 1] with three points x0 = -1, x1 = 0, x2 = 1. Use this interpolating
polynomial to compute the value of this function at x = 1/2.
We have y0 = 1/3, y1 = 1, y2 = 3. We construct the system of linear
euqations with variables 𝑎! , 𝑎" , 𝑎# :
𝑎! + 𝑎" . −1 + 𝑎# −1 # = 1/3 1 −1 1 𝑎! 1/3
𝑎! + 𝑎" . 0 + 𝑎# . (0)# = 1 ⟺ 1 0 0 𝑎" = 1
𝑎! + 𝑎" . 1 + 𝑎# . (1)# = 3 1 1 1 𝑎# 3
Solve this system, we obtain: 𝑎! = 1, 𝑎" = 4/3, 𝑎# = 2/3.
Thus, we get the interpolating polynomial :
4 2
P x = 1 + x + x#.
3 3
With x = 1/2, we have the following approximation:
2 1
31/2
= 3 » 1 + + = 1,8333
3 6
(The value 31/2 = 1,7320508…, the error is about 0,1)
19/05/2022 9
Lagrange's formula
Suppose that xi, i = 0,1,...,n are n+1 support points in [a, b], and yi =
f(xi) is the value of function f. Then the interpolating polynomial can
be written in the following form (called Lagrange's formula for the
interpolating polynomial)
n
P(x) = å y P (x),
i=0
i i
where
(x - x 0 )...(x - x i-1 )(x - x i+1 )...(x - x n ) Õ (x - x k )
Pi (x) = = k ¹i
(x i - x 0 )...(x i - x i-1 )(x i - x i+1 )...(x i - x n )
Õ (x - x
k ¹i
i k )
It is easy to see that:
• It is a polynomial degree at most n
• and it satisfy the condition
Pi (x j ) = 0, "j ¹ i, Pi (x i ) = 1.
5/19/22 10
Lagrange's formula
Example 1: Find the Lagrange's formula for interpolating polynomial
of the function y = 3x on [-1, 1] with three points x0 = -1, x1 = 0, x2 =
1. Use this polynomial interpolation to compute the value of this
function at x = 1/2.
We have :y0 = 1/3, y1 = 1, y2 = 3. The Lagrange's formula is:
5/19/22 12
Newton's interpolation formula : Finite difference
Finite difference:
Definition: Given a function f(x) with variable x and h = Δx = constant >0 which
represents the variation on x. Then:
Δf(x) = f(x+Δx) - f(x)
is called forward difference degree 1 at x of the function f(x) corresponding to h.
We have:
The finite difference degree 1:
Δf(x) = f(x+h) - f(x) = (x+h)3 – x3 = 3x2h + 3xh2 + h3.
The finite difference degree 2:
Δ2f(x) = Δf(x+h) - Δf(x)
= (3(x+h)2h + 3(x+h)h2 + h3) – (3x2h + 3xh2 + h3)
= 6xh2 + 6h3.
The finite difference degree 3:
Δ3f(x) = Δ2f(x+h) - Δ2f(x) = (6(x+h)h2 + 6h3) – (6xh2 + 6h3)
= 6h3.
Thus
Δkf(x) = 0, for all k ≥ 4 and for all x ∈ R.
14
Newton's interpolation formula : Finite difference
Constructing forward differences
Suppose that xi+1 – xi = h = const, for all i = 0,1,.., n - 1. Then the
sequence of forward differences of this function can be determined as
follows:
Δyi = yi+1 - yi
Δ 2 yi = Δ(Δyi ) = Δyi+1 - Δyi
Δ n yi = Δ(Δ n-1yi ) = Δ n-1yi+1 - Δ n-1yi
x y Δy Δ2y Δ3y Δ4y
… … … … … … …
xi-2 yi-2
Δyi-2
xi-1 yi-1 Δ2yi-2
Δyi-1 Δ3yi-2
xi yi Δ2yi-1 Δ4yi-2
Δyi Δ3yi-1
xi+1 yi+1 Δ2yi
Δyi+1
xi+2 yi+2
5/19/22 15
… … … … … … …
Newton's interpolation formula : Finite difference
Newton's forward formula:
Suppose that xi+1 – xi = h = const > 0 for all i = 0,1,..,n – 1 and this
points is ordered as follows
x0<x1 <….<xn-1 <xn
The Newton forward difference form of the interpolating polynomial is:
Δy0 Δ 2 y0 Δ n y0
Pfw (x) = y0 + (x-x 0 ) + 2
(x - x 0 )(x - x1 ) + ... + n
(x-x 0 )(x-x1 )...(x-x n-1 ).
1!h 2!h n!h
Δy0 Δ 2 y0 Δ n y0
Pfw (x 0 +th) = y0 + t+ t(t - 1) + ... + t(t - 1)...(t - (n - 1)).
1! 2! n!
5/19/22 16
Newton's interpolation formula : Finite difference
Newton's backward formula:
Suppose that xi+1 – xi = h = const > 0 for all i = 0,1,..,n – 1 and this
points is ordered as follows
x0<x1 <….<xn-1 <xn
The Newton backward difference form of the interpolating polynomial is:
Δyn-1 Δ2 yn-2 Δ n y0
Pbw (x) = yn + (x-x n ) + 2
(x-x n )(x-x n-1 ) + ... + n
(x-x n )(x-x n-1 )...(x-x1 ).
1!h 2!h n!h
Δyn-1 Δ 2 yn-2 Δ n y0
Pbw (x n +th) = yn + t+ t(t + 1) + ... + t(t + 1)...(t + (n - 1)).
1! 2! n!
5/19/22 17
Newton's interpolation formula : Finite difference
Example: Find the polynomial interpolation using Newton’s formula
for the function y = 3x on [-1, 1] with points x0 = -1, x1 = 0, x2 = 1.
The table of the forward differences of the function is:
x y Δy Δ2y
-1 1/3
2/3
0 1 4/3
2
1 3
5/19/22 19
Newton's interpolation formula : Finite difference
Example : Given the data of the function y = sin x as follows
xi 0,1 0,2 0,3 0,4
yi 0,09983 0,19867 0,29552 0,38942
5/19/22 22
Interpolation Error
Theorem : If P(x) is Lagrange’s formula for interpolation polynomial
of f(x) with support points xi, for i = 0,1,...,n in [a, b]. Then the error
obtained when using P(x) to compute f(x) for an arbitrary point x in
[a, b] can be estimated by the following formula:
M
|f(x) - P(x)| £ |ω(x)|, "x Î [ a, b] ,
(n+1)!
y P
where
M = sup f (n+1) (x) f
a £ x £b
5/19/22 26
Runge's phenomenon
Runge's phenomenon
5/19/22 27
Runge's phenomenon
Runge's phenomenon
5/19/22 28
Runge's phenomenon
This shows that high-degree polynomial interpolation at equidistant
points can be troublesome.
Why?
Runge's phenomenon is the consequence of two properties of this
problem.
- The magnitude of the derivatives of this particular function grows
quickly when n increases.
- The equidistance between points leads to a Lebesgue constant
that increases quickly when n increases.
5/19/22 30
Newton’s Interpolation Formula: Divided Differences
Divided Differences:
Definition: Let f(x) be a function of x and the support points are ordered
as x0<x1 <….<xn-1 <xn
We call :
f(x i+1 ) - f(x i ) divided difference order 1 of the
f(x i , x i+1 ) =
x i+1 - x i function f at x i , x i+1
5/19/22 31
Newton’s Interpolation Formula: Divided Differences
Properties of Divided Differences: :
§ Property 1 k
f(x i )
f(x 0 , x1 , ..., x k ) = å ,
i=0 ω¢(x i )
where k
ω(x) = (x - x 0 )(x - x1 )...(x - x k ) = Õ (x - xi )
i=0
§ Property 2 : Divided difference is a linear operator
5/19/22 32
Newton’s Interpolation Formula: Divided Differences
5/19/22 33
Newton’s Interpolation Formula: Divided Differences
Based on this table, we can construct Newton's divided difference
formula for the interpolation polynomial as follows
Pbw (x) = y n + f(x n-1 ,x n )(x - x n ) + f(x n-2 ,x n-1 ,x n )(x - x n )(x - x n-1 ) + ...+
+ f(x 0 ,x1 ,...,x n )(x - x n )(x - x n-1 )...(x - x1 ).
5/19/22 34
Newton’s Interpolation Formula: Divided Differences
Example : Given the data of (xi ,yi) for a function as follows
xi -4 -1 0 2 5
yi 1245 33 5 9 1335
5/19/22 36
Newton’s Interpolation Formula: Divided Differences
Algorithm 1: Compute value of interpolating polynomial at an arbitrary point x
After the inner loop has terminated, t[j] = Ti,i-j, 0 ≤ j ≤ i. The desired value Tnn =
P(x) of the interpolating polynomial can be found in t[0].
5/19/22 37
Newton’s Interpolation Formula: Divided Differences
Algorithm 2: Compute divided differences & Evaluate value of interpolation
polynomial at a point x.
p := a[n];
for i:= n -1 step -1 until 0 do
p := p*(x – x[i]) + a[i];
The output p is the value of interpolation
polynomial at x.
5/19/22 38
Determining Interpolating Cubic Spline Functions
Spline functions yield smooth interpolating curves which are less likely to exhibit
the large oscillations characteristic of high-degree polynomials. They are finding
applications in graphics and, increasingly, in numerical methods. For instance,
spline functions may be used as trial functions in connection with the Rayleigh-
Ritz-Galerkin method for solving boundary value problems of ordinary and partial
differential equations. More recently, they are also used in signal processing.
5/19/22 39
Determining Interpolating Cubic Spline Functions
Consider a finite sequence Y := (y0, y1, . . . , yn) of n + 1 real numbers.
We denote by
SΔ(Y; .)
5/19/22 40
Determining Interpolating Cubic Spline Functions
In what follows D = { xi , i = 0,1,..., n} will be a fixed partition of the interval
[a, b] by support points a = x0 < x1 < · · · < xn = b and Y = (yi), i=0,1,...,n
will be a sequence of n+1 prescribed real numbers. In addition let Ij be
the subinterval Ij := [xj-1 , xj], j = 0,1,…, n−1, and hj+1 := xj+1 − xj its length.
5/19/22 41
Determining Interpolating Cubic Spline Functions
By integration
( x j +1 - x ) (x - xj )
2 2
S D' (Y ; x) = - M j + M j +1 + Aj
2h j +1 2h j +1 (2)
(x - x) (x - x )
3 3
+ Aj ( x - x j ) + B j
j +1 j
S D (Y ; x) = M j + M j +1
6h j +1 6h j +1
where
Mj
a j := y j , g j := ,
2
M j h j +1
b j := S (Y; x j ) = -
'
D + Aj
2
y j +1 - y j 2M j + M j +1
= - h j +1 ,
h j +1 2
S D''' (Y; x +j ) M j +1 - M j
d j := = .
6 6h j +1
Thus S∆(Y; ·) has been characterized by its moments Mj. The task of
calculating these moments will now be addressed.
5/19/22 43
Determining Interpolating Cubic Spline Functions
The continuity of S’∆ (Y; ·) at the interior points x = xj, j = 1, 2, . . . , n − 1
yields n − 1 equations for the moments Mj.
(x - x) (x - x )
2 2
j +1 j
S (Y ; x) = - M j
'
D + M j +1
2h j +1 2h j +1
y j +1 - y j h j +1
+ - ( M j +1 - M j ).
h j +1 6
For j = 1, 2, . . . , n − 1, we have therefore
-
y j - y j -1 h j hj
SD (Y ; x j ) =
'
+ M j + M j -1 ,
hj 3 6
+
y j +1 - y j h j +1 h j +1
S (Y ; x ) =
'
D j - Mj - M j +1 ,
h j +1 3 6
and since SD' (Y ; x +j ) = SD' (Y ; x -j ),
hj h j + h j +1 h j +1 y j +1 - y j y j - y j -1
M j -1 + Mj + M j +1 = - (5)
6 3 6 h j +1 hj
for j = 1, 2, . . . , n − 1.
5/19/22 44
Determining Interpolating Cubic Spline Functions
These are n − 1 equations for the n + 1 unknown moments. Two further
equations can be gained separately from each of the side conditions (a),
(b) and (c) listed in the condition (*).
Case (a) : SD'' (Y ; a ) = M 0 = 0 = M n = S D'' (Y ; b),
Case (b) : S D'' (Y ; a ) = S D'' (Y ; b) Þ M 0 = M n ,
hn h +h h
S D' (Y ; a ) = S D' (Y ; b) Þ
M n -1 + n 1 M n + 1 M1j +1
6 3 6
y -y y - yn -1
= 1 n- n .
h1 hn
The latter condition is identical with (5) for j = n if we put
hn+1 = h1 , M n+1 = M1 , yn+1 = y1.
Recall that (b) in the condition (*) requires yn = y0.
h h y -y
Case (c) : S D' (Y ; a) = y0' Þ 1 M 0 + 1 M 1 = 1 0 - y0' ,
3 6 h1
hn hn yn - yn -1
S (Y ; b) = y Þ M n -1 + M n = yn -
'
D
'
n
'
.
5/19/22
6 3 hn 45
Determining Interpolating Cubic Spline Functions
The last two equations, as well as those in (5), can be written in a
common format:
µ j M j -1 + 2M j + l j M j +1 = d j , j = 1, 2, . . . , n - 1,
upon introducing the abbreviations (j = 1, 2, . . . , n − 1)
h j +1 hj
l j := , µ j := 1 - l j = ,
h j + h j +1 h j + h j +1
(6)
6 æ y j +1 - y j y j - y j -1 ö
dj = çç - ÷÷ .
h j + h j +1 è h j +1 hj ø
In case (a), we define in addition
l0 := 0, d0 := 0, µn := 0, dn := 0, (7)
and in case (c)
6 ⎛ y1 − y0 ⎞
λ0 := 1, d0 := ⎜ − y0 ⎟ ,
'
h1 ⎝ h1 ⎠
(8)
6 ⎛ ' yn − yn−1 ⎞
µ n := 1, d n := ⎜ yn − ⎟ .
5/19/22 hn ⎝ hn ⎠ 46
Determining Interpolating Cubic Spline Functions
This leads in cases (a) and (c) to a system of linear equations for the
moments Mi that reads in matrix notation:
⎛ 2 λ0 ... 0 ⎞ ⎛ M 0 ⎞ ⎛ d0 ⎞
⎜ ⎟⎜ ⎟ ⎜ ⎟
⎜ µ1 2 λ1 . . . 0 ⎟ ⎜ M1 ⎟ ⎜ d1 ⎟
⎜ ... ⎟⎜ ! ⎟ =⎜ ! ⎟ (9)
⎜ ⎟⎜ ⎟ ⎜ ⎟
⎜0 . . . 2 λ n−1 ⎟ ⎜ ⎟ ⎜ ⎟
⎜0 ⎟ ⎜ ⎟ ⎜ ⎟
⎝ . . . µ n 2 ⎠ ⎜⎝ M n ⎟⎠ ⎜⎝ d n ⎟⎠
The coefficients λi, µi, di in (9) and (11) are well defined by (6) and the
additional definitions (7), (8), and (10), respectively. The periodic case (b)
also requires further definitions,
h1 hn
ln := , µn := 1 - ln = ,
hn + h1 hn + h1
(10)
6 æ y1 - yn yn - yn -1 ö
d n := ç - ÷,
hn + h1 è h1 hn ø
5/19/22 47
Determining Interpolating Cubic Spline Functions
which then lead to the following linear system of equations for the
moments M1, M2, . . . , Mn (= M0):
⎛ 2 λ1 . . . µ1 ⎞ ⎛ M1 ⎞ ⎛ d1 ⎞
⎜ ⎟⎜ ⎟ ⎜ ⎟
⎜ µ2 2 λ2 . . . 0 ⎟ ⎜ M 2 ⎟ ⎜ d2 ⎟
⎜0 µ . . . 0 ⎟⎜ ! ⎟ =⎜ ! ⎟
⎟ (11)
⎜ 3
⎟⎜ ⎟ ⎜
⎜0 . . . 2 λ n−1 ⎟ ⎜ ⎟ ⎜ ⎟
⎜ ⎟ ⎜⎜ ⎟ ⎜ ⎟
⎝ λn . . . µ n 2 ⎠ ⎝ M n ⎟⎠ ⎜⎝ d n ⎟⎠
Note in particular that in (9) and (11)
li ³ 0, µi ³ 0, li + µi = 1, (12)
for all coefficients λi, µi, and that these coefficients depend only on the
location of the knots xj ∈ ∆ and not on the prescribed values yi ∈ Y or on
y’0 , y’n in case (c). We will use this observation when proving the following:
Theorem. The systems (9) and (11) of linear equations are nonsingular for
any partition ∆ of a, b.
5/19/22 48
Convergence Properties of Cubic Spline Functions
Interpolating polynomials may not converge to a function f whose values
they interpolate, even if the partitions ∆ are chosen arbitrarily fine. In
contrast, we will show in this section that, under mild conditions on the
function f and the partitions ∆, the interpolating spline functions do
converge towards f as the fineness of the underlying partitions
approaches zero.
5/19/22 49