Professional Documents
Culture Documents
Lecture Notes On Numerical Analysis
Lecture Notes On Numerical Analysis
Numerical Analysis
MATH 435
E−mail: dattab@math.niu.edu
URL: www.math.niu.edu/~dattab
PART I.
Numerical Methods for Root Finding Problem
1 PART I: Numerical Methods for the Root-Finding Problem
1.1 Introduction
In this lecture, we will discuss numerical methods for the Root-Finding Problem. As the title suggests,
the Root-Finding Problem is the problem of finding a root of the equation f (x) = 0, where f (x) is a function
of a single variable x. Specifically, the problem is stated as follows:
The number ξ is called a root of f (x) = 0 or a zero of the function f (x). The function of f (x) may be alge-
braic or trigonometric functions. The well-known examples of algebraic functions are polynomials.
A polynomial of degree n is written as Pn (x) = a0 + a1 x + a2 x2 + ... + anxn . The numbers ai , i = 0, · · · , n are
called the coefficients of the polynomial. If a0 = 1, the polynomial Pn (x) is called the monic polynomial.
(INCOMPLETE)
1.2 Bisection-Method
As the title suggests, the method is based on repeated bisections of an interval containing the root. The
basic idea is very simple.
Basic-Idea:
Suppose f (x) = 0 is known to have a real root x = ξ in an interval [a, b].
a+b
• Then bisect the interval [a, b], and let c = be the middle point of [a, b]. If c is the root, then we
2
are done. Otherwise, one of the intervals [a, c] or [c, b] will contain the root.
• Find the one that contains the root and bisect that interval again.
• Continue the process of bisections until the root is trapped in an interval as small warranted by the
desired accuracy.
To implement the idea, we need to know which of the two intervals in each iteration contains the root of
f (x) = 0. The Intermediate Mean-Value Theorem of calculus can help us identify the interval in each
iteration. For a proof of this theorem, see any calculus book (e.g., ).
f(a) and f (b) are of opposite signs (i.e., f (a)f (b) < 0).
1
Algorithm 1.1 The Bisection Method for Rooting-Finding
End.
Iteration 1. k = 0 :
a0 + b 0 4+2·5 6·5
c0 = = = = 3 · 25.
2 2 2
Since f (c0 )f (a0 ) = f (3 · 25)f (2 · 5) < 0, set b1 = c0 , a1 = a0 .
Iteration 2. k = 1 :
3 · 25 + 2 · 5
c1 = = 2 · 8750.
2
Since f (c1 )f (a1 ) > 0, set a2 = 2 · 875, b2 = b1
Iteration 3. k = 2 :
a2 + b 2 2 · 875 + 3 · 250
c2 = = = 3 · 0625
2 2
Since f (c2 )f (a2 ) = f (3 · 0625)f (2 · 875) < 0, set b3 = c2 , a3 = a2 .
Iteration 4. k = 3
a3 + b 3 2 · 875 + 3 · 0625
c3 = = = 2.9688.
2 2
It is clear that the iterations are converging towards the root x = 3.
Notes:
1. From the statement of the Bisection algorithm, it is clear that the algorithm always converges.
2. The example above shows that the convergence, however, can be very slow.
Stopping Criteria
Since this is an iterative method, we must determine some stopping criteria that will allow the iteration to
stop. Here are some commonly used stopping criteria.
2
Let be the tolerance; that is, we would like to obtain the root with an error of at
most of . Then
Accept x = ck as a root of f (x) = 0 if any of the following criteria is satisfied:
|ck−1 − ck |
2. ≤ (The relative change is less than or equal to the tolerance).
|ck |
(b − a)
3. ≤ (The length of the interval after k iterations is less than or equal to the tolerance).
2k
Comments:
1. The Criterion 1 can be misleading, since, it is possible to have |f (ck )| very small, even if ck is not close
to the root. (Do an example to convince yourself that it is true).
2. The
Criterion
3 is based on the fact that after k steps, the root will be computed with error at most
b 0 − a0
.
2k
or 2−N ≤
(b0 − a0 )
or −N log10 2 ≤ log10
b 0 − a0
or N log10 2 ≥ − log10 .
b 0 − a0
− log10 b0 −a
0
or N≥ .
log10 2
[log10 (b0 − a0 ) − log10 ()]
or N≥
log10 2
Theorem 1.1 The number of iterations N needed in the Bisection Method to obtain an accuracy of is
given by
3
Example 1.2 Suppose we would like to determine a priori the minimum number of iterations needed in the
Bisection Algorithm, given a0 = 2.5, b0 = 4, and = 10−3 . By Theorem 1.1, we have
log10 (1.5) − log10 (10−3 ) log10 (1.5) + 3
N≥ = = 10.5507.
log10 2 log10 (2)
Thus, a minimum of 11 iterations will be needed to obtain the desired accuracy using the Bisection Method.
Remarks: Since the number of iterations N needed to achieve a certain accuracy depends upon the initial
length of the interval containing the root, it is desirable to choose the initial interval [a0 , b0 ] as small as
possible.
Finding a root of f (x) = 0 by finding a fixed point of x = g(x) immediately suggests an iterative procedure
of the following type.
Start with an initial guess x0 of the root, and form a sequence {xk } defined by
xk+1 = g(xk ), k = 0, 1, 2, · · ·
so that starting with any x0 in [a, b], the sequence {xk } defined
The simplest way to write f (x) = 0 in the form x = g(x) is to add x on both sides, that is,
x = f (x) + x = g(x).
Define g(x) = x + f (x) = x3 − 6x2 + 12x − 6. We know that there is a root of f (x) in [2.5, 4]; namely x = 3.
Let’s start the iteration xk+1 = g(xk ) with x0 = 3.5,
4
The convergence and divergence of the fixed-point iteration are illustrated by the following graphs.
Fixed-Point
x
=
y
x2 x1 x0
Fixed-Point
x0 x1 x2
The following theorem gives a sufficient condition on g(x) which ensures the convergence of the sequence
{xk }.
Theorem 1.2 (Fixed-Point Iteration Theorem): Let f (x) = 0 be written in the form x = g(x).
Assume that g(x) has the following properties:
1. For all x in [a, b], g(x) ∈ [a, b]; that is g(x) takes every value between a and b.
2. g 0 (x) exists on (a, b) with the property that there exists a positive constant r < 1 such that
|g 0 (x)| ≤ r,
Then
5
(i) there is a unique fixed point x = ξ of g(x) in [a, b].
(ii) For any x0 in [a, b], the sequence {xk } defined by
xk+1 = g(xk ), k = 0, 1, · · ·
The proof of the Theorem requires the Mean Value Theorem of Calculus;
Let f (x) be a continuous function on [a, b], and be differentiable on (a, b).
f (b) − f (a)
Then there is a number c in (a, b) such that = f 0 (c).
b−a
Existence:
If a = g(a), then a is a fixed point. If b = g(b), then b is a fixed point. If not, because of the assumption
1, g(a) > a, and g(b) < b. Thus, f (a) = g(a) − a > 0, and f (b) = g(b) − b < 0. Also f (x) = g(x) − x is
continuous on [a, b].
Thus, by the Intermediate Mean Value Theorem, there is a root of f (x) in [a, b]. This proves the
existence.
Uniqueness:
To prove uniqueness, suppose ξ1 and ξ2 are for two fixed points in [a, b], and ξ1 6= ξ2 .
Then by the Mean Value Theorem, there is a number c in (a, b) such that
g(ξ1 ) − g(ξ2 )
= g 0 (c).
(ξ1 − ξ2 )
Since g(ξ1 ) = ξ1 , and g(ξ2 ) = ξ2 , we have
ξ1 − ξ2
= g 0 (c).
ξ1 − ξ2
That is, g 0 (c) = 1, which is a contradiction to our assumption 2. Thus, p can not be different from q.
Convergence:
Let ξ be the root of f (x) = 0. Then the absolute error at step k + 1 is given by ek+1 = |xk+1 − ξ|. To
prove that the sequence convergence, we need to show that limk→∞ ek+1=0 .
Now ek+1 = |xk+1 − ξ| = |g(xk ) − g(ξ)| (note that ξ = g(ξ)).
Thus by the Mean Value Theorem, we have ek+1 = |g 0 (c)| |xk − ξ| = |g 0 (c)|ek , where c is in (xk , ξ).
Since g 0 (c) ≤ r, we have ek+1 ≤ rek .
Similarly, we have ek ≤ rek−1 . Thus ek+1 ≤ r2 ek−1 .
6
Continuing in this way, we finally have ek+1 ≤ rk+1 e0 , where e0 is the initial error. (That is, e0 = |x0 − ξ|).
Since r < 1, we have rk+1 → 0 as k → ∞.
Thus,
lim ek+1 = lim |xk+1 − ξ|
k→∞ k→∞
≤ lim rk+1 e0
k→∞
= 0.
This proves that the sequence {xk } converges x = ξ. But x = ξ is the only fixed point of g(x).
In practice, it is not easy to verify Assumption 1. The following corollary of the fixed-point theorem is more
useful in practice; because, the conditions here are more easily verifiable. We leave the proof of the corollary
as an [Exercise].
Corollary 1.1 Let g(x) be continuously differentiable in some open interval containing the fixed point ξ,
and let |g 0 (ξ)| < 1, then there exists a number > 0 so that the iteration xk+1 = g(xk ) converges whenever
x0 is chosen in |x0 − ξ| ≤ .
Example 1.3 Let f (x) = x3 − 6x2 + 11x − 6 = 0. Choose a = 2.5, b = 4. Let’s write f (x) = 0 in the form
1
x = g(x) as follows: x = (−x3 + 6x2 + 6) = g(x).
11
Then
1
g 0 (x) = (−3x2 + 12x).
11
It is easy to verify graphically and analytically that |g 0 (x)| is less than 1 for all x is (2.5, 4), (note that
g 0 (4) = 0, and g 0 (2.5) = 1.0227).
So, by Corollary 1.1, the iteration xk+1 = g(xt ) should converge to the root x = 3 for any x0 ∈ [2.5, 4]. This
is verified as follows:
x0 = 3.5
x1 = g(x0 ) = 3.3295
x2 = g(x1 ) = 3.2368
x3 = g(x2 ) = 3.1772
x4 = g(xx ) = 3.1359
x5 = g(x4 ) = 3.1059
x6 = g(x5 ) = 3.0835
x7 = g(x6 ) = 3.0664
x8 = g(x7 ) = 3.0531
x9 = g(x8 ) = 3.0426
x10 = g(x9 ) = 3.0344
x11 = g(x10 ) = 3.0778
The sequence is clearly converging to the root x = 3. This can be justified from the above theorem.
π
Example 1.4 Find a root of f (x) = x − cos x = 0 in [0, ].
2
7
π
Let’s write x − cos x = 0 as x = cos x = g(x). Then |g 0 (x)| = | sin x| < 1 in (0, ). Thus, by Corollary 1.1
2
should converge. Indeed,
x0 =0
x1 = cos xo = 1
x2 = cos x1 = 0.54
x3 = cos x2 = 0.86
..
.
x17 = 0.73956
x18 = cos x17 = 0.73956
Choose
f (x)
g(x) = x − .
f 0 (x)
Since g 0 (x) is continuous, this means that there exists a small neighborhood around the root x = ξ such that
for all points x in that neighborhood, |g 0 (x)| < 1.
Thus if g(x) is chosen as above and the starting approximation x0 is chosen sufficiently close to the
root x = ξ, then the fixed-point iteration is guaranteed to converge, according to the corollary above.
This leads to the following well-known classical method, known as, the Newton-Raphson method.
(Remark: In many text books and literature, the Newton-Raphson Method is simply called the Newton
Method. But, the title “The Newton-Raphson Method” is justified. See an article by [ ] in SIAM Review
(1996)).
8
Algorithm 1.2 The Newton-Raphson Method
or k > N , Stop.
End
f (xk )
Definition 1.1 The iterations xk+1 = xk − are called Newton’s iterations.
f 0 (xk )
Remarks:
1. If none of the above criteria has been satisfied within a predetermined, say N iterations, then the
method has failed after the prescribed number of iterations. In that case, one could try the method
again with a different x0 .
2. A judicious choice of x0 can sometimes be obtained by drawing the graph of f (x), if possible. However,
there does not seem to exist a clear-cut guideline of how to choose a right starting point x0 that
guarantees the convergence of the Newton-Raphson Method to a desired root.
Some Familiar Computations Using the Newton-Raphson Method
√
1. Computing the Square Root of a Positive Number A: Compute A, where A > 0.
√ √
Computing A is equivalent to solving x2 − A = 0. The number A, thus, may be computed by
applying the Newton-Raphson Method to f (x) = x2 − A.
Since f 0 (x) = 2x, we have the following Newton iterations to generate {xk }:
9
√
Newton-Raphson Iterations for Computing A
x2k − A x2 + A
xk+1 = xk − = k
2xk 2xk
End
x20 + A (1.5)2 + 2
Iteration 1. x1 = = = 1.4167
2x0 3
x21 + A
Iteration 2. x2 = = 1.4142
2x1
x22 + A
Iteration 3. x3 = = 1.4142
2x2
xnk − A (n − 1)xnk + A
xk+1 = xk − = .
nxn−1
k nxn−1
k
10
1
The Newton-Raphson Iteration for Computing
A
xk+1 = xk (2 − Axk )
End
1
The problem is to find
3
1
f (x) = − 3.
x
Take x0 = 0.25
Then x1 = x0 (2 − Ax0 ) = 0.3125
x2 = x1 (2 − Ax1 ) = 0.3320
x3 = x2 (2 − A2 ) = 0.333
1
Note that 0.333 is the 4-digit approximation of (correct up to 4 decimal figures).
3
A Geometric Interpretation of the Newton-Raphson Method
• The first approximation x1 can be viewed as the x-intercept of the tangent line to the graph of f (x)
at (x0 , f (x0 )).
• The second approximation x2 is the x-intercept of the tangent line to the graph of f (x) at (x1 , f (x1 )).
And so on.
11
1 ))
(x
,f
1
(x
x0
x2 x1
))
f (x 0
,
(x 0
f (xk )
xk+1 = xk −
f 0 (xk )
f (xk )(xk − xk−1 )
≈ xk −
f (xk ) − f (xk−1 )
12
Algorithm 1.3 The Secant Method
For k = 1, 2, · · · do
• Compute f (xk ) and f (xk−1 ).
f (xk )(xk − xk−1 )
• Compute the next approximation: xk+1 = xk −
f (xk ) − f (xk−1 )
• Test for convergence or maximum number of iterations: If |xk+1 − xk | < or if k > N , Stop.
End
Note: The secant method needs two approximations x0 , x1 to start with, whereas the Newton-Raphson
method just needs one, namely, x0 .
Example 1.7 f (x) = x2 − 2 = 0.
Let x0 = 1.5, x1 = 1
Iteration 1. k = 1.
f (x1 )(x1 − x0 )
x2 = x1 −
f (x1 ) − f (x0 )
(−1)(−.5) .5
= 1− =1+ = 1.4
−1 − .25 1.25
Iteration 2
f (x2 )(x2 − x1 )
x3 = x2 −
f (x2 ) − f (x1 )
(−0.04)(−0.1)
= 1.4 −
(−0.04) − (−1)
= 1.4 + 0.0042
= 1.4042
Iteration 3
f (x3 )(x3 − x2 )
x4 = x3 −
f (x3 ) − f (x2 )
= 1.4143.
Iteration 4
f (x4 )(x4 − x3 )
x5 = x4 − = 1.4142
f (x4 ) − f (x3 )
13
Remarks: By comparing the results of this example with those obtained by the Newton-Raphson (Ex-
ample
√ 1.5) method, we see that it took 5 iterations by the secant method to obtain a 4-digit accuracy of
2 = 1.4142; whereas for the Newton-Raphson method, this accuracy was obtained just after 2 iteration.
In general, the Newton-Raphson method converges faster than the secant method. The exact rate
of convergence of these two and the other methods will be discussed in the next section.
• x2 is the x-intercept of the secant line passing through (x0 , f (x0 )) and (x1 , f (x1 )).
• x3 is the x-intercept of the secant-line passing through (x1 , f (x1 )) and (x2 , f (x2 )).
• And so on.
(x1 , f (x1 ))
x2
x0 x=ξ x1
(x2 , f (x2 ))
(x0 , f (x0 ))
Example 1.8 Consider solving f (x) = tan(πx) − 6 = 0, using the Secant Method.
Take: x0 = 0 x1 = 0.48
(Note that ξ = 0.44743154 is a root of f (x) = 0 lying in the interval [0, 0.48]).
Iteration 1
(x1 − x0 )
x2 = x1 − f (x1 ) = 0.181194
f (x1 ) − f (x0 )
Iteration 2
x0 = 0.48, x1 = 0.181194
14
x2 = 0.286187
Iteration 3
x0 = 0.181194, x1 = 0.286187
x2 = 1.091987. Clearly, The iterations are diverging.
However, the secant method can easily be modified to make it a bracket method. The idea is as follows:
• Choose the initial approximations x0 and x1 such that f (x0 ) f (x1 ) < 0, ensuring that the root is in
[x0 , x1 ].
• Compute x2 as in the Secant method; that is, take x2 is the x-intercept of the secant line passing
through x0 and x1 .
• This yields a method called, the Method of False Position or the Method of Regular Falsi.
Step 0. Set i = 1.
(xi − xi−1 )
Step 1. Compute xi+1 = xi − f (xi )
f (xi ) − f (xi−1 )
xi+1 − xi
If | | < or i ≥ N . Stop.
xi
Step 2. If f (xi ).f (xi+1 ) < 0, then, set xi ≡ xi+1 , xi−1 ≡ xi .
Otherwise, set xi ≡ xi+1 , xi−1 ≡ xi−1 . Return to step 0. End
f (x) = tan(πx) − 6 = 0.
15
x0 = 0, x1 = 0.48; f (x0 ).f (x1 ) < 0
Iteration 1
x1 − x0
x2 = x1 − f (x1 ) = 0.181194
f (x1 ) − f (x0 )
f (x2 ).f (x1 ) < 0
Iteration 2
x1 − x0
x2 = x1 − f (x1 ) = 0.286187
f (x1 ) − f (x0 )
f (x2 ).f (x1 ) > 0
Iteration 5
x2 = 0.410304
Definition 1.2 (Rate of Convergence of an Iterative Method). Suppose that the sequence {xk }
converges to ξ. Then the sequence {xk } is said to converge to ξ with the order of convergence α if there
exists a positive constant p such that
|xk+1 − ξ| ek+1
lim = lim = p.
k→∞ |xk − ξ|α k→∞ eα k
Thus if α = 1, the convergence is linear. If α = 2, the convergence is quadratic; and so on. The number
α is called the convergence factor.
Using the above definition, we will now show that the rate of convergence for the Fixed Point Iteration
method is usually linear but that of the Newton-Raphson method is quadratic, and that of the Secant method
is superlinear.
ek+1 = |g 0 (c)|ek ,
16
where c is a number between xk and ξ.
ek+1
So, lim = lim |g 0 (c)|.
k→∞ ek k→∞
Since {xk } → ξ, and c is in (xk , ξ), it follows that lim |g 0 (c)| = |g 0 (ξ)|.
k→∞
ek+1
This gives lim = |g 0 (ξ)|. Thus α = 1.
k→∞ ek
We, therefore, have
xk+1 = g(xk ), k = 0, 1, · · ·
converges linearly.
f 00 (p)
f (x) = f (p) + f 0 (p)(x − p) + (x − p)2
2!
f n (p)
+···+ (n − p)n + Rn (x),
n!
f (n+1) (c)
Rn (x) = (x − p)n+1
(n + 1)!
Let’s choose a small interval around the root x = ξ. Then for any x in this interval, we have, by Taylor’s
theorem of order 1, the following expansion of the function g(x):
(x − ξ)2 00
g(x) = g(ξ) + (x − ξ)g 0 (ξ) + g (ηk )
2!
where ηk lies between x and ξ.
17
Now, for the Newton-Raphson Method, we have seen that g 0 (ξ) = 0.
(x − ξ)2 00
So, g(x) = g(ξ) + g (ηk )
2!
(xk − ξ)2 00
or g(xk ) = g(ξ) + g (ηk ).
2!
(xk − ξ)2 00
or g(xk ) − g(ξ) = g (ηk ).
2!
Since g(xk ) = xk+1 , and g(ξ) = ξ, this give
(xk − ξ)2 00
xk+1 − ξ = g (ηk )
2!
|xk − ξ|2 00
That is, |xk+1 − ξ| = |g (ηk )|
2
ek+1 |g 00 (ηk )|
or = .
e2k 2
Since ηk lies between x and ξ for every k, it follows that
lim ηk = ξ.
k→∞
The quadratic convergence roughly means that the accuracy gets doubled at each iteration.
The Rate of Convergence for the Secant Method.
It can be shown [Exercise] that if the Secant method converges, then the convergence factor α is approxi-
mately 1.6 for sufficiently large k. This is said as “The rate of convergence of the Secant method is
superlinear”.
where f (m−1) (ξ) denotes the (m − 1)th derivative of f (x) at x = ξ. In this case f (x) can be written as
f (x) = (x − ξ)m h(x), where h(x) is a polynomial of degree at most m − 2.
18
In case f (x) has a root of multiplicity m, it was suggested by Ralston and Robinowitz (1978) that, the fol-
lowing modified iteration will ensure quadratic convergence in the Newton-Raphson method, under certain
conditions [Exercise].
Since in practice, the multiplicity m is not known apriori, another useful modification is to apply the
Newton-Raphson iteration to the function:
f (x)
u(x) =
f 0 (x)
in place of f (x).
u(xi )
Thus, in this case, the modified Newton-Raphson iteration becomes xi+1 = xi − .
u0 (xi )
Note that, since f (x) = (x − ξ)m h(x), u0 (x) 6= 0 at x = ξ.
Example:
f (x) = ex − x − 1
f 0 (x) = ex − 1
f 00 (x) = ex
19
2(e0.0415 − 0.0415 − 1)
Iteration 2. x2 = 0.0415 − = .00028703 = 2.8703 × 10−4 .
e0.0415 − 1
Method II
f (x) = ex − x − 1.
f (xi )f 0 (xi )
xi+1 = xi −
(f 0 (xi )2 − ((f (xi )f 00 (xi ))
x0 = 0.5
Iteration 1. x1 = −0.0493 = −4.93 × 10−2
b n = an
bn−1 − bn z = an−1 ⇒ bn−1 = an−1 + bn z
..
.
and so on.
In general, bk − bk+1 z = ak ⇒ bk = ak + bk+1 z. k = n − 1, n − 2, ..., 1, 0.
Thus, knowing the coefficients an , an−1 , ..., a1 , a0 of Pn (x), the coefficients bn , bn−1 , ..., b1 of Qn−1 (x) can be
computed recursively starting with bn = an , as shown above. That is, bk = ak + bk+1 z, k = n − 1, k =
2, . . . , 1, 0.
Again, note that Pn (z) = b0 . So, Pn (z) = b0 = a0 + b1 z.
That is, if we know the coefficients of a polynomial, we can compute the value of the polynomial at a given
point out of these coefficients recursively as shown above.
20
Algorithm 1.5 Evaluating Polynomial: Pn (x) = a0 + a1 xp + a2 x2 + . . . + an xn at x = z.
Outputs: b0 = Pn (z).
Step 1. Set bn = an .
Compute bk = ak + bk+1 z
End
It is interesting to note that as a by-product of above, we also obtain Pn0 (z), as the following computations
show :
Inputs: (1) b1 , ..., bn - The coefficients of the polynomial Qn−1 (x) obtained from the
previous algorithm
(2) A number z.
Step 1. Set cn = b n ,
Compute ck = bk + ck+1 z,
End
21
Example 1.10 Let P3 (x) = x3 − 7x2 + 6x + 5.
Let z = 2.
Here a0 = 5, a1 = 6, a2 = −7, a3 = 1.
Generate the sequence {bk } from {ak }:
b 3 = a3 = 1
b2 = a2 + b3 z = −7 + 2 = −5
b1 = a1 + b2 z = 6 − 10 = −4
b0 = a0 + b1 z = 5 − 8 = −3.
So, P3 (2) = b0 = −3
f (xk )
xk+1 = xk −
f 0 (xk )
In case f (x) is a polynomial Pn (x) of degree n: f (x) = Pn (x) = a0 + a1 x + a2 x2 + · · · + an xn , the above
iteration becomes:
Pn (x)
xk+1 = xk − 0
Pn (xk )
If the sequence {bk } and {ck } are generated using Horner’s Scheme, at each iteration we then have
b0
xk+1 = xk −
c1
22
Algorithm 1.6 The Newton-Raphson Method with Horner’s Scheme
For k = 0, 1 , 2, · · · , do
Step 1. z = xk , bn ≡ an , cn ≡ bn
For j = n − 1, n − 2, · · · , 1 do
bj ≡ aj + z bj+1
cj ≡ bj + z cj+1
End.
Step 3. b0 = a0 + z b1
End
Notes:
1. The outer-loop corresponds to the Newton-Raphson Method
2. The inner-loop and the statement b0 = a0 + z b1 corresponds to the evaluation of Pn (x) and its
derivative Pn (x) at successive approximations.
Example 1.11 Find a root of P3 (x) = x3 − 7x2 + 6x + 5 = 0, using the Newton-Raphson method and
Horner’s scheme.
P3 (x) has a root between 1.5 and 2.
Let x0 = 2
Iteration 1. k = 0:
b0 = −3, c1 = −10
b0 3 17
x1 = x0 − =2− = = 1.7
c1 10 10
Iteration 2. k = 1:
z = x1 = 1.7, b3 = 1, c3 = b3 = 1.
23
b2 = a2 + z b3 = −7 + 1.7 = −5.3
b1 = a1 + z b2 = 6 + 1.7(−5.3) = −3.0100
b0 = a0 + z b1 = 5 + 1.7(−3.0100) = −0.1170
b0 0.1170
x2 = x1 − = 1.7 − = 1.6872
c1 9.130
(The exact root, correct upto four decimal places is 1.6872).
• Recall that starting with two initial approximations x0 and x1 , the Secant Method finds the next
approximation x2 as the x-intercept of the line passing throught (x0 , f (x0 )), and (x1 , f (x1 )).
• In the Müler Method, starting with three initial approximations x0 , x1 and x2 , the next approximaiton
x3 is obtained as the x-intercept of the parabola P passing through (x0 , f (x0 )), (x1 , f (x1 )), and
(x2 , f (x2 )).
• Since a parabola can intersect x-axis at two points, the one that is close to x2 is taken as x3 .
24
x0 x1 x2 x3
To avoid catastrophic cancellation, instead of using the traditional formula, we use the following formula
for solving the quadratic equation ax2 + bx + c = 0.
The sign in the denominator is chosen so that it is the largest in magnitude, guaranteeing that x3 is closest
to x2 .
−2c
In our case, x3 − x2 = √
b ± b2 − 4ac
25
−2c
or x3 = x2 + √ .
b ± b2 − 4ac
Note: one can also give on explicit expresions for a and b as follows:
(x0 − x2 )2 [f (x1 ) − f (x2 )] − (x1 − x2 )2 [f (x0 ) − f (x2 )]
b=
(x0 − x2 )(x1 − x2 )(x0 − x1 )
−2c
Step 3: Compute x3 = x2 + √ choosing + or − so that the denominator is the
b ± b2 − 4ac
largest in magnitude.
Step 4: Test if |x3 − x2 | < or if the number of iterations exceeds N . If so, stop. Otherwise go
to Step 5.
26
2c 12
Step 3: Compute x3 = x2 − √ = x2 + √ = 0.25 + 1.5612i
b− 2
b − 4ac −3 − 9 − 48
2c
Step 3: x3 = x2 − √ = x2 − (0.8388 + 0.3702i) = −0.5888 + 1.1910i
b− b2 − 4ac
Iteration 4
x3 = −0.3563 + 1.3238i
Iteration 5
x3 = −0.3492 + 1.3184i
Iteration 6
x3 = −0.3464 + 1.3180i
Iteration 7
x3 = −0.3455 + 1.3183i
x3 − x2
Since | | < 6.8738 × 10−4 , we stop here.
x2
Thus, an approximate pair of complex roots is: α1 = −0.3455 + 1.3183i, α2 = 0.3455 − 1.3183i.
27
Verify:
(x − α1 )(x − α2 )(x − 2.6906) = x3 − 2.006x2 − 4.9975.
All three roots are real: 5.8210, 1.6872, −0.5090. We will try to approximate the root 1.6872.
Iteration 1.
x0 = 0, x1 = 1, x2 = 2
Or ! ! !
4 −2 a 8
= , which gives a = −4, b = −12.
1 −1 b 8
2c
Step 3: Compute x3 = x2 − √
b − b2 − 4ac
= x2 − 0.2753 = 1.7247 (choosing the negative sign in the determinant).
Iteration 2.
x2 = x3 = 1.7247, x1 = x2 = 2, x0 = x1 = 1
28
The roots of this polynomial equation are 1, 2, ..., 20 and thus very well-separated. But, a small perturbation
of the coefficient x19 which is -210 will change the roots completely. Some of them will even become complex.
Try this yourself using MATLAB function roots.
29
Roots of Wilkinson polynomial
4
original
perturbed
1
Im
−1
−2
−3
−4
0 5 10 15 20 25
Re
where Qn−2 (x) is a polynomial of degree n − 2. Moreover, the zeros of Qn−1 (x) in the first case
and those of Qn−2 (x) is the second case are also the zeros of P (x). The coefficients of Qn−1 (x) or
Qn−2 (x) can be generated using synthetic division as in Horner’s method, and then any of the root-finding
procedure obtained before can be applied to compute a root or a pair of roots of Qn−2 (x) = 0 or Qn−1 (x).
The procedure can be continued until all the roots are found.
Example 1.14 Consider finding the roots of f (x) = x4 + 2x3 + 3x2 + 2x + 2 = 0. It is easy to see that x ± i
is a pair of complex conjugate roots of f (x) = 0. Then we can write
or
x4 + 2x3 + 3x2 + 2x + 2 = (x2 + 1)(b3 x2 + b2 x + b1 ).
30
Equating coefficients of x4 , x3 , and x2 on both sides, we obtain
b3 = 1, b2 = 2, b1 + b3 = 3,
giving b3 = 1, b2 = 2, b1 = 2.
Thus, (x4 + 2x3 + 3x2 + 2x + 2) = (x2 + 1)(x2 + 2x + 2).
The zeros of the deflated polynomial Q2 (x) = x2 + 2x + 2 can now be found by using any of the methods
described earlier.
31
PART II.
Interpolation
2 Interpolation
2.1 Problem Statement and Applications
Consider the following table:
x0 f0
x1 f1
x2 f2
.. ..
. .
xk fk
.. ..
. .
xn fn
In the above table, fk , k = 0, · · · , n are assumed to be the values of a certain function f (x), evaluated
at xk , k = 0, · · · , n in an interval containing these points. Note that only the functional values are
known, not the function f (x) itself. The problem is to find fu corresponding to a nontabulated inter-
mediate value x = u.
Such a problem is called an Interpolation Problem. The numbers x0 , x1 , · · · , xn are called the nodes.
Interpolation Problem
The Interpolation problem is also a classical problem and dates back to the time of Newton and Kepler,
who needed to solve such a problem in analyzing data on the positions of stars and planets. It is also of
interest in numerous other practical applications. Here is an example.
32
Pn (x0 ) = f0 = a0 + a1 x0 + a2 x20 + · · · + an xn0
Pn (x1 ) = f1 = a0 + a1 x1 + a2 x21 + · · · + an xn1
.. (2.1)
.
Pn (xn ) = fn = a0 + a1 xn + a2 x2n + · · · + an xn2
These equations can be written in matrix form:
a0
1 x0 x20 · · · xn0 f0
a1
1 x1 x21 · · · xn1 f1
a2 = (2.2)
.. ..
.
..
.
.
1 xn x2n · · · xnn fn
an
Because x0 , x1 , · · · , xn are distinct, it can be shown [Exercise] that the matrix of the above system is
nonsingular. Thus, the linear system for the unknowns a0 , a1 , · · · , an has a unique solution, in view of the
following well-known result, available in any linear algebra text book.
33
be accurate. There are, however, several other ways to construct such a polynomial, that do not require
solution of a Vandermonde system. We describe one such in the following:
Suppose n = 1, that is, suppose that we have only two points (x0 , f0 ), (x1 , f1 ), then it is easy to see that
the linear polynomial
x − x1 (x − x0 )
P1 (x) = f0 + f1
(x0 − x1 ) (x1 − x0 )
is an interpolating polynomial, because
P1 (x0 ) = f0 , P1 (x1 ) = f1 .
is an interpolating polynomial.
To see this, note that
(x − x1 ) · · · (x − xn )
L0 (x) =
(x0 − x1 ) · · · (x0 − xn )
(x − x0 )(x − x2 ) · · · (x − xn )
L1 (x) =
(x1 − x0 )(x1 − x2 ) · · · (x1 − xn )
..
.
(x − x0 )(x − x1 )(x − x2 ) · · · (x − xn−1 )
Ln (x) =
(xn − x0 )(xn − x1 )(xn − x2 ) · · · (xn − xn−1 )
Also, note that
Thus
Pn (x0 ) = L0 (x0 )f0 + L1 (x0 )f1 + · · · + Ln (x0 )fn = f0
34
Example 2.1 Interpolate f (x) from the following table:
0 7
1 13
2 21
4 43
(x − 1)(x − 2)(x − 4)
L0 (x) =
(−1)(−2)(−4)
(x − 0)(x − 2)(x − 4)
L1 (x) =
1 · (−1)(−3)
(x − 0)(x − 1)(x − 4)
L2 (x) =
2 · 1 · (−2)
(x − 0)(x − 1)(x − 2)
L3 (x) =
4·3·2
i xi f (xi )
1
0 2
2
1
1 2.5
2.5
1
2 4
4
We want to find f (3).
(x − x1 )(x − x2 ) (x − 2.5)(x − 4)
L0 (x) = = = (x − 2.5)(x − 4)
(x0 − x1 )(x0 − x2 ) (−0.5)(−2)
(x − x0 )(x − x2 ) (x − 2)(x − 4) 1
L1 (x) = = =− (x − 2)(x − 4)
(x1 − x0 )(x1 − x2 ) (0.5)(−1.5) 0.75
(x − x1 )(x − x0 ) 1
L2 (x) = = (x − 2.5)(x − 2)
(x2 − x1 )(x2 − x0 ) 3
1 1 1
L0 (x) +
P2 (x) = f (x0 )L0 (x) + f (x1 )L1 (x) + f (x2 )L2 (x) = L1 (x) + L2 (x)
2 2.5 4
1 1 1 1 1 1 1 .5
P2 (3) = L0 (3) + L1 (3) + L2 (3) = (−0.5) + + = 0.3250
2 2.5 4 2 2.5 0.75 4 3
35
1
Verify: (The value of f (x) at x = 3 is 3 ≈ 0.3333).
Theorem 2.2 (Interpolation-Error Theorem) Let Pn (x) be the interpolating polynomial that interpo-
lates at (n + 1) distinct numbers in [a, b], and let f (x) be (n + 1) times continuously differentiable on [a, b].
Then for every x̄ in [a, b], there exists a number ξ = ξ(x̄) in (a, b) (depending on x̄) such that
f (n+1) (ξ(x̄)) Y
n
En (x̄) = f (x̄) − Pn (x̄) = (x̄ − xi ). (2.5)
(n + 1)! i=0
Proof: If x̄ is one of the numbers x0 , x1 , · · · , xn : then the result follows trivially. Because, the error in this
case is zero, and the result will hold for any arbitrary ξ.
Next, assume that x̄ is not one of the numbers x0 , x1 , · · · , xn .
Define a function g(t) in variable t in [a, b]:
(t − x0 )(t − x1 ) · · · (t − xn )
g(t) = f (t) − Pn (t) − [f (x̄) − Pn (x̄)] ∗ . (2.6)
(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn )
=0
(Note that the numerator of the fraction appearing above contains the term (xk − xk ) = 0).
Furthermore,
(x̄ − x0 ) · · · (x̄ − xn )
g(x̄) = f (x̄) − Pn (x̄) − [f (x̄) − Pn (x̄)] ∗
(x̄ − x0 ) · · · (x̄ − xn )
= f (x̄) − Pn (x̄) − f (x̄) + Pn (x̄) (2.8)
=0
Thus, g(t) becomes identically zero at (n + 2) distinct points: x0 , x1 , · · · , xn , and x̄. Furthermore, g(t) is
(n + 1) times continuously differentiable, since f (x) is so.
Therefore, by generalized Rolle’s theorem, [ ], there exists a number ξ(x̄) in (a, b) such that g (n+1) (ξ) =
0.
Let’s compute g (n+1) (t) now. From (2.5) we have
dn+1 (t − x0 )(t − x1 ) · · · (t − xn )
g (n+1) (t) = f (n+1) (t) − Pn(n+1) (t) − [f (x̄) − Pn (x̄)] (2.9)
dn+1 ((x̄ − x0 )(x̄ − x1 ) · · · (x̄xn )
Then
36
dn+1 (t − x0 )(t − x1 ) · · · (t − xn )
dtn+1 (x̄ − x0 )(x̄ − x1 ) · · · (x̄xn )
1 dn+1
= · n+1 [(t − x0 )(t − x1 ) · · · (t − xn )]
(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn ) dt
1
= (n + 1)!
(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn )
(n+1) (n+1)
Also, Pn (t) = 0, because Pn is a polynomial of degree at most n. Thus, Pn (ξ) = 0.
So,
(f (x̄) − Pn (x̄))
g (n+1) (ξ) = f (n+1) (ξ) − (n + 1)! (2.10)
(x̄ − x0 ) · · · (x̄ − xn )
f (n+1) (ξ)
Since g (n+1) (ξ) = 0, from (2.10), we have En (x̄) = f (x̄) − Pn (x̄) = (x̄ − x0 ) · · · (x̄ − xn ).
(n + 1)!
Remark: To obtain the error of interpolation using the above theorem, we need to know the (n + 1)th
derivative of the f (x) or its absolute maximum value on the interval [a, b]. Since in practice this value is
hardly known, this error formula is of limited use only.
Example 2.3 Let’s compute the maximum absolute error for Example 2.2.
Here n = 2.
f (3) (ξ)
= (x̄ − x0 )(x̄ − x1 )(x̄ − x2 )
3!
To know the maximum value of E2 (x̄), we need to know f (3) (x).
Let’s compute this now:
1 1 2 6
f (x) = , f 0 (x) = − 2 , f 00 (x) 3 , f (3) (x) = − 4 .
x x x x
6 6
So, |f (3) (ξ)| < 4 = for 0 < x ≤ 2.
2 16
Since x̄ = 3, x0 = 2, x1 = 2.5, x2 = 4, we have
6 1
× (3 − 2)(3 − 2.5)(3 − 4)| = 0.0625.
|E2 (x̄)| ≤ |
16 6
Note that in four-digit arithmetic, the difference between the value obtained by interpolation and the exact
value is 0.3333 − 0.3250 = 0.0083.
37
h h h h h
a = x0 x1 x2 b = xn
Then it can be shown [Exercise] that
hn+1
|(x̄ − x0 )(x̄ − x1 ) · · · (x̄ − xn )| ≤ n!
4
If we also assume that |f (n+1) (x)| ≤ M , then we have
M hn+1 M hn+1
|En (x̄)| = |f (x̄) − Pn (x̄)| ≤ n! = . (2.11)
(n + 1)! 4 4(n + 1)
Example 2.4 Suppose a table of values for f (x) = cos x has to be prepared in [0, 2π] with equal spacing
nodes of spacing h, using linear interpolation, with an error of interpolation of at most 5 × 10−8 . How
small should h be?
Here n = 1.
f (x) = cos x, f 0 (x) = − sin x, f 2 (x) = f 00 (x) = − cos x
max |f (2) (x)| = 1, for 0 ≤ x ≤ 2π
Thus M = 1.
38
Furthermore, computing various Lagrangian polynomials is an expensive procedure. It is, indeed, desir-
able to have a formula which makes use of Pk−1 (x) in computing Pk (x).
The following form of interpolation, known as Newton’s interpolation allows us to do so.
The idea is to obtain the interpolating polynomial Pn (x) in the following form:
f [xi+1 ] − f [xi ]
f (xi ) = f [xi ] and f [xi , xi+1 ] =
xi+1 − xi
Similarly,
f [xi+1 , ..., xi+k−1 , xi+k ] − f [xi , xi+1 , ..., xi+k−1 ]
f [xi , xi+1 , · · · , xi+k−1 , xi+k ] =
xi+k − xi
With these notations, we then have
a0 = f0 = f (x0 ) = f [x0 ]
f1 − f0 f (x1 ) − f (x0 ) f [x1 ] − f [x0 ]
a1 = = = = f [x0 , x1 ].
x1 − x0 x1 − x0 x1 − x0
Continuing this, it can be shown that [Exercise]
ak = f [x0 , x1 , · · · , xk ]. (2.13)
Substituting these expressions of ak in (2.13), the interpolating polynomial Pn (x) now can be written in
terms of the divided differences:
Pn (x) = f [x0 ] + f [x0 , x1 ](x − x0 ) + f [x0 , x1 , x2 ](x − x0 )(x − x1 ) + · · · +
(2.14)
f [x0 , x1 , · · · , xn ](x − x0 )(x − x1 ) · · · (x − xn−1 ).
Notes:
(i) Each divided difference can be obtained from two previous ones of lower orders.
For example, f [x0 , x1 , x2 ] can be computed from f [x0 , x1 ], and f [x1 , x2 ], and so on. Indeed, they can
be arranged in form of a table as shown below:
39
Table of Divided Differences (n = 4)
x f (x) 1st Divide Difference 2nd Divided Difference 3rd Divided Difference
x0 f0
f [x0 , x1 ]
x1 f1 f [x0 , x1 , x2 ]
f [x1 , x2 ]
f [x0 , x1 , x2 , x3 ]
x2 f2 f [x1 , x2 , x3 ]
f [x2 , x3 ]
f [x1 , x2 , x3 , x4 ]
x3 f3 f [x2 , x3 , x4 ]
f [x3 , x4 ]
x4 f4
(ii) Note that in computing Pn (x) we need only the diagonal entries of the above table; that is, we need
only f [x0 ], f [x0 , x1 ], · · · , f [x0 , x1 , · · · , xn ].
(iii) Since the divided differences are generated recursively, the interpolating polynomials of successively
higher degrees can also be generated recursively. Thus the work done previously can be used
gainfully.
For example,
P1 (x) = f [x0 ] + f [x1 , x0 ](x − x0 )
P2 (x) = f [x0 ] + f [x0 , x1 ](x − x0 ) + f [x0 , x1 , x2 ](x − x0 )(x − x1 )
= P1 (x) + f [x0 , x1 , x2 ](x − x0 )(x − x1 ).
i xi fi 1st diff. 2nd diff. 3rd diff. 4th diff. 5th diff.
0 1.0 0
0.3522
1 1.5 0.17609 −0.1023
0.2400 0.0265533
2 2.0 0.30103 −0.0491933 −0.006408
0.1761 0.0105333 −00.2172
3 3.0 0.47712 −0.0281267 .001412
0.1339 0.0051033
4 3.5 0.54407 −0.01792
0.11598
5 4.0 0.60206
40
From (2.14), with n = 3, we have
(Note that in computing P4 (2.5), P3 (2.5) computed previously has been gainfully used).
If we use the notation Dij = f [xi , . . . , xi+j ]. Then
Inputs:
The definite numbers x0 , x1 , · · · , xn and the values f0 , f1 , · · · , fn .
Outputs:
The Divided Differenced D00 , D11 , · · · Dnn .
Step 2: For i = 1, 2, · · · , n do
j = 1, 2, · · · i do
Di,j−1 − Di−1,j−1
Dij =
xi − xi−j
End
A Relationship Between nth Divided Difference and the nth Derivative
The following theorem shows how the nth derivative of a function f (x) is related to the nth divided difference.
The proof is omitted. It can be found in any advanced numerical analysis text book (e.g., Atkins on (1978),
p. 144).
Theorem 2.3 Suppose f is n times continuously differentiable and x0 , x1 , · · · , xn are (n + 1) distinct num-
bers in [a, b]. Then there exists a number ξ in (a, b) such that
f (n) (ξ)
f [x0 , x1 , · · · , xn ] =
n!
41
The Newton Interpolation with Equally Spaced Nodes
Suppose again that x0 , · · · , xn are equally spaced with spacing h;
that is xi+1 − xi = h, i = 0, 1, 2, ..., n − 1. Let x − x0 = sh.
Then x − x0 = sh
x − x1 = x − x0 + x0 − x1 = (x − x0 ) − (x1 − x0 ) = sh − h = (s − 1)h
In general, x − xi = (s − i)h.
So,
f [x1 , x2 ] − f [x0 , x1 ]
f [x0 , x1 , x2 ] =
(x2 − x0 )
f (x2 )−f (x1 ) f (x1 )−f (x0 )
x2 −x1 − x1 −x0
= (2.19)
(x2 − x0 )
f (x2 ) − 2f (x1 ) + f (x0 ) ∆2 f0
= =
h × 2h 2h2
In general, we have
Theorem 2.4
f [x0 , x1 , . . . , xk ]
1 (2.20)
= ∆k f0 .
k!hk
42
Proof is by induction on k.
For k = 0, the result is trivially true. We have also proved the result for k = 1, and k = 2.
Assume now that the result is true k = m. Then we need to show m that the result
is also true for k = m + 1.
∆ f1 ∆m f0
f [x1 , . . . , xm+1 ] − f [x0 , . . . , xm ] m!hm − m!hm ∆m (f1 − f0 ) ∆m+1 f0
Now, f [x0 , · · · , xm+1 ] = = = =
xm+1 − x0 (m + 1)h m!(m + 1)h m+1 (m + 1)!hm+1
x − x0
where s = .
h
x f (x) ∆f ∆2 f ∆3 f ∆4 f
x0 f0
∆f0
x1 f1 ∆2 f0
∆f1 ∆3 f0
2
x2 f2 ∆ f1 ∆3 f0
3
∆f2 ∆ f1
x3 f3 ∆2 f2
∆f3
x4 f4
43
x f ∆f ∆2 f ∆3 f
0 1
1.7183
1 2.7183 2.9525
4.6708 5.0731
2 7.3891 8.0256 8.7177
12.6964 13.7908
3 20.0855 21.8163
34.5127
4 54.5982
Let x = 1.5
x − x0 1.5 − 0
Then s = = = 1.5
h 1
1.5 1.5 1.5 1.5 1.5
P4 (1.5) = 1+ 1.7183+ 2.9525+ 5.0731+ 8.7177 = 1+1.5(1.7183)+
0 1 2 3 4
0.3750(2.9525) + (−0.0312)(5.0731) + (0.0020)(8.7177) = 4.5438
The correct answer up to 4 decimal digits is 4.4817.
∇fn = fn − fn−1 , n = 1, 2, 3, . . . ,
and
∇k fn = ∇(∇k−1 fn ), k = 2, 3, . . .
44
Newton’s Backward-Difference
Interpolations Formula
X
n
k −s
Pn (x) = (−1) 5k f n .
k
k=0
2.7 Spline-Interpolation
So far we have been considering interpolation by means of a single polynomial in the entire range.
Let’s now consider interpolation using different polynomials (but of the same degree) at different intervals.
Let the function f (x) be defined at the nodes a = x0 , x1 , x2 , ..., xn = b. The problem now is to construct
piecewise polynomials Sj (x) on each interval [xj , xj+1 ], j = 0, 1, 2, ..., n − 1, so that the resulting function
S(x) is an interpolant for the function f (x).
The simplest such polynomials are of course, linear polynomials (straight lines). The interpolating polynomial
in this case is called linear spline. Two most disadvantages of a linear spline are (i) the convergence is
rather very slow, and (ii) not suitable for applications demanding smooth approximations, since these splines
have corner at the knots.
“Just imagaine a cross section of an airplane wing in the form of a linear spline and you quickly decide to
go by rail. (Stewart (1998), p. 93).”
Likewise the quadratic splines have also certain disadvantages.
The most common and widely used splines are cubic splines. Assume that the cubic polynomial Sj (x),
has the following form:
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 .
Since Sj (x) contains four unknowns, to construct n cubic polynomials S0 (x), S1 (x), ..., Sn−1 (x), we need 4n
conditions. To have these 4n conditions, a cubic spline S(x) for the function f (x) can be conveniently defined
as follows:
Cubic Spline Interpolant
A function S(x), denoted by Sj (x) over the interval [xj , xj+1 ], j = 0, 1, ..., n − 1 is called a cubic
spline interpolant if the following conditions hold:
Then, since for j ther are four unkowns: aj , bj , cj , and dj and there are n such polynomials to be determined,
all together there are 4n unknowns. However, conditions (i)-(iv) above give only (4n − 2) equations: (i) gives
n + 1, and each of (ii)-(iv) gives n − 1. So, to completely determine the cubic spline, we must need two more
equations. To obtain these two additional equations, we can invoke boundary conditions.
• If the second derivative of S(x) can be approximated, than we can take: (i) S 00 (x0 ) = S 00 (xn ) = 0
(free or natural boundary).
• On the other hand, if only the first derivative can be estimated, we can use the following boundary
condition: (ii) S 0 (x0 ) = f 0 (x0 ), and S 0 (xn ) = f 0 (xn ) (clamped boundary).
• We will discuss only the clamped cubic spline here.
From the condition (i), it immediately follows that
45
aj = fj , j = 0, 1, 2, ..., n.
Set hj = xj+1 − xj . With some mathematical manipulations, it can then be shown (see for e.g., Burden and
Faires, pp. 144-145), that once aj ’s are known, the coefficients cj , j = 0, 1, 2, ..., n can be found by solving
the following linear algebraic system of equations:
Ax = r,
where
A=
2h0 h0 0 0
..
h .
0 2(h0 + h1 ) h1
..
0 h1 2(h1 + h2 ) h2 .
.. .. .. ..
. . . .
0
..
. hn−2 2(hn−2 + hn−1 ) hn−1
0 0 hn−1 2hn−1
3
h0 (a1 − a0 ) − 3f 0 (a)
c0
3
− a1 ) − − a0 )
3
c1 h1 (a2 h0 (a1
x= .. , r = .
. ..
.
cn
0 3
3f (b) − hn−1 (an − an−1 )
Once c0 , c1 , ..., cn are known by solving the above system of equations, the quantities bj and dj can be
computed as follows:
(aj+1 − aj ) hj
bj = − (cj+1 + 2cj ), j = n − 1, n − 2, · · · , 0
hj 3
cj+1 − cj
dj = , j = n − 1, n − 2, · · · , 0.
3hj
Note:
The matrix A is a symmetric strictly diagonally daminant matrix and can be solved in O(n) flops, as described
before. (See the book, Numerical Linear Algebra and Application, by Biswa Nath Datta, Brooks-Cole
Publishing Co., Pacific Grove, California, (1995)).
46
Algorithm 2.2 Computing Clamped Cubic Spline
Inputs:
(i) The nodes x0 , x1 , ..., xn .
(ii) The functional values:
f (xi ) = fi , i = 0, 1, ..., n.
(Note that a = x0 and b = xn ).
(iii) f 0 (x0 ) = f 0 (a) and f 0 (xn ) = f 0 (b).
Outputs: The coefficients a0 , ..., an ; b0 , ..., bn ; c0 , c1 , ..., cn , and d0 , d1 , ..., dn of the n polynomials
S0 (x), S1 (x), ..., Sn−1 (x) of which the cubic interpolant S(x) is composed.
Step 1. For i = 0, 1, ..., n − 1 do
Set hj = xj+1 − xj
Step 2. Compute a0 , a1 , ..., an :
For i = 0, 1, ..., n − 1 do
ai = f (xi ), i = 0, 1, ..., n.
End
Step 3. Compute the coefficients c0 , c1 , ..., cn by solving the system Ax = r, where A, x, and r are as defined
above.
Step 4. Compute the coefficients b0 , ..., bn and d0 , d1 , ..., dn as given in the box above.
47
Exercises
Y
n
(t − xi )
dn+1 i=0 (n + 1)!
1. Prove by induction that n+1 n = n
dt Y Y
(x − xi ) (x − xi )
i=0 i=0
3. Suppose that a table is to be prepared for the function f (x) = ln x on [1, 3.5] with equal spacing
nodes such that the interpolation with third degree polynomial will give an accuracy of = 5 × 10−8 .
Determine how small h has to be to guarantee the above accuracy.
48
4. Prove by induction that
∆k f0
(a) f [x0 , x1 , · · · , xk ] = .
k!hk
(b) ak = f [x0 , x1 , · · · , xk ], where ak ’s are the coefficients of the Newton interpolating polynomial.
5. (a) Find an approximate value of log10 (5) using Newton’s forward difference formula with x0 =
1, x1 = 2.5, x2 = 4, and x3 = 5.5.
6. Using the data of problem 2, estimate f (1.025) with linear and quadratic splines and compare your
results with those obtained there.
49
7. Show that f [x0 , x1 , · · · , xn ] does not change if the nodes are rearranged.
√
2 3 3
(b) max |ψ2 (x)| = h
9
x0 ≤ x ≤ x2
[Hint: To bound |ψ2 (x)|, shift this polynomial along the x-axis:
ψ̂2 (x) = (x + h)x(x − h) and obtain the bound of ψ̂2 (x)].
(d) Using the results of (a), (b), and (c), obtain the maximum absolute error in each case for the
functions:
f (x) = ex , 0 ≤ x ≤ 2
Π
f (x) = sin x 0 ≤ x ≤
2
(e) The interpretation of the result of Part (c) is that if the interpolation nodes are chosen so that
the interpolation point x is chosen close to the midpoint of [x0 , x3 ], then the interpolation error is
smaller than if n were chosen anywhere between x0 and x3 . Verify this statement with the data
of Problem #2.
50