Professional Documents
Culture Documents
:
Chapter One
References
John H. Mathews & Kurtis D.
Fink, Numerical Methods Using
MATLAB, 4th edition (2004).
Noha Medhat 2
1
9/11/2022
Course Outline
Introduction to MATLAB (in the lab).
Error Analysis.
Solution of Non-linear Equations.
Solution of Linear Systems.
Interpolation
Curve fitting
Numerical Differentiation and Integration.
Solution of Differential Equations.
Noha Medhat 3
Noha Medhat 4
2
9/11/2022
Noha Medhat 5
Error analysis
Why do we measure errors?
1. To determine the accuracy of numerical results.
2. To develop stopping criteria for iterative algorithms.
Accuracy:
It describes how close an approximation is to a true value.
We describe it using either absolute error or relative error.
Precision:
It describes how many significant digits we use to approximate
a particular value.
It also refers to how closely individual computed values agree
with each other.
Noha Medhat 6
3
9/11/2022
absolute
error
Noha Medhat 7
Example 1
Noha Medhat 8
4
9/11/2022
Example 2
Determine the absolute and relative errors:
• 𝑝 = 3 𝑎𝑛𝑑 𝑝ො = 3.1
𝐸𝑝 = 0.1, 𝑎𝑛𝑑 𝑅𝑝 = 0.0333
This example shows that the same relative error occurs for
widely varying absolute errors.
Noha Medhat 9
Scientific Notation
It is a standard way to present a real number as
𝒑 = 𝒎 × 𝟏𝟎𝒏
Significand/Mantissa Exponent
0.0000747= 𝟕. 𝟒𝟕 × 𝟏𝟎−𝟓
Noha Medhat 10
10
5
9/11/2022
Significant Digits
Significant digits are the digits of a number that are
meaningful in terms of precision. They include:
Noha Medhat 11
11
Non-Significant Digits
Digits of a number are not significant when they do not add
information regarding the precision of that number. They
include:
Noha Medhat 12
12
6
9/11/2022
Sources of errors
Two sources of numerical error:
Round-off error.
Truncation error.
Round-off Error:
A computer’s representation of real numbers is limited to
the fixed number of digits of precision (finite-digit
arithmetic).
1
≈ 0.3333 …
3
2 ≈ 1.4142 …
Noha Medhat 13
13
Or 𝒓 𝒌 = 𝒅𝒌 + 𝟏 𝒊𝒇 𝒅𝒌+𝟏 ≥ 𝟓
14
7
9/11/2022
Chopping method
It is done by discarding a part of the number 𝒅𝒌+𝟏 …
𝒑 = ±𝟎. 𝒅𝟏 𝒅𝟐 𝒅𝟑 … 𝒅𝒌 𝒅𝒌+𝟏 … × 𝟏𝟎𝒏
𝒇𝒍𝒄𝒉𝒐𝒑 𝒑 = ±𝟎. 𝒅𝟏 𝒅𝟐 𝒅𝟑 … 𝒅𝒌 × 𝟏𝟎𝒏
Example 3
𝒑 = 𝟐𝟐Τ𝟕 = 𝟑. 𝟏𝟒𝟐𝟖𝟓𝟕𝟏𝟒𝟐𝟖𝟓𝟕𝟏𝟒𝟐𝟖 ⋯
For six-digit arithmetic representation:
𝒇𝒍𝒓𝒐𝒖𝒏𝒅 𝒑 = 𝟑. 𝟏𝟒𝟐𝟖𝟔
𝒇𝒍𝒄𝒉𝒐𝒑 𝒑 = 𝟑. 𝟏𝟒𝟐𝟖𝟓
Noha Medhat 15
15
Truncation Error:
It is introduced when a complicated mathematical expression
is replaced with Taylor polynomial (series).
Noha Medhat 16
16
8
9/11/2022
𝒙𝟎 𝒙
Noha Medhat 17
17
𝒙𝟑 𝒙𝟓 𝒙𝟕
𝐬𝐢𝐧 𝒙 = 𝒙 − + − +⋯
𝟑! 𝟓! 𝟕!
𝒙𝟐 𝒙𝟒 𝒙𝟔
𝐜𝐨𝐬 𝒙 = 𝟏 − + − + ⋯
𝟐! 𝟒! 𝟔!
Noha Medhat 18
18
9
9/11/2022
Example 4
𝑝 − 𝑝ො
𝑅𝑝 = = 7.03442 × 10−7
𝑝
J. H. Mathews & K. D. Fink, Numerical Methods using MATLAB (4th edition)
Noha Medhat 19
19
Loss of significance
(Subtractive Cancellation)
It occurs when two nearly equal numbers are subtracted to
produce a result much smaller than the original numbers.
Noha Medhat 20
20
10
9/11/2022
Example 5
Compare the results of calculating 𝑓(500) and g(500) using six
digits rounding arithmetic.
Exact value is 11.174755300747198 (g involves less error)
𝒙
𝒇 𝒙 =𝒙 𝒙+𝟏− 𝒙 , g(𝒙) =
( 𝒙 + 𝟏 + 𝒙)
Noha Medhat 21
21
Example 6
Subtraction of nearly
equal numbers :
0.04000 𝒃 ≈ 𝒃𝟐 − 𝟒𝒂𝒄
Noha Medhat 22
22
11
9/11/2022
−0.01611 + 0.02000
≈ 0.2415
−0.01611
For 𝒙𝟐
0.3222 × 𝟏𝟎−𝟑
(b > 0)
Noha Medhat 23
23
0.04000
0.1946
Noha Medhat 24
24
12
9/11/2022
Propagation of Errors
In numerical methods, the calculations are not made with
exact numbers.
ෝ + 𝝐𝒑 + 𝒒
𝒑+𝒒= 𝒑 ෝ + 𝝐𝒒 = 𝒑
ෝ+𝒒
ෝ + 𝝐𝒑 + 𝝐𝒒
ෝ+𝒒
𝒑+𝒒 − 𝒑 ෝ = 𝝐𝒑 + 𝝐𝒒
Noha Medhat 25
25
Propagation of Errors
Multiplication
𝝐𝒑 𝝐𝒒
ෝ /𝒑 ≈ 𝟏, 𝒒
For good approximations: 𝒑 ෝ/𝒒 ≈ 𝟏, and 𝑹𝒑 𝑹𝒒 = ≈𝟎
𝒑 𝒒
Noha Medhat 26
26
13