MAT208 Lect Note1
MAT208 Lect Note1
Outline:
Introduction
1.0 Introduction:
Numerical Analysis is the branch of mathematics concerned with obtaining
numerical results for mathematical problems as well as performing operations on
tabulated data, with the operation of arithmetic and following the rules of
algebra.
Solution to problems like 3𝑥2 + 𝑥 − 2 = 0 and may be solved by applying
the rules governing algebra and calculus, where the solution obtained are
numerical values. Similarly, solution to differential equations like ,
Equation of the form 3𝑥5 + 𝑥 − 2 = 0 do not have a general closed form expression,
however, its graph shows that there exist at least one value of in the interval
(0.5, 1) for which the expression equals zero. The question then is, how this value
might be determined.
A. First Differences
The first differences (𝛥𝑓(𝑥) = 𝑓(𝑥 + ℎ) − 𝑓(𝑥)) of the function 𝑓(𝑥) is derived
as follows (note that subscripts represents the order of 𝑥 − values as well as
𝑓(𝑥) −values and 𝑓(𝑥𝑖 ) = 𝑓𝑖 .
𝛥𝑓(𝑥0 ) = 𝑓(𝑥0 + ℎ) − 𝑓(𝑥0 ) = 𝑓(𝑥1 ) − 𝑓(𝑥0 ) = 𝑓1 − 𝑓0
𝛥𝑓(𝑥1 ) = 𝑓(𝑥1 + ℎ) − 𝑓(𝑥1 ) = 𝑓(𝑥2 ) − 𝑓(𝑥1 ) = 𝑓2 − 𝑓1
⋮
𝛥𝑓(𝑥𝑖 ) = 𝑓(𝑥𝑖 + ℎ) − 𝑓(𝑥𝑖 ) = 𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 ) = 𝑓𝑖+1 − 𝑓
Thus, we have that
Example: Consider the function tabulated below, the first and second columns
represents 𝑥 and 𝑓(𝑥) respectively, while the third column represents the first
differences (written inline between preceding rows).
𝑓(𝑥) Δ𝑓
0.0 0.000
0.203
0.2 0.203
0.220
0.4 0.423
0.261
0.6 0.684
0.346
0.8 1.030
0.527
1.0 1.557
1.2 2.572 1.015
The second differences are obtained as the difference of the first differences,
illustrated below.
Δ2𝑓0 = Δ(Δ𝑓0) = Δ(𝑓1 − 𝑓0)
= Δ𝑓1 − Δ𝑓0
= 𝑓2 − 𝑓1 − (𝑓1 − 𝑓0)
= 𝑓2 − 2𝑓1 + 𝑓0
Similarly,
Δ2𝑓1 = 𝑓3 − 2𝑓2 + 𝑓1.
Below is the standard tabular format for displaying forward finite differences
𝛥𝑓 𝛥2 𝑓 𝛥3 𝑓 𝛥4 𝑓
𝑥0 𝑓0
𝛥𝑓0
𝑥1 𝑓1 𝛥2 𝑓0
𝛥𝑓1 𝛥3 𝑓0
𝑥2 𝑓2 𝛥 𝑓1
2
𝛥4 𝑓0
𝛥𝑓2 𝛥 𝑓1
3
𝑥3 𝑓3 𝛥2 𝑓2
𝑥4 𝑓4 𝛥𝑓3
When 𝑓(𝑥) behaves like a polynomial, the number of data in the table has special
properties.
Example:
0 1 2 3 4 5 6
0 1 8 27 64 125 216
Build a forward difference table for this function.
Solution:
𝑥 𝑓 Δ𝑓 Δ2 𝑓 Δ3 𝑓 Δ4 𝑓
0 0
1
1 1 6
7 6
2 8 12 0
19 6
3 27 18 0
37 6
4 64 24 0
61 6
5 125 30
91
6 216
Observe that the difference became a constant value at the third difference,
thus fourth and higher differences are zero.
This implies that for a degree polynomial, the 𝑛𝑡ℎ difference will constant while
the (𝑛 + 1)𝑡ℎ and higher differences will be zeros.
0
0
0 0
0 𝑒
0 𝑒
𝑒 −4𝑒
𝑒 −3𝑒
−2𝑒 6𝑒
−𝑒 3𝑒
𝑒 −4𝑒
0 𝑒
0 𝑒
0 0
0 0
0 0
0
0
10
The effect of the error spreads fanwise, it also increases in magnitude as the
order of the differences increase. In the column of the differences, the
coefficients of corresponds to the coefficients in the binomial expansion of
(1 − 𝑒)𝑛 , thus the error can be located in the reverse direction and corrected.
Example:
The 2nd differences in the table above are equal except for 3-terms. Also, the 3rd
differences are all zeros with the exception of a group of four terms. The
conclusion is that the tabulated data behaves like a polynomial of degree 2.
The error propagates symmetrically through the table, thus the error is traced
back to the entry of 𝑓(𝑥) at 𝑥 = 7.
The entry in the 4th difference is 2 times the set 1, −4, 6, −4, 1 and this implies
that 𝑓(7) is in error by 2.
Hence,
Hence,
Remark:
The choice of 𝑥0 shall be stated in a given problem, with which the backward
difference table can be constructed, this is illustrated below.
𝑥 𝑓(𝑥) ∇𝑓 ∇2 𝑓 ∇3 𝑓 ∇4 𝑓
𝑥−2 𝑓−2
∇𝑓−2
𝑥−1 𝑓−1 ∇2 𝑓−2
∇𝑓−1 ∇3 𝑓−2
2
𝑥0 𝑓0 ∇ 𝑓−1 ∇4 𝑓−2
3
∇𝑓0 ∇ 𝑓−1
𝑥1 𝑓1 ∇2 𝑓0
∇𝑓1
𝑥2 𝑓2
Example:
The function (𝑥) = 𝑒−𝑥 is evaluated between 1.00 ≤ 𝑥 ≤ 2.00 and tabulated below.
Find 𝑒−1.9 using the NGB polynomial of degree 4, choosing 𝑥0 = 2.00
Solution:
Therefore,
Thus, we have that 𝑓(1.9) = 𝑒 −1.9 ≈ 𝑃4 (1.9) = 0.1496.
Comparing the result from NGB technique and the exact value of 𝑒−1.9 = 0.1496
This implies that NGB polynomial of degree 4 estimated this function accurately
to 4 decimal places.
Example:
The function 𝑓(𝑥) = 𝑒 −𝑥 is evaluated on the interval 1.00 ≤ 𝑥 ≤ 2.00 and tabulated
below.
𝑥 1.00 1.25 1.50 1.75 2.00
𝑓(𝑥) 0.3679 0.2865 0.2231 0.1738 0.1353
Solution:
Example:
The function 𝑓(𝑥) = 𝑒 −𝑥 is evaluated on the interval 1.00 ≤ 𝑥 ≤ 2.00 and tabulated
below.
𝑥 1.00 1.25 1.50 1.75 2.00
𝑓(𝑥) 0.3679 0.2865 0.2231 0.1738 0.1353
Solution:
Clearly, NGF, NGB, GF and GB gave results that are accurate up to 4 decimal
places, when the results are compared with the exact value of 𝑒 −1.9 which is
0.1496 (to 4 decimal places).
𝐿𝑖 (𝑥) is defined as
𝑛
(𝑥 − 𝑥𝑗 )
𝐿𝑖 (𝑥) = ∏ , 𝑖≠𝑗
(𝑥𝑖 − 𝑥𝑗 )
𝑗=0
That is
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑖−1 )(𝑥 − 𝑥𝑖+1 ) … (𝑥 − 𝑥𝑛 )
𝐿𝑖 (𝑥) = (10)
(𝑥𝑖 − 𝑥0 )(𝑥𝑖 − 𝑥1 ) … (𝑥𝑖 − 𝑥𝑖−1 )(𝑥𝑖 − 𝑥𝑖+1 ) … (𝑥𝑖 − 𝑥𝑛 )
Example:
Write down the polynomial, which passes through (1, 5), (1.5, −3) and (3, 0).
Solution:
With the 3 given points (𝑥, 𝑦) = (1, 5), (1.5, −3) and (3, 0), we employ a polynomial
of degree 2. Thus
2
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) (𝑥 − 1.5)(𝑥 − 3)
𝐿0 (𝑥) = = = 𝑥 2 − 4.5𝑥 + 4.5
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) (1 − 1.5)(1 − 3)
(𝑥 − 𝑥0 )(𝑥 − 𝑥2 ) (𝑥 − 1)(𝑥 − 3) 4
𝐿1 (𝑥) = = = − (𝑥 2 − 4𝑥 + 3)
(𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 ) (1.5 − 1)(1.5 − 3) 3
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) (𝑥 − 1)(𝑥 − 1.5) 1 2
𝐿0 (𝑥) = = = 𝑥 − 2.5𝑥 + 1.5
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 ) (3 − 1)(3 − 1.5) 3
Therefore,
4 1
𝑃2 (𝑥) = (𝑥 2 − 4.5𝑥 + 4.5)(5) + − (𝑥 2 − 4𝑥 + 3)(−3) + ( 𝑥 2 − 2.5𝑥 + 1.5)(0)
3 3
⇒ 𝑃2 (𝑥) = 9𝑥 2 − 38.5𝑥 + 34.5
Example:
Below is the tabulated values of 𝑦 = ln(𝑥) for 𝑥 = 1.0, 1.1 and 1.3,
𝑥 1.0 1.1 1.3
𝑦 0.0000 0.0953 0.2624
From the values, compute ln(1.2)
Solution:
Therefore,
1 1
𝑃2 (1.2) = − (0.0000) + 1(0.0953) + (0.2624) = 0.1828
3 3
Hence, using Lagrange interpolation formula, we estimated the value of ln(1.2) to
be 0.1828. This differs from the exact value of ln(1.2) with −0.0005, that is, the
estimate is in error by −0.0005,
This method is employed if the given data set is linear, and the approach minimizes
the sum of squares of expected computation errors.
The method determines the values of 𝑎 and 𝑏 of 𝑦(𝑥) = 𝑎𝑥 + 𝑏 subject to the
condition that the sum of square of the error(s) is minimum.
Example:
Approximate by least squares method, a curve that fits the following data for
𝑦(𝑥), hence find 𝑦(7) to the nearest whole number.
𝒙 3 4 6 8 9
𝒚 2 5 7 9 10
Solution:
A curve that fits this data using least squares method requires that we solve for
𝑎 and 𝑏 in 𝑦(𝑥) = 𝑎𝑥 + 𝑏, where 𝑁 = 5. Thus, we have
𝒙 𝒚 𝒙𝒚 𝒙𝟐
3 2 6 9
4 5 20 16
6 7 42 36
8 9 72 64
9 10 90 81
2
∑𝑥𝑖 = 30 ∑𝑦𝑖 = 33 ∑𝑥𝑖 𝑦𝑖 = 230 ∑𝑥 = 206
Therefore,
𝑁∑𝑥𝑖 𝑦𝑖 − (∑𝑥𝑖 )(∑𝑦𝑖 ) 5(230) − (30)(33) 1150 − 990 160 16
𝑎= = = = =
𝑁 ∑ 𝑥𝑖2 − (∑𝑥𝑖 )2 5(206) − (30)2 1030 − 900 130 13
and
(∑𝑦𝑖 )(∑ 𝑥𝑖2 ) − (∑𝑥𝑖 )(∑𝑥𝑖 𝑦𝑖 ) (33)(206) − (30)(230) 6798 − 6900 102 51
𝑏= 2 2
= 2
= =− =−
𝑁 ∑ 𝑥𝑖 − (∑𝑥𝑖 ) 5(206) − (30) 1030 − 900 130 65
In this chapter, we study the technique that allow us to compute the derivative
of functions from tabulated data, using previous definitions of interpolating
polynomials.
The derivative of a function at a point, say 𝑥0 , is estimated from the slope of the
interpolation polynomial, provided the function is suitably approximated.
Since 𝑓(𝑥) = 𝑃𝑛 (𝑥) + 𝑒𝑟𝑟𝑜𝑟 , the derivative 𝑓 ′ (𝑥0 ) of a function 𝑓(𝑥) from a
tabulated data is computed as
1 1 1 1
𝑓 ′ (𝑥0 ) ≈ (Δ𝑓0 − Δ2 𝑓0 + Δ3 𝑓0 − + − + ⋯ ± Δ𝑛 𝑓0 ) (11)
ℎ 2 3 𝑛
Example:
Solution:
1 1
𝑓 ′ (1.7) ≈ (1.212 − (0.268)) = 5.390
0.2 2
(ii) Using 4 terms of the formula (equation (11)), we have that
1 1 1 1
𝑓 ′ (𝑥0 ) ≈ (Δ𝑓0 − Δ2 𝑓0 + Δ3 𝑓0 − Δ4 𝑓0 )
ℎ 2 3 4
That is,
1 1 1 1
𝑓 ′ (1.7) ≈ (1.212 − (0.268) + (0.060) − (0.012)) = 5.475
0.2 2 3 4
Remark: The table for this example is for the function 𝑓(𝑥) = 𝑒 𝑥 , the derivative
of this function remain itself, thus the derivative of the function at 𝑥 = 1.7 is
5.474.
The result obtained from the 4 term truncation is more accurate than the two
term variant.
The definite integral of some function of interest may be obtained from the
tabulated data values of such function.
𝑦
𝑓(𝑥)
𝑎 = 𝑥0 𝑥1 𝑥2 … 𝑥𝑛−1 𝑥𝑛 = 𝑏 𝑥
Figure 1: The graph of 𝑓(𝑥), indicating data points 𝑥𝑖 ′𝑠
𝑏
From the diagram above, ∫𝑎 𝑓(𝑥)𝑑𝑥 is evaluated by dividing the entire interval
[𝑎, 𝑏] into 𝑛 equal subintervals, and the integral becomes a weighted sum of the
𝑏−𝑎
area under the curve, with step size ℎ taken to be ℎ = 𝑛 .
Note: 𝑛 is 1 less than the total number of points 𝑥0 to 𝑥𝑛 presented in the table.
Example:
Using Trapezoidal rule, approximate the integral of the function 𝑓(𝑥) tabulated
on the interval 2.0 to 3.0 as presented below
𝑥 2.0 2.2 2.4 2.6 2.8 3.0
𝑓(𝑥) 7.389 9.025 11.023 13.646 16.445 20.086
Solution:
𝟏
2.2.2 Simpson’s Rule of Integration
𝟑
Example:
Solution:
1
Simpson’s rule is given defined as
3
𝑏
ℎ
∫ 𝑓(𝑥)𝑑𝑥 = (𝑓 + 4𝑓2 + 2𝑓3 + 4𝑓4 + 2𝑓5 + ⋯ + 2𝑓𝑛−2 + 4𝑓𝑛−1 + 𝑓𝑛 )
𝑎 3 1
𝟑
2.2.3 Simpson’s Rule of Integration
𝟖
3
The Simpson’s 8 rule is expressed as
𝑏
3ℎ
∫ 𝑓(𝑥)𝑑𝑥 = (𝑓 + 3𝑓2 + 3𝑓3 + 2𝑓4 + 3𝑓5 + 3𝑓6 + 2𝑓7 + ⋯ + 3𝑓𝑛−2 + 3𝑓𝑛−1 + 𝑓𝑛 )
𝑎 8 1
Example:
3
Apply Simpson’s rule in computing the integral of a function 𝑓(𝑥) tabulated on
8
an interval as presented thus
𝒙 0.000 0.125 0.250 0.375 0.500 0.625 0.750
𝒇(𝒙) 1.0000 0.9998 0.9961 0.9801 0.9412 0.8676 0.7596
Solution:
3
Simpson’s rule is given defined as
8
𝑏
3ℎ
∫ 𝑓(𝑥)𝑑𝑥 = (𝑓 + 3𝑓2 + 3𝑓3 + 2𝑓4 + 3𝑓5 + 3𝑓6 + 2𝑓7 + ⋯ + 3𝑓𝑛−2 + 3𝑓𝑛−1 + 𝑓𝑛 )
𝑎 8 1
Example:
Find the roots of 𝑥 4 − 𝑥 = 10 that lies near 2 (to 4 decimal places), using Newton
Raphson method.
Solution:
𝑥 4 − 𝑥 = 10 ⇒ 𝑥 4 − 𝑥 − 10 = 0
that is, 𝑓(𝑥) = 𝑥 4 − 𝑥 − 10 and 𝑓 ′ (𝑥) = 4𝑥 3 − 1
The Bisection Method of finding a root of a function 𝑓(𝑥) is based upon the Mean
Value Theorem.
The iteration method starts with an initial guess of two points, say 𝑎 and 𝑏. Then
we check for the condition that 𝑓(𝑎) and 𝑓(𝑏) have different signs (that we check
if 𝑓(𝑎)𝑓(𝑏) < 0).
If 𝑓(𝑎)𝑓(𝑏) > 0, we proceed to guess another point 𝑐, until the condition that the
function 𝑓 at any two of these points have different signs, is satisfied.
The average of any two such points 𝑎, 𝑏 or 𝑐, is then considered for the next
bisection check.
Example:
Find the real roots of the equation 𝑓(𝑥) = 𝑥 3 − 3𝑥 − 3, that lies near 2 (to 2
decimal places), using the Bisection Method
Solution:
Suppose 𝑥1 = 2
𝑓(𝑥1 ) = 𝑓(2) = 23 − 3(2) − 3 = −1
We then 𝑓(𝑥) check for 𝑥 = 1
⇒ 𝑓(1) = 13 − 3(1) − 3 = −5
Clearly, 𝑓(2) and 𝑓(1) have the same signs and 𝑓(2)𝑓(1) > 0, so a root of 𝑓(𝑥)
cannot lie between 2 and 1.
Let 𝑥 = 3,
⇒ 𝑓(3) = 33 − 3(3) − 3 = 15
Since , 𝑓(2) and 𝑓(3) have different signs and 𝑓(2)𝑓(3) < 0, then there exist a
root of 𝑓(𝑥) that lies between 2 and 3.
Given an equation 𝑓(𝑥) = 0, we can approximate a root of the function via fixed
point iteration following the steps listed below
i. Find initial values 𝑎 and 𝑏 such that 𝑓(𝑎) and 𝑓(𝑏) have different signs, then,
take
𝑎+𝑏
𝑥0 =
2
ii. Transform the given function to become 𝑔(𝑥), such that |𝑔′ (𝑥0 )| < 1. This
guarantees convergence of the expression.
iii. Apply successive iteration to get approximate root, in the form
𝑥𝑛 = 𝑔(𝑥𝑛−1 ), 𝑛 = 1, 2, 3, …
Example:
Solution:
Let 𝑓(𝑥) = 2𝑥 3 − 2𝑥 − 5
b. 2𝑥 3 − 2𝑥 − 5 = 0
2𝑥 3 = 2𝑥 + 5
1 1
2𝑥 + 5 3 2𝑥 + 5 3
𝑥=( ) ⇒ 𝑔(𝑥) = ( )
2 2
Thus,
2 2
1 1 1
𝑔′(𝑥) = (2𝑥 + 5)−3 and 𝑔′ (𝑥) = (2(1.5) + 5)−3 = that is |𝑔′ (𝑥0 )| < 1
3 3 12
1
2𝑥+5 3
iii. Using 𝑔(𝑥) = ( 2 ), we have that 𝑥0 = 1.5 and
1
2𝑥𝑛−1 + 5 3
𝑥𝑛 = ( )
2
when 𝑛 = 1
1 1
2𝑥0 + 5 3 2(1.5) + 5 3
𝑥1 = ( ) =( ) = 1.5874
2 2
when 𝑛 = 2
1 1
2𝑥1 + 5 3 2(1.5874) + 5 3
𝑥2 = ( ) =( ) = 1.5989
2 2
when 𝑛 = 3
1 1
2𝑥2 + 5 3 2(1.5989) + 5 3
𝑥3 = ( ) =( ) = 1.6003
2 2
when 𝑛 = 4
1 1
2𝑥3 + 5 3 2(1.6004) + 5 3
𝑥4 = ( ) =( ) = 1.6005
2 2
when 𝑛 = 5
1 1
2𝑥4 + 5 3 2(1.6005) + 5 3
𝑥5 = ( ) =( ) = 1.6006
2 2
when 𝑛 = 6
1 1
2𝑥5 + 5 3 2(1.6006) + 5 3
𝑥6 = ( ) =( ) = 1.6006
2 2
From the values of 𝑥3 through 𝑥6 , it is observed that the iteration converges to
1.6006, hence a root of 2𝑥 3 − 2𝑥 − 5 = 0 is 1.6006 (to 4 decimal place).
Appendices:
𝑥𝑖 = 𝑥0 + 𝑖ℎ and 𝑥𝑖+𝑗 = 𝑥𝑖 + 𝑗ℎ
1. Shift Operator
𝐸𝑓(𝑥) = 𝑓(𝑥 + ℎ) or 𝐸𝑓𝑖 = 𝑓𝑖+1 , and 𝐸 𝑛 𝑓𝑖 = 𝑓𝑖+𝑛 ∀ 𝑛
Δ = 𝐸 − 1.
To show that these operators are linear, we adopts the definition of linearity
a. Linearity of 𝐸
Let 𝑓(𝑥) and 𝑔(𝑥) be any two functions, then
c. Linearity of ∇
Let 𝑓(𝑥) and 𝑔(𝑥) be any two functions, then
Appendix 4: Exercise
Solution:
Therefore,