QoTCex Lecture2 PDF
QoTCex Lecture2 PDF
MECE 390-A1
Numerical Methods of Mechanical Engineering
Objective
To understand Round-off errors, we need to firs look how computers store numbers
Principle
Integers
All Integers can be exactly represented by using binary system. However, only up to a certain limit.
Limit for n bits is 2𝑛𝑛 − 1. 4-bit integers
25 − 1 = 32 − 1 = 31
The net effect of this is that all computers involving floating point numbers are subjected to
computer-induced errors. Collectively, these errors fall under the umbrella of round-off error.
Machine/computer precision 𝜺𝜺𝒎𝒎 : Minimum relative step that can be represented in Finite
Precision Arithmetic.
Example: if 𝜹𝜹 < 𝜺𝜺𝒎𝒎𝟏𝟏 then 1.0 + 𝜹𝜹 =1.0, : if 𝜹𝜹 < 𝜺𝜺𝒎𝒎𝟎𝟎.𝟏𝟏 then 1.0 + 𝜹𝜹 =1.1
Value of 𝜺𝜺𝒎𝒎 : double precision ~ 10−16
single precision ~ 10−7
Many numerical procedure are approximations that are derived from Tayler series. We often can
use Tayler series to estimate the expected error.
Tayler series expansion
ℎ2 ℎ3 𝑑𝑑𝑑𝑑
𝑓𝑓 𝑥𝑥0 + ℎ = 𝑓𝑓 𝑥𝑥0 + 𝑓𝑓′ 𝑥𝑥0 ℎ + 𝑓𝑓𝑓(𝑥𝑥𝑜𝑜 ) + 𝑓𝑓𝑓(𝑥𝑥𝑜𝑜 ) + ⋯ ,where 𝑓𝑓 𝑥𝑥0 = 𝑑𝑑𝑑𝑑�𝑥𝑥 and ℎ = 𝑥𝑥 − 𝑥𝑥𝑜𝑜 = ∆𝑥𝑥
2! 3! 𝑜𝑜
If we truncate this series after the n derivative term, we can show the source of the error
e.g. n=1: 𝑓𝑓 𝑥𝑥0 + ℎ = 𝑓𝑓 𝑥𝑥0 + 𝑓𝑓′ 𝑥𝑥0 ℎ + truncation error (~𝑂𝑂(ℎ2 ))
′ 𝑥𝑥0
ℎ2 ′
ℎ3
𝑓𝑓 𝑥𝑥0 + ℎ = 𝑓𝑓 𝑥𝑥0 + 𝑓𝑓 ℎ + 𝑓𝑓 𝑥𝑥𝑜𝑜 + 𝑓𝑓𝑓(𝑥𝑥𝑜𝑜 ) + ⋯
3! 3!
Dominant error (~∝ 𝑂𝑂(ℎ2 ))
The largest contributing term in the error is the second
derivatives term.
The corresponding error is proportional to ℎ2 .
Error = 𝑂𝑂(ℎ2 ),
For, n order approximation, the dominant error is : Error = 𝑂𝑂(ℎ𝑛𝑛 )
This mean that reducing can dramatically increase the accuracy of Taylor’s formula.
For example, for the first order approximation, when h is halved the error should go down by
factor 4.
∆𝑥𝑥 ∆𝑥𝑥 1 1
i.e. ℎ = ∆𝑥𝑥 ; thus 𝜀𝜀 𝜀𝜀( )2 = 𝜀𝜀 ,
2 2 2 4
However, in either case, we are increasing the number of operations that must be performed by
the computer and this has the effect of increasing round-off error. Because the total error is the
sum of the round-off and truncation errors, there is trade-off that generally favors step sizes that
are small but not too small.
Total error
Step size Round-off Error Truncation Error
Error
Round-off error
Sept size, h
In general, we do no have the patience to find the exact value of hoptimal. Use instead your
intuitive (Remember, we are smarter than machine! )
Numerical error is a signed quantity defined by the amount that needs to be added to the
numerical or approximate value to be equal to the exact or true value.
Exact Value = Numerical Value + Error
True Value = Approximate Value + Error
2. Relative error
Ture Value – Approximated Value
𝜺𝜺𝒕𝒕 = and used as:
Ture Value
Percent Relative Error: 𝜺𝜺𝒕𝒕 % = 100𝜺𝜺𝑻𝑻
Relative error is preferred for setting a convergence or stopping criterion, because it give the
relative importance of the error.
In engineering problems often 0.1% or 0.01% accuracy is acceptable, but in numerical
calculations it is often easy and advisable to require higher accuracy of the results.
3. Practical difficulties
When true value tends to zero (True value 0), Relative Error tends to infinity (𝜺𝜺𝒕𝒕 ∞ ).
Solution: when calculating the Relative Error, add a very small value to the denominator, to
Ture Value – Approximated Value 𝜹𝜹~10−6 (single precision)
prevent division by zero. 𝜺𝜺𝒕𝒕 =
Ture Value+𝜹𝜹 𝜹𝜹~10−12 (double precision)