You are on page 1of 37

Introduction to Errors

and Approximations

Numerical Methods
MATH160
Numerical Methods

Numerical Methods are techniques used to find approximate


solutions to mathematical problems.
Errors play an important part of the numerical methods as they
determine the validity of the approximate solution. If the
Accuracy vs Precision

Accuracy refers to how closely a


computed or measured value
agrees with the true value.
Precision refers to how closely
individual computed or measured
values agree with each other.
Accuracy vs Precision

Inaccuracy (also called bias) is


defined as systematic deviation
from the truth.
Imprecision (also called uncertainty),
on the other hand, refers to the
magnitude of the scatter.
Error is the collective term used to
represent both the inaccuracy and
imprecision of our predictions.
Error

Numerical errors arise from the use of approximations to represent


exact mathematical operations and quantities. For such errors, the
relationship between the exact, or true, result and the
approximation can be formulated as

True value = Approximation + Error


By rearranging, “

Error = |Approximation - True value|


Error

Error = |Approximation - True value|

The error presented in the equation is called the True Error, 𝜀𝑡 , or


Absolute Error.
𝜺𝒕 = |Approximation − True value|
Relative Error

Relative Error
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥. 𝑣𝑎𝑙𝑢𝑒
𝜀𝑟 =
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒

Percent Relative Error

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥. 𝑣𝑎𝑙𝑢𝑒


%𝜀𝑟 = × 100%
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒
Example

Suppose that you have the task of measuring the lengths of a bridge and a
rivet and come up with 9999 and 9 cm, respectively. If the true values are
10,000 and 10 cm, respectively, the error in both cases is 1 cm.
Bridge Measurement Rivet Measurement
𝜀𝑡 = |Approximation − True value| 𝜀𝑡 = |Approximation − True value|
𝜀𝑡 = |9999cm − 10000cm| 𝜀𝑡 = |9cm − 10cm|
𝜀𝑡 = 1 cm 𝜀𝑡 = 1 cm

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥. 𝑣𝑎𝑙𝑢𝑒 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥. 𝑣𝑎𝑙𝑢𝑒


%𝜀𝑟 = × 100% %𝜀𝑟 = × 100%
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒

10000 − 9999 10 − 9
%𝜀𝑟 = × 100% = 0.01% %𝜀𝑟 = × 100% = 10%
10000 10
Approximate Relative
Error
Approximate Relative Error
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥. −𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝑎𝑝𝑝𝑟𝑜𝑥.
𝜀𝑎 =
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥.

Percent Approximate Relative Error


𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥. −𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝑎𝑝𝑝𝑟𝑜𝑥.
%𝜀𝑎 = × 100%
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥.
Tolerance Error

In numerical methods, we are interested in whether the percent


approximate relative error is lower than a prespecified tolerance
error, 𝜀𝑠 .
We use the criterion,
%𝜀𝑎 < %𝜀𝑠
To see if our approximate result is in assumed to be within the
prespecified acceptable error level.
Round-off Errors
It arises because digital computers cannot represent some
quantities exactly. They are important to engineering and scientific
problem solving because they can lead to erroneous results. There
are two major facets of roundoff errors involved in numerical
calculations:
1. Digital computers have magnitude and precision limits on their
ability to represent numbers.
2. Certain numerical manipulations are highly sensitive to roundoff
errors. This can result from both mathematical considerations as well
as from the way in which computers perform arithmetic operations.
Truncated Errors

Truncation errors are those that result from using an approximation


in place of an exact mathematical procedure.
Taylor’s theorem and its associated formula, the Taylor series, is of
great value in the study of numerical methods. Remember that
Taylor Series is,
𝑦 ′ 𝑥0 𝑦 ′′ 𝑥0
𝑦 = 𝑦 𝑥0 + 𝑥 − 𝑥0 + 𝑥 − 𝑥0 2 +
1! 2!
𝑦 ′′′ 𝑥0 3
𝑦 𝑖𝑣
𝑥0
𝑥 − 𝑥0 + 𝑥 − 𝑥0 4 + ⋯
3! 4!
Approximation of a
Function
Approximate 𝑦 = arctan 𝑥 @ 𝑥0 = 0.2.
When approximating using Taylor series, we use the function 𝑇(𝑥) to
represent 𝑦.

𝑥0 = 0.2

Zero-order approximation uses only the first term of the Taylor


Series:
𝑇0 𝑥 = 𝑦 𝑥0 = arctan 0.2 = 0.197396
Approximation of a
Function
First-Order Approximation uses terms up to the first degree to
approximate 𝑦.
𝑦 ′ 𝑥0
𝑇1 𝑥0 = 𝑦 𝑥0 + 𝑥 − 𝑥0 = 0.197396 + 0.96153(𝑥 − 0.2)
1!

𝑥0 = 0.2
Approximation of a
Function
Second-Order Approximation uses terms up to the 2nd degree to
approximate 𝑦.
𝑦 ′ 𝑥0 𝑦 ′′ 𝑥0
𝑇2 𝑥0 = 𝑦 𝑥0 + 𝑥 − 𝑥0 + 𝑥 − 𝑥0 2
1! 2!
𝑇2 𝑥0 = 0.197396 + 0.96153(𝑥 − 0.2) − 0.18491(𝑥 − 0.2)2

𝑥0 = 0.2
Approximation of a
Function
Third-Order Approximation uses terms up to the 3rd degree to
approximate 𝑦.
𝑦 ′ 𝑥0 𝑦 ′′ 𝑥0 2
𝑦 ′′′
𝑥0 3
𝑇3 𝑥0 = 𝑦 𝑥0 + 𝑥 − 𝑥0 + 𝑥 − 𝑥0 + 𝑥 − 𝑥0
1! 2! 3!
𝑇3 𝑥0 = 0.197396 + 0.96153(𝑥 − 0.2) − 0.18491(𝑥 − 0.2)2 −0.26077 𝑥 − 0.2 3

𝑥0 = 0.2
Approximation of a
Function
As we increase the order of approximations, the better the
approximated curve follows the true curve.
Fourth-Order Approximation Fifth-Order Approximation
𝑇4 𝑥0 = 0.197396 + 0.96153 𝑥 − 0.2 𝑇5 𝑥0 = 0.197396 + 0.96153 𝑥 − 0.2
−0.18491 𝑥 − 0.2 2 − 0.26077 𝑥 − 0.2 3 −0.18491 𝑥 − 0.2 2 − 0.26077 𝑥 − 0.2 3
+0.16412 𝑥 − 0.2 4 +0.16412 𝑥 − 0.2 4 + 0.09994 𝑥 − 0.2 5
Approximation of a
Function
We can also use the Taylor series to approximate values at certain
points of the function.

𝑥0 = 0.2
𝐸

𝑥𝑖 𝑥𝑖+1
= 𝑥0 + ℎ 𝑥𝑖 = 𝑥0 = 0.2
𝑥𝑖+1 = 𝑥0 + ℎ = 0.2 + ℎ
Approximation of a
Function
When approximating the value of a function 𝑦 @ 𝑥 = 𝑥𝑖+1 = 𝑥0 + ℎ,
the relationship below should be used,

𝑦(𝑥𝑖+1 ) = 𝑛𝑡ℎ 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟


𝑛
𝑦 𝑚 𝑥𝑖 𝑚
𝑦(𝑥𝑖+1 ) = ෍ 𝑥𝑖+1 − 𝑥𝑖 + 𝐸𝑟𝑟𝑜𝑟
𝑚!
𝑚=0
𝑛
𝑦 𝑚 𝑥𝑖 𝑚
𝑦(𝑥𝑖+1 ) = ෍ 𝑥0 + ℎ − 𝑥0 + 𝐸𝑟𝑟𝑜𝑟
𝑚!
𝑚=0
Approximation of a
Function
𝑛
𝑦 𝑚 𝑥𝑖 𝑚
𝑦(𝑥𝑖+1 ) = ෍ ℎ + 𝐸𝑟𝑟𝑜𝑟
𝑚!
𝑚=0

𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 𝑦 ′′′ 𝑥
𝑖
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ 2+ ℎ 3
1! 2! 3!
𝑦 𝑖𝑣 𝑥𝑖 𝑛
+⋯+ ℎ + 𝐸𝑟𝑟𝑜𝑟
𝑛!

The error term above is called the Remainder, 𝑅𝑛 of the Taylor


Series
Remainder of the Taylor
Series
The remainder 𝑅𝑛 represents the truncation error of the Taylor
series. It is included to account for all terms from n+1 to infinity:
𝑓 𝑛+1
(𝜉) 𝑛+1
𝑅𝑛 = ℎ = 𝑂(ℎ𝑛+1 )
𝑛+1 !
where the subscript n connotes that this is the remainder for the
nth-order approximation and ξ is a value of x that lies somewhere
between 𝑥0 and 𝑥0 + ℎ. The nomenclature 𝑂(ℎ𝑛+1 ) means that the
truncation error is of the order of ℎ𝑛+1 .
Example

1. Use Taylor series expansions with n = 0 to 3 to approximate


𝜋
𝑓 𝑥 = cos 𝑥 at 𝑥 = on the basis of the value of 𝑓 𝑥 and its
3
𝜋
derivatives at 𝑥0 = .
4
Solution
Steps:
1. Find the value of h.
𝜋 𝜋 𝜋
ℎ = 𝑥𝑖+1 − 𝑥𝑖 = − =
3 4 12
2. Use the series,
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 ′′′ 𝑥
𝑖 3
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + ℎ
1! 2! 3!
𝑦 𝑖𝑣 𝑥𝑖
+⋯+ ℎ 𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑛!
to evaluate the nth order approximations.
Solution
3. Evaluate the zero-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑧𝑒𝑟𝑜 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + 𝐸𝑟𝑟𝑜𝑟
𝜋 𝜋
𝑦 =𝑦 + 𝑂(ℎ0+1 )
3 4
𝜋 𝜋
𝑦 = cos + 𝑂 ℎ0+1 = 0.70710678 + 𝑂(ℎ)
3 4

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒−𝑎𝑝𝑝𝑟𝑜𝑥.𝑣𝑎𝑙𝑢𝑒 𝜋
%𝜀𝑟 = × 100% 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒= cos =0.5
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 3
0.5 − 0.70710678
%𝜀𝑟 = × 100% = 41.42%
0.5
Solution
4. Evaluate the first-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑓𝑖𝑟𝑠𝑡 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + 𝐸𝑟𝑟𝑜𝑟
1!
𝜋
𝜋 𝜋 sin 𝜋
𝑦 = cos − 4 + 𝑂 ℎ2 = 0.52198666 + 𝑂 ℎ2
3 4 1! 12

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒−𝑎𝑝𝑝𝑟𝑜𝑥.𝑣𝑎𝑙𝑢𝑒 𝜋
%𝜀𝑟 = × 100% 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒= cos =0.5
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 3
0.5 − 0.52198666
%𝜀𝑟 = × 100% = 4.40%
0.5
Solution

5. Evaluate the second-order approximation and the percent relative


error.
𝑦 𝑥𝑖+1 = 𝑠𝑒𝑐𝑜𝑛𝑑 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + 𝐸𝑟𝑟𝑜𝑟
1! 2!
𝜋 𝜋
𝜋 𝜋 sin 𝜋 cos 𝜋 2
𝑦 = cos − 4 − 4 + 𝑂 ℎ3 = 0.49775449 + 𝑂 ℎ3
3 4 1! 12 2! 12

0.5 − 0.49775449
%𝜀𝑟 = × 100% = 0.45%
0.5
Solution
6. Evaluate the third-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑡ℎ𝑖𝑟𝑑 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 ′′′
𝑥𝑖 3
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + ℎ + 𝐸𝑟𝑟𝑜𝑟
1! 2! 3!
𝜋 𝜋 𝜋
𝜋 𝜋 sin 𝜋 cos 𝜋 2 sin 𝜋 3
𝑦 = cos − 4 − 4 + 4 + 𝑂 ℎ4
3 4 1! 12 2! 12 3! 12
𝜋
𝑦 = 0.49986915 + 𝑂 ℎ4
3

0.5 − 0.49986915
%𝜀𝑟 = × 100% = 0.03%
0.5
Solution

SUMMARY

n-th order Approximation value Percent Relative Error


approximation
0 0.70710678 41.42%
1 0.52198666 4.40%
2 0.49775449 0.45%
3 0.49986915 0.03%
Example

2. Use the Taylor series to estimate 𝑓 𝑥 = 𝑒 −2𝑥 at 𝑥 = 1 for 𝑥0 =


0.25 . Employ the zero-, first-, second-, third- and fourth-order
versions and compute the percent relative error for each case.
Solution

Steps:
1. Find the value of h.
ℎ = 𝑥𝑖+1 − 𝑥𝑖 = 1 − 0.25 = 0.75
2. Use the series,
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 ′′′
𝑥𝑖 3
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + ℎ
1! 2! 3!
𝑦 𝑖𝑣 𝑥𝑖
+⋯+ ℎ 𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑛!
to evaluate the nth order approximations.
Solution
3. Evaluate the zero-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑧𝑒𝑟𝑜 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + 𝐸𝑟𝑟𝑜𝑟
𝑦 1 = 𝑦 0.25 + 𝑂(ℎ0+1 )
𝑦 1 = 𝑒 −2(0.25) + 𝑂 ℎ0+1 = 0.60653066 + 𝑂(ℎ)

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒−𝑎𝑝𝑝𝑟𝑜𝑥.𝑣𝑎𝑙𝑢𝑒
%𝜀𝑟 = × 100% 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒=𝑒 −2(1) =0.13533528
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒
0.13533528 − 0.60653066
%𝜀𝑟 = × 100% = 348.17%
0.13533528
Solution
4. Evaluate the first-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑓𝑖𝑟𝑠𝑡 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + 𝐸𝑟𝑟𝑜𝑟
1!
−2 0.25
𝑒
𝑦 1 = 𝑒 −2(0.25) − 2 0.75 + 𝑂 ℎ2 = −0.30326533 + 𝑂 ℎ2
1!

𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 − 𝑎𝑝𝑝𝑟𝑜𝑥. 𝑣𝑎𝑙𝑢𝑒


%𝜀𝑟 = × 100% 𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒=𝑒 −2(1) =0.13533528
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒
0.13533528 − (−0.30326533)
%𝜀𝑟 = × 100% = 324.08%
0.13533528
Solution
5. Evaluate the second-order approximation and the percent relative
error.
𝑦 𝑥𝑖+1 = 𝑠𝑒𝑐𝑜𝑛𝑑 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + 𝐸𝑟𝑟𝑜𝑟
1! 2!
𝑒 −2 0.25 𝑒 −2 0.25
𝑦 1 = 𝑒 −2(0.25) − 2 0.75 + 4 0.75 2
+ 𝑂 ℎ3
1! 2!
𝑦 1 = 0.37908166 + 𝑂 ℎ3

0.13533528 − 0.37908166
%𝜀𝑟 = × 100% = 180.11%
0.13533528
Solution
6. Evaluate the third-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑡ℎ𝑖𝑟𝑑 − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 ′′′
𝑥𝑖 3
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + ℎ + 𝐸𝑟𝑟𝑜𝑟
1! 2! 3!
−2 0.25 −2 0.25 −2 0.25
𝑒 𝑒 𝑒
𝑦 1 = 𝑒 −2(0.25) − 2 0.75 + 4 0.75 2−8
0.75 3
+ 𝑂 ℎ4
1! 2! 3!
𝑦 1 = 0.03790817 + 𝑂 ℎ4

0.13533528 − 0.03790817
%𝜀𝑟 = × 100% = 71.99%
0.13533528
Solution
6. Evaluate the fourth-order approximation and the percent relative error.
𝑦 𝑥𝑖+1 = 𝑓𝑜𝑢𝑟𝑡ℎ − 𝑜𝑟𝑑𝑒𝑟 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 + 𝐸𝑟𝑟𝑜𝑟
𝑦 ′ 𝑥𝑖 𝑦 ′′ 𝑥𝑖 2
𝑦 ′′′ 𝑥𝑖 3
𝑦 𝑖𝑣 𝑥𝑖 4
𝑦 𝑥𝑖+1 = 𝑦 𝑥𝑖 + ℎ + ℎ + ℎ + ℎ + 𝐸𝑟𝑟𝑜𝑟
1! 2! 3! 4!
𝑦 1
𝑒 −2 0.25 𝑒 −2 0.25 𝑒 −2 0.25 𝑒 −2 0.25
= 𝑒 −2(0.25) − 2 0.75 + 4 0.75 2−8 0.75 3 + 16 0.75 4 + 𝑂 ℎ4
1! 2! 3! 4!
𝑦 1 = 0.16584823 + 𝑂 ℎ4

0.13533528 − 0.16584823
%𝜀𝑟 = × 100% = 22.55%
0.13533528
Solution
SUMMARY
n-th order Approximation value Percent Relative Error
approximation
0 0.60653066 348.17%
1 -0.30326533 324.08%
2 0.379081662 180.11%
3 0.037908166 71.99%
4 0.165848227 22.55%
5 0.127466209 5.81%
6 0.137061714 1.28%
7 0.135005534 0.24%
END

You might also like