Numerical Analysis
Numerical Analysis
Numerical Analysis
1.1 Introduction
Definition 1.2.2 The difference between the exact number a and the approximate
number a∗ is called the error, sometimes denoted by ∆a, that is, ∆a = a − a∗ , where
∆a < 0 for a < a∗ , ∆a > 0 for a > a∗ .
∆ = |a − a∗ | ≤ ∆a
Clearly,
a∗ − ∆a ≤ a ≤ a∗ + ∆a
where (a∗ − ∆a ) is the minor approximation and
(a∗ + ∆a ) is the major approximation of a
Exercise 1.2.1 Determine the limiting absolute error of the approximation number
a = 2.7 to the number e.
Solution 1.2.1
∆ = |e − 2.7| ≤ ∆a
2.7 − ∆a ≤ e ≤ ∆a + 2.7
Since e > 2.7 and e < 2.72, |e − 2.7| < 2.72 − 2.7 = 0.02 ⇒ ∆a = 0.02.
∆
Definition 1.2.4 If a∗ is an approximation to a, then δ = , is called the relative
|a|
error of the approximate number a∗ .
Solution 1.2.2 The limiting absolute error ∆p = 0.001gf and p ≤ 999.847 + 0.001 =
999.848gf .
0.001
δp = · 100 %
999.848
= 10−4 %
3. Initial error - Some errors arise due to the use of approximate numerical pa-
rameters whose values are determined either experimentally or through infinite
processes. When performing computations with machines these errors are carried
into the final data.
f (x) = 0 (1.1)
where f (x) is defined and continuous on some finite or infinite interval a < x < b.
If f (ξ) = 0, then ξ ∈ [a, b] is called a root of the equation.
1. Isolate the roots. This is a procedure to identify the smallest possible interval
[α, β] containing one and only one root of (1.1).
2. improve the values of the approximate roots, that is, refine the roots to the
required degree of accuracy
• identify an interval [α, β] with f (α)f (β) < 0. Thus, [α, β] contains at least one
root of the equation f (x) = 0.
• if f (ξ) = 0, then the root ξ will be unique if f 0 (x) exists and retains the same
sign throughout [a, b]. E.g. f 0 (x) > 0 (or f 0 (x) < 0) for α < ξ < β.
y
6
y = f (x)
f (β)
-
> x
α ξ β
f (α)
a0 xn + a1 xn−1 + . . . + an = 0, (a0 6= 0) ai ∈ R, i = 1, 2 . . . , n
has at most n real roots. n + 1 sign changes on [α, β] assures us of the isolation.
x −∞ -3 -1 0 1 3 +∞
f (x) - - + + - + +
f (x) has three roots in the interval (−3, −1), (0, 1), (1, 3).
0 0 2
√
We√can also make√ use of f (x) = 0, thus, f (x) = 3x − 6 = 0, x = ± 2. √ √ √ √
f ( 2) < 0, f (− 2) > 0, f (∞) > 0, f (−∞) < 0, thus f (x) has roots in (−∞, − 2), (− 2, 2), ( 2, ∞)
f (x) = 0 can be replaced by φ(x) = ψ(x) where φ(x) and ψ(x) are simpler than f (x).
We consider the intersection of φ(x) and ψ(x).
1p
-
ξ
ξ ≈ 0.9
Consider f (x) = 0, where f is continuous on [a, b] and f (a)f (b) < 0, that is, f (a) and
f (b) have opposite signs.
Procedure
and
b−a
bn − an =
2n
that is, if the interval [a, b] is subinterval into two, four, eight, etc, equal subintervals,
b−a b−a b−a
then the length of each subinterval is , 2 , 3 , etc.
2 2 2
Thus for 2n subintervals, the length of each is
b−a
= bn − an
2n
Example 1.3.3 Find the root of f (x) = x4 + 2x3 − x − 1 = 0 in the interval [0,1] using
the bisection method.
n an bn ξn f (ξn )
1 0.0000 1.0000 0.5000 -1.1900
2 0.05000 1.0000 0.7500 -0.5900
3 0.7500 1.0000 0.8750 0.0500
4 0.7500 0.8750 0.8125 -0.3040
5 0.81250 0.8750 0.8438 -0.1350
6 0.8438 0.8750 0.8594 -0.0430
7 0.8594 0.8750 0.8672 -0.0027
8 0.8672 0.8750 0.8711 -0.0267083
Error = |ξ − ξ7 |
≤ |b7 − a7 |
= 0.8750 − 0.8594
= 0.0156
|b7 − a7 |
Absolute error = ≈ 0.0181 = 1.8 × 10−2 .
|a7 |
Exercise 1.3.1 Use the bisection method to find the smallest positive root of x3 − 2x +
1 = 0.
Let f be a differentiable function, that is, the graph of f has a definite slope at each
point and hence a unique tangent.
At point (x0 , f (x0 )) on f , there is a tangent.
f (x)
r
6
(x0 , f (x0 ))
- x
a ξ x1 b = x0
y = `(x)
h2 00
f (x0 + h) = f (x0 ) + hf 0 (x0 ) + f (x0 ) + . . . = 0
2!
.
We can determine h by taking the first two terms.
f (x0 ) + hf 0 (x0 ) = 0
f (x0 )
⇒h = −
f 0 (x0 )
The new approximation to the root will be
x1 = x0 + h
f (x0 )
= x0 − 0
f )x0 )
f (xn )
xn+1 = xn − , n = 0, 1, 2, . . . ,
f 0 (xn )
Exercise 1.3.2 1. Use Newton’s method to find the negative root for x4 − 3x2 +
75x − 10000 = 0 within 10−3 within the interval [-15;-10].
2. Two of the zeros of x4 +2x3 −7x2 +3 are positive. Find them by Newton’s method,
correct to two significant figures.
x 0 4 8 12 16
f (x) 5 7 10 13 17
The technique of finding f (1), f (2), f (7), f (15) etc, is called interpolation, while finding
f (−1), f (17), etc is extrapolation.
• the given function should be either in increasing or decreasing order, without any
sudden jumps.
p(xi ) = yi , 0 ≤ i ≤ n
p(x) = y0 .
Example 1.4.1 Find the polynomial of least degree that interpolates the following ta-
ble.
x 2 5
y 6 18
Solution 1.4.1
18 − 6
p(x) = 6 + (x − 2)
5−2
= 76 + 4(x − 2)
= 4x − 2
To produce one more entry in the table we add another term p4. Assuming p(xi ) =
yi , 0 ≤ i ≤ k. We consider
y2 y3 y4 y5 y6 yn yn+1
y1
-
x
x1 x2 x3 x4 x5 x6 ... xn xn+1
2
P (x) = a0 + a1 x + a2 x + . . . + an xn
Difference tables are another way to write the nth order polynomial that passes through
(n + 1) points of the curve, (xi , f (xi )), i = 0, 1, 2, . . . , n.
where ∆x and ∆y are increments of x and y respectively, is called the first finite
difference of f .
Finite differences of higher order are denoted by
∆n y = ∆(∆n−1 y), n = 1, 2, 3 . . . .
1. ∆(u + v) = ∆u + ∆v.
3. ∆m (∆n y) = ∆m+n y.
Example 1.4.2 Construct the finite difference for the function P (x) = x2 , taking the
interval increment to be ∆x = 1.
Solution 1.4.2
∆n Pn (x) = n!a0 hn
= constant, where h = ∆x
Differences Tables
In general,
n(n−1)
∆n yi = yi+n − nyi+n−1 + 2 yi+n−2 − . . . + (−1)k n Ck y(i+n−k) + . . . + (−1)n yi
x y ∆y ∆2 y ∆3 y ∆4 y
x0 y0
∆y0
x1 y1 ∆2 y0
∆y1 ∆ 3 y0
x2 y2 ∆2 y 1 ∆ 4 y0
∆y2 ∆3 y 1
..
x3 y3 ∆2 y 2 .
..
∆y3 .
.. ..
x4 y4 . .
.. .. .. .. .. ..
. . . . . .
Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + . . .
+ an (x − x0 )(x − x1 ) . . . (x − xn−1 ) (1.2)
Pn (x0 ) = y0 = a0
Pn (x1 ) = y1 = a0 + a(x1 − x0 ) = a0 + a1 h
y1 − y0 ∆y0
⇒ a1 = =
h h
Pn (x2 ) = y2 = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 )
⇒ y2 − y1 − 2(y1 − y0 ) = 2a2 h2
y2 − 2y1 + y0 ∆2 y0
∴ a2 = =
2h2 2h2
..
.
∆n y0
an =
n!hn
Substituting for ai (i = 0, 1, 2, . . . , n) in (1.2),
∆y0 ∆2 y0
Pn (x) = y0 + (x − x0 ) + (x − x0 )(x − x1 ) + . . . +
h 2!h2
n
∆ y0
+ (x − x0 )(x − x1 ) . . . (x − xn−1 ).
n!hn
Example 1.4.3 Construct Newton’s interpolation polynomial on [3.5;3.7] using the
spacing h = 0.05 for f (x) = ex given in the following table.
x y ∆y ∆2 y ∆3 y ∆4 y
3.5 33.115 1.698 0.087 0.005 -0.002
3.55 34.813 1.785 0.092 0.003
3.6 36.598 1.887 0.95
3.65 38.475 1.972
3.7 40.447
1.698 0.087
P4 (x) = 33.115 + (x − 3.5) + (x − 3.5)(x − 3.55)
0.05 2 × 0.052
0.005
+ (x − 3.5)(x − 3.55)(x − 3.6)
6 × 0.053
0.002
− (x − 3.5)(x − 3.55)(x − 3.6)(x − 3.65).
24 × 0.054
Exercise 1.4.1 Construct an empirical formula for the function represented by the
following table.
x 0 1 2 3 4 5
y 5.2 8.0 10.4 12.4 14.0 15.2
y0 y1 y2 y3
- x
x0 x1 x2 x3 xn
As for Newton’s forward difference, the nth degree polynomial may be written as
y0 = a0
y1 − y0 = a1 (x1 − x0 )
y1 − y0
⇒ a1 = , denoted y[x1 , x0 ]
x1 − x0
y2 − y0 − (x2 − x0 )(y1 − y0 )
a2 =
(x2 − x0 )(x2 − x1 )
y[x2 , x1 ] − y[x1 , x0 ]
= denoted y[x2 , x1 , x0 ]
x2 − x0
..
.
ak = y[xk , xk−1 , . . . , x0 ]
y[xk , xk−1 , . . . , x1 ] − y[xk−1 , xk−2 , . . . , x0 ]
=
xk − x0
Lagrange interpolating polynomial is for arbitrarily spaced points. Consider the con-
struction of a polynomial Ln (x) of degree not exceeding n having at specified points
x0 , x1 , . . . , xn the same value as the function y = f (x), that is,
y
6
y = f (x)
y = Ln (x)
- x
x0 x1 xn
For the general case, we need to find a polynomial Ln (x) that satisfies the conditions
Ln (xi ) = yi
Xn
Ln (x) = `i (x)yi
i=0
Thus,
n
X (x − x0 )(x − x1 )(x − x2 ) . . . (x − xi−1 )(x − xi+1 ) . . . (x − xn )
Ln (x) = f (xi )
(xi − x0 )(xi − x1 ) . . . (xi − xi−1 )(xi − xi+1 ) . . . (xi − xn )
i=0
i = 0, 1, 2, . . . , n
Estimate f (324.7).
Solution 1.4.4
3
X x − xj
L3 (x) = f (xi )`i (x) , with `i (x) = Π3j=0,j6=i
xi − xj
i=0
⇒ f (324.7) ≈ 2.52397
x -5 -4 -3 -2 -1 0
f (x) 0.0067379 0.0183156 0.0497871 0.1353353 0.3678794 1
Construct the Lagrange interpolating polynomial of degree 3 and find f (−2.5) and f (2.5)
and compare your value to the exact values.
A spline function is a function that consists of polynomial pieces joined together with
certain smoothness conditions.
A simple example is polygonal function (or spline of degree 1) whose pieces form linear
polynomials joined together for continuity.
pr
s0 prhh. h
.. sn−2
s1 r s2 r s3 s4 hr
h pq
r r
- x
t0 t1 t2 t3 t4 t5 ... tn−1
Properties of S
3. There is a partitioning of the interval a = t0 < t1 < . . . < tn−1 = b such that S
is a linear polynomial on each subinterval [ti , ti−1 ]
Example 1.4.5 Show that G(x) is not a spline function of first degree.
x, x ∈ [−1, 0]
G(x) = 1 − x , x ∈ [0, 1]
2x − 2 , x ∈ [1, 2]
Solution 1.4.5
lim x = lim (1 − x) = 1
x→0+ x→0
lim x = lim x = 0
x→0− x→0
Thus lim G(x) 6= lim G(x)
x→0+ x→0−
Solution 1.4.6
Zi+1 − Zi
Qi (x) = (x − ti )2 + Zi (x − ti ) + yi
2(ti+1 − ti )
where Zi = Q0 (ti )
0.1x2 ,
0≤x≤1
1. S(x) =
9.3x2 − 18.4x + 9.2 , 1 ≤ x ≤ 1.3
x , −∞ < x < 1
2. S(x) = x2 , 1 ≤ x ≤ 2
4, 2 ≤ x ≤ ∞
From (1.5)
f (x) − f (x − h)
f 0 (x) = + ET (h)
h
where
h
ET (h) = − f 00 (c2 )
2
for some c2 ∈ [x − h, x].
2h3 000
f (x + h) − f (x − h) = 2hf 0 (x) + f (x) + . . .
3!
f (x + h) − f (x − h)
⇒ f 0 (x) = + ET (h)
2h
h2 000
where ET (h) = f (c) for some c ∈ [x − h, x + h].
6
Find an approximation to f 0 (1.50) using the two-point forward difference formula with
h = 0.05.
Solution 1.5.1
f (x + h) − f (x)
f 0 (x) =
h
f (1.50 + 0.05) − f (1.50)
⇒ f 0 (1.50) ≈
0.05
f (1.55) − f (1.50)
=
0.05
7.30278 − 6.72253
=
0.05
= 11.6050
Exercise 1.5.1 Use the three point central difference formula with h = 0.1 to estimate
f 0 (1.50) using the table above.
1.5.4 Three Point Formula for First Order Derivative by the Lagrange
Polynomial
where fk = f (xk ).
2x − x1 − x2 2x − x0 − x2 2x − x0 − x1
f 0 (x) = P 0 (x) = 2
f0 + 2
f1 + f2 .
2h h 2h2
h2 00 h3 000 h2 (iv)
f (x + h) = f (x) + hf 0 (x) + f (x) + f (x) + f (x) + . . . (1.6)
2 3! 4!
h2 h3 000 h2 (iv)
f (x − h) = f (x) − hf 0 (x) + f 00 (x) − f (x) + f (x) + . . . (1.7)
2 3! 4!
Adding (1.6) and (1.7) eliminates terms with odd order derivatives
2h2 00 2h4 (iv)
f (x + h) + f (x − h) = 2f (x) + f (x) + f (x) + . . .
2 24
Solving for f 00 (x) yields
f (x + h) − 2f (x) + f (x − h)
f 00 (x) = + ET (f, h) − central difference formula
h2
h2 (iv)
where ET (f, h) = − f (c) where c ∈ [x − h, x + h].
12
Example 1.5.2 Given f (x) = xex , use the central difference formula to approximate
f 00 (0.5) with h = 0.1, 0.01, 0.001. Compare the calculated value with the true value.
Solution 1.5.2
f (x + h) − 2f (x) + f (x − h)
f 00 (x) =
h2
for h = 0.01
f (0.51) − 2f (0.5) + f (0.49)
f 00 (0.5) =
0.0001
≈ 4.121864950
P
Q
y0 y1 y2 yi yi+1 yn−1 yn
M N
- x
a = x0 x1 x2 xi xi+1 xn−1 b = xn
To derive the Trapezoidal rule, divide the area represented by I into a number of thin
strips.
b−a
Let h = , be the interval length, n number of strips.
n
Provided h is small, area due to the ith strip is approximated by area of trapezium
M P QN .
Let xr = a + rh, fr = f (xr ) = yr
Total area under the curve is approximated the sum of areas of the n trapezia, i.e.
h h h
I ≈ (f0 + f1 ) + (f1 + f2 ) + . . . + (fn−1 + fn )
2 2 2
1 1
= h( (f0 + f1 + f2 + . . . + fn−1 + fn )
2 2
Xn
00
= h fr , where ”means first and last term are halved.
r=0
b−a
where h = , x0 = a , xn = b.
n
Assuming y has (n + 1) continuous derivatives in [xk , xk+1 ], k = 0, 1, 2, . . . , n − 1, by
Taylor’s theorem
y(xk+1 ) = y(xk + h)
h2 00 hn (n) h(n+1) (n+1)
= y(xk ) + hy 0 (xk ) + y (xk ) + . . . + y (xk ) + y (ck )
2 n! (n + 1)!
for some ck ∈ [xk , xk+1 ].
For h very small
h2 00 hn (n)
y(xk + h) = y(xk ) + hy 0 (xk ) + 2! y (xk ) + ... + n! y (xk )
Taylor’s formula of order n.
Solution 1.7.1
y 0 = y + y + ex
y 00 = y 0 + ex
= y + 2ex
y 000 = y + 3ex
y (iv) = y + 4ex
The Taylor series order 4 is given by
h2 00 h3 000 h4 iv
yk+1 = yk + hyk0 + y + y k + yk
2! k 3! 4!
h 2 h3 h4
= yk + h(yk + exk ) + (yk + 2exk ) + (yk + 3exk ) + (yk + 4exk )
2 6 24
h2 h3 h4 h2 h3
= 1+h+ + + yk + h 1 + h + + exk
2 6 24 2 6
For h = 1
yk+1 = 2.70833yk + 2.66667exk
with y0 = y(0) = 1
y1 = 2.70833 + 2.66667 = 5.37500
y2 = 14.55727 + 7.24876 = 21.80603
The exact solution of y 0 = y + ex is
y = (1 + x)ex
∴ y1 = 2e2
= 5.43656
|e| = 0.06156
We know that
y 0 (x) = f (x, y(x))
y 0 (xk ) ≈ f (xk , yk )
Thus,
yk+1 = yk + hf (xk , yk ) , k = 0, 1, 2, . . . , n − 1
2xy
Example 1.7.2 Solve y 0 = , y(1) = 2 in [1, 1.3] using Euler’s method with
1 + x2
h = 0.1.
2xy
Solution 1.7.2 f (x, y) = .
1 + x2
Mesh points: x0 = 1, x1 = x0 + h = 1.1, x2 = 1.2, x3 = 1.3
y0 = y(x0 )
= y(1) = 2
y1 = y0 + hf (x0 , y0 )
= 2 + 0.1f (1, 2)
2×1×2
= 2 + 0.1 ×
1 + 12
= 2.2
y2 = y1 + hf (x1 , y1 )
= 2 + 0.1f (1.1, 2.2)
= 2.419
y3 = y2 + f (x2 , y2 )
2 × 1.2 × 2.419
= 2.419 + 0.1 ×
1 + (1.2)2
= 2.65693