Sta122 N1-2023
Sta122 N1-2023
Chapter 4: Interpolation 28
4.1 Definition & Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1.3 References
The following reference books will be useful during our course
• deBoor C. R. & Conte S. D. (2017). Elementary Numerical Analysis: An algorithmic approach.
3rd Edition. McGraw-Hill Book Company, New York, USA.
• Hultquist P. F. (). Numerical methods for engineers and computer scientists
• Burden R. L. & Faires J. D. (2011). Numerical Analysis. 9th Edition. Brooks/Cole, Boston,
USA.
• Chapra S. C. & Canale R. P. (2010). Numerical methods for engineers. 6th Edition. McGraw-
Hill Book Company, New York, USA.
• Chapra, S. C. (2012). Applied numerical methods with MATLAB for engineers and scientists.
3rd Edition. McGraw-Hill Book Company, New York, USA.
• Atkinson K., Han W. & Stewart D. (2009). Numerical solution of ordinary differential
equations. John Wiley & Sons, New Jersey, USA.
• Any other online references specific to the topics
Lecturer
Timothy K. K. Kamanu, PhD
Consultation Times
Online + On demand
Evaluation
– Errors – Interpolation
– Accuracy – Polynomials
δfp = f1 − f0
p = 1 − 1/2
∆ and δ
Directed Research
Figure 2.1: Practical problem solving on computers
1
An algorithm is a sequence of steps required to solve a problem.
Timothy K. K. Kamanu, PhD
2
All mathematical models are wrong but all are useful in8identifying general tendency/trend.
Department of Mathematics, University of Nairobi
Figure 2.2: Basic flowchart showing symbols for terminal, input/output, and decision nodes of a program
2.1
ϵx = xT − xA (3.1)
xT − xA ϵx
Rx = = (3.2)
xT xT
Often the true value is not known in advance and therefore xA can be used in the denominator.
3. The percentage error is equivalent to Rx × 100.
xT − xA
Rx % = × 100 (3.3)
xA
xA = 3.14286.
ϵx = xT − xA
= 3.1415926535897932 · · · − 3.14286
= 0.001267346.
π − 22
7
Rx =
π
= 0.0004034088
where the first terms RHS have ready approximations, using say Taylor series approximations2
5. Statistical estimation errors
Mathematical models are devoid of a random component. Statistical error estimation arises from
random variation as well as statistical estimation based on Monte Carlo simulation.
Monte Carlo methods are useful when approximation integrals of known functions f (x)
1
”Elementary functions” any function composed of addition, subtraction, multiplication, division, powers, roots,
logarithms, trigonometric functions, inverse trigonometric functions, hyperbolic functions, and inverse hyperbolic
functions; and their finite expressions R x
2
The above set is not exhaustive: other functions that do not have elementary antiderivatives are: x dx,
RTimothy
p K. K. Kamanu, PhDR R√
2 of Nairobi
R 14 R R
sin(x)dx, sin(x )dx,
Department of Mathematics, University 3
1 + x dx, exp(exp(x))dx, ln(ln(x))dx, sin(sin(x)), etc.
based on uniform random draws but find the best and most useful setting in estimating
integrals of unknown functions such as probability density and distribution functions [see Gibbs
Sampler & Importance Sampling].
6. Blunders or mistakes
Blunders or mistakes often arise in simulation studies and comprise programming errors. Logical
program errors are hard to determine without explicit domain knowledge and/or experience.
Blunders and mistakes can be avoided and detected by
• Test data: testing programs using known true values
• Compartmentalization: breaking the problem into small sub-problems solved using subroutines
(small bits of code) that can be tested separately.
Transcendental numbers e.g. π, e etc., and transcendental functions such as logarithm, hyperbolic,
trigonometric, etc. functions cannot be represented in finite representation in binary as well as decimal
representations.
and if the error is ≤ 5 in the (m + 1)th value of xT , counting from the first non-zero digit, then
xA is said to have, at-least, m significant digits of accuracy relative to xT .
Example 3.5.2. Number of Significant Digits Determine the number of significant digits
in the following
• xT = 1234.567 and xA = 1234.517
xT = 1234.5 67
xA = 1234.5 17
|ϵx | = |xT − xA | = 0000.0 50
xT = 0.0 23 48
xA = 0.0 23 51
|xT − xA | = 0.0 00 0 3
xT = 3.14 159265
xA = 3.14 28571
|xT − xA | = 0. 00 126445
# Significant digits
1
x = 0.76545423 × 10 7
y = 0.76544211 × 101 7
x − y = 0.00001212 × 101 4
Example 3.6.1 illustrates loss of precision which should be avoided whenever possible/necessary.
The propagation of errors under addition and other arithmetic operations can be considered by letting
x : True value of x
x̄ : Approximate value of x
ϵx : Error in x i.e., x − x̄
y : True value of y
ȳ : Approximate value of y
ϵy : Error in x i.e., y − ȳ
Timothy K. K. Kamanu, PhD
Department of Mathematics, University of Nairobi 20
3.6.1 Addition
Propagation of error under addition is sanctioned as
Notes
1. The maximum error taken is
|ϵx + ϵy | ≤ |ϵx | + |ϵy |
ϵx+y = ϵx + ϵy
3.6.2 Substraction
Propagation of error under subtraction is sanctioned as
x − y = (x̄ + ϵx ) − (ȳ + ϵy )
= (x̄ − ȳ) + (ϵx − ϵy )
Notes
1. The error propagated under subtraction is
ϵx−y = ϵx − ϵy
3.6.3 Multiplication
Propagation of error under multiplication is sanctioned as
xy = (x̄ + ϵx )(ȳ + ϵy )
= x̄ȳ + x̄ϵy + ȳϵx + ϵx ϵy
|{z}
2nd order approx.≈0
xy − x̄ȳ ≊ +x̄ϵy + ȳϵx
after neglecting the cross product term (i.e., limiting to calculations first order approximation under
multiplication), it follows that
1. The error propagated under multiplication is
ϵxy = x̄ϵy + ȳϵx
2. The relative error under multiplication is equivalent to the sum of the relative error of the
operands (x and y)
ϵx ϵy
Timothy K. K. Kamanu, PhD Rexy = + = Rex + Rey
Department of Mathematics, University of Nairobi x̄ 21ȳ
3.6.4 Division
Propagation of error under multiplication is sanctioned as
x x̄ + ϵx x̄ + ϵx
= = −1
y ȳ + ϵy
ϵx
ȳ 1 + ȳ
= but if |h| << 1 then (1 + h)−1 = 1 − h + h2 − h3 + · · · , hence
ϵy ϵx 2 ϵx 3
x̄ ϵx
= + 1 − + 2 − 3 + ···
ȳ ȳ ȳ ȳ ȳ
x̄ ϵx x̄ ϵx ϵy
= + − 2− +···
ȳ ȳ ȳ ȳ 2
|{z}
2nd order approx.≈0
x̄ ϵx x̄
≊ + − 2.
ȳ ȳ ȳ
|{z} | {z }
Approx’ Error
That is
x x̄ ȳϵx − x̄ϵy
ϵx/y = − =
y ȳ ȳ 2
ϵx ϵy
Rex/y = − = Rex − Rey
x̄ ȳ
xy
• EXERCISE: Division - Suppose Q = z
and let u = xy, then the error is???
ϵf = f (a) − f (ā)
Example 3.7.1. Find an expression for the error associated with the quantity Q =
(x + 2y) · z 4
Solution
Let u = x + 2y and v = z 4 , then ϵu = ϵx + 2ϵy
Timothy K. K. Kamanu, PhD □
Department of Mathematics, University of Nairobi 23
Timothy K. K. Kamanu, PhD
Department of Mathematics, University of Nairobi 24
Illustration of loss of significant digits during functional evaluation
1e−13
Differences in f(x)
5e−14
0e+00
−5e−14
0 20 40 60 80 100
Values of x
Figure 3.2: Loss of significant digits during calculations as simulated by the algorithm below.
A2. Some functional formulae do not lend themselves for efficient evaluation to reduce ϵf .
Reformulation is necessary inorder to reduced loss of precision following loss-of-significance
error.
Solution It is imperative to find an appropriate computable form to avoid error emanating from
cancellation and loss of significant digits i.e.
√ √ √
√ x+1+ x
true
f (x) = x x+1− x · √ √
x+1+ x
x
= √ √
x+1+ x
As x increases the magnitude of the errors increase and decreases as illustrated below with
x ∈ [1, 100]
As x increases there are fewer digits of accuracy as illustrated in Table 3.7 and Figure ??. The
above results can be recreated using the following code-block
6e−11
4e−11
2e−11
0e+00
Values of x
Figure 3.3: Illustration of the error due to loss-of-significance during functional evaluation.
x = c(1:5,10,100,1000,10000,100000)
15 fx = x * (sqrt(x+1)-sqrt(x));
fx_true = x / (sqrt(x+1) + sqrt(x));
Diff_fx2 = fx_true-fx;
cbind(x,fx,fx_true)
Specify_Decimal(cbind(x,fx,fx_true),20)
20 ## Please comment out pdf() and dev.off() lines hereunder
#pdf("Loss_of_Significant_Digits2.pdf",height = 6,width = 12)
barplot(Diff_fx2,col = rainbow(length(x)),names.arg = x,cex.axis =
1.2,
main="Illustration of loss of significant digits (functional
evaluation)",
xlab = "Values of x",
25 ylab = "Error in function evaluation")
#dev.off();
Interpolation
4.1 Definition & Application
Webster Dictionary
... act of introducing something, especially spurious and foreign ...
... act of calculating values of functions between values already known ...
Example 4.1.1. Taylor series expansion of f (x) about a point x = x0 . If a function f (x) is
continuous and and differentiable between say [a, b] ⊂ R, then the Taylor
series expansion Pn (x) of f (x) about a point x = x0 i.e.,
n
X f k (x0 )
Pn (x) = (x − x0 ) (4.1)
k=0
k!
f ′ (x0 ) f ′′ (x0 ) f (n) (x0 )
= f (x0 ) + (x − x0 ) + (x − x0 )2 + · · · + (x − x0 )n
1! 2! n!
can be regarded as an interpolating polynomial satisfying the following
conditions
• Derivatives satisfy
• a
• b
which is of the form
Pn (x) = a0 + a1 x + a2 x2 + · · · + an xn
Definition 5. Interpolation: problem definition Given the values of a known function y = f (x) at a
sequence of ordered points x0 , x1 , . . . , xn . Find f (x) for arbitrary x between the base points.
Note
• {xi }, i = 0, 1, 2, . . . , n are termed nodes, base points or tabular points
• We assume that f (x) is continuous and differentiable in [x0 , xn ]
• When x0 ≤ x ≤ xn , the problem is termed interpolation
• When x < x0 or x > xn , the problem is termed extrapolation
• Interpolation is more accurate than extrapolation
• If yi = f (xi ), the problem of interpolation involves drawing a smooth curve through the points
(x0 , y0 ), (x1 , y1 ), · · · , (xn , yn ).
• Interpolation is not equivalent to the least-squares curve-fitting problem