Week 2 M1Lessons 2-3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Module 1

Numerical Methods:
Introduction, Discrete
Algebra, Accuracy, Errors
M1: Numerical Methods: Introduction,
Discrete Algebra, Accuracy, Errors

L2&3: APPROXIMATIONS and


ROUND-OFF ERRORS,
ACCURACY AND PRECISION
Learning Outcomes
• Discuss the rules of Significant Figures.
• Discuss the rules of rounding and
truncating/chopping
• Convert number from one number system to
the other and vice versa
• Explain the difference between accuracy and
precision
• Compute relative errors of a numerical
calculation
Learning Outcomes
• Discuss types of number representation
• Compute Machine epsilon of a number system
• Perform arithmetic operation of computer
number system
Why do we have significant figures on our number?

The power of our measuring instrument is limited.

Numerical values from a measurement are inexact.

The precision of measurement is expressed using


SIGNIFICANT FIGURES.
Rules of Significant Figures
1. Nonzero integers ALWAYS count as significant figures.

2. LEADING ZEROS that comes before all of the nonzero digits are not
significant.

3. CAPTIVE ZEROS that fall between nonzero digits are count is


significant figures.
Rules of Significant Figures
4. TRAILING ZEROS that are at the right end of the number are
significant only if the number is in decimal form.

5. Exact numbers such as those determined by COUNTING and


DEFINITION. and also the CONSTANTS have infinite significant figures.

6. When a number is in scientific notation, all the digits in the mantissa


are significant.
Rules of rounding and truncating/chopping
1. RETAIN the number if the digit next to the “digit of interest” is less than
5.

2. ROUND UP the number if the digit next to the “digit of interest” is


greater than 5.
Rules of rounding and truncating/chopping
3. Given that the next digit of the “digit of interest” is 5; ROUND UP the
number if “digit of interest” is ODD, RETAIN the number if “digit of
interest” is EVEN.

4. In truncating/chopping a number, RETAIN all digits of the number


before the “digit of interest”.
before converting number system from one form to the
other, let’s know about the two number systems…
1. Decimal number system 2. Binary number system
Converting decimal number to binary number
1. For integers: Divide repeatedly by 2 and use the remainders in reverse
order as the successive base-2 values.
Converting decimal number to binary number
2. For decimal fractions: Multiply repeatedly by 2 and use the integer
parts as the successive base-2 values.
Converting binary number to decimal number
1. For integer numbers 2. For decimal numbers
Accuracy and Precision
ACCURACY refers to how closely a computer or measured value agrees with
the true value.

PRECISION refers to how closely individual computed or measured values


agree with each other.

INACCURACY also called bias, is defined as systematic deviation from the


truth

IMPRECISION also called uncertainty, refers to the magnitude of the scatter.


Accuracy and Precision
Letter d is precisely accurate

Letter c is precise but inaccurate

Letter b is accurate but imprecise

Letter a is inaccurate and imprecise


From lesson 1, we know that numerical methods
yield approximate results that are close the exact
analytical solution.

How confidence we are in our approximate result?

How much error is present in our calculation?

Is this calculated error tolerable?


Error Definitions
Case 1: If the true value will be known from a problem that can be solved
ANALYTICALLY
True Error:
𝐸𝑡 = True Value − Approximation (+/−)

True Percentage Relative Error:


True value − Approximation
𝜀𝑡 = × 100%
True value
Note: A negative value indicates that the approximation is above the true value,
otherwise, for a positive value, it is below the true value.
Error Definitions
Sample problem for Case 1: The parachutist problem from Lesson 1
Tabulated Result between Analytical and Numerical Result:
ANALYTICAL NUMERICAL Solve the true error and relative error
Error Definitions
Sample problem for Case 1: The parachutist problem from Lesson 1
Tabulated Result with error analysis:

True
SI. Analytical Numerical True Error Percentage
Relative Error
0 0 0 0 0.00
2 16.4 19.6 3.2 19.51
4 27.77 32 4.23 15.23
6 35.64 39.85 4.21 11.81
8 41.1 44.82 3.72 9.05
10 44.87 47.97 3.1 6.91
12 47.49 49.96 2.47 5.20
14 53.39 53.39 0 0.00
Error Definitions
Sample problem for Case 1: The parachutist problem from Lesson 1
One way of reducing error is by lowering the step increment
𝒄
𝒗 𝒕𝒊+𝟏 = 𝒗 𝒕𝒊 + [𝒈 − 𝒗 𝒕𝒊 ](𝒕𝒊+𝟏 − 𝒕𝒊 )
𝒎
True
SI. Analytical Numerical True Error Percentage
Relative Error
0 0.000 0.000 0.000 0.00
0.1 0.972 0.980 0.008 0.82
0.2 1.926 1.942 0.016 0.81
0.3 2.863 2.886 0.023 0.80
0.4 3.783 3.813 0.030 0.79
0.5 4.687 4.723 0.037 0.78
0.6 5.573 5.617 0.043 0.78
0.7 6.444 6.494 0.049 0.77
In case 1, we can define the true error since both
numerical and analytical results are available for
each point. How about for those approximate
functions? How can we define the approximate
error without knowing the analytical result for
every point on the approximate function?
Error Definitions
Case 2: In real world applications, we usually don’t know the answer a priori.
We don’t know the true value due to the absence of analytical result.
Approximate Error:
𝐸𝑎 = Current approximation − Previous Approximation (+/−)

Approximate Percentage Relative Error:


Cur. Approx. −Prev. Approx.
𝜀𝑎 = × 100%
Cur. Approx.

Note: A negative value indicates that the previous approximation is above the current
approximation, otherwise, for a positive value, it is below the current approximation.
Error Definitions
Case 2: In real world applications, we usually don’t know the answer a priori.
We don’t know the true value due to the absence of analytical result.
Iterative approaches in calculating numerical problems apply this case
examples are: Newton’s Method, Taylor Series and etc.
The computation of these approaches are repeated until stopping criteria is
achieved
𝜺𝒂 < 𝜺 𝒔 Pre-specified % tolerance (Use absolute value)

Value of 𝜺𝒔 using Scarborough formula (Scarborough 1966):

𝜺𝒔 = 𝟎. 𝟓 × 𝟏𝟎𝟐−𝒏 % the result is valid up to n


significant figures
Error Definitions
Sample problem for Case 2: The Maclaurin Series Expansion for
approximating exponential function.

Determine the number of terms needed for the Maclaurin Series to


approximate the function y = ex at x = 0.5 and conforming the
error criterion 𝜺𝒔 to 3 significant figures.
Error Definitions
Sample problem for Case 2: The Maclaurin Series Expansion for
approximating exponential function.
1. Solving the error criterion 𝜺𝒔 with n = 3.
Error Definitions
2. Calculate the approximate relative error until it falls below the error criterion
Cur. Approx. −Prev. Approx.
𝜀𝑎 = × 100%
Cur. Approx.

True answer is e0.5 = 1.648721…


Round off and Chopping Errors
Numbers such as 2, 𝜋, and e cannot be expressed by a fixed number of
significant figures. Therefore, they cannot be represented exactly by a computer
which has a fixed word-length.

Discrepancy introduced by the omission of significant figures is called round off


or chopping errors.
If 𝜋 is to be stored on the base-10 system carrying 7 significant digits,
1. chopping
2. round-off
let’s discuss how numbers are stored/represented in a
computer…
The Integer Representation
The signed magnitude method is used to represent an integer. It utilizes the
first bit of a word to indicate the sign, with a 0 for positive and a 1 for negative.
The remaining bits are used to store the number.
1. The integer value of -173 would be stored on a 16-bit computer

2. The integer value of 45 would be stored on an 8-bit computer


The Integer Representation
3. Determine the range of integers in base-10 that can be represented
on a 16-bit computer.
Max Positive Value 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Zero 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Max Negative Value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


The Floating-Point Representation
It is used to represent fractional quantities. In this method, the decimal number
is expressed as a fractional part, called a mantissa or significand, and an
integer part, called an exponent or characteristic.
𝒆 Computer Representation
𝒎 ∙𝒃
exponent
mantissa base
Ex. Convert 156.78 into floating-point decimal
number

Note: Mantissa should be always normalized.


The Floating-Point Representation
Sample problem: Represent 0.0005 as a floating-point number on a machine that
uses 7-bit word. Employ first digit for the sign of number, the next three digits for the
sign and magnitude of the exponent, and remaining digits for the magnitude of the
mantissa.
2. Computer Representation
1. Find the equivalent floating-point
decimal number representation

Note: Mantissa should be always normalized.


The Machine Epsilon
The computer representation of decimal number system utilizes rounding and
chopping in order to meet the capacity (no of bits in a word) of the machine. To
determine the effects of these errors, machine epsilon is utilized.

𝚬= 𝒃 𝟏−𝒕
number of
number significant digits in
base mantissa
The Machine Epsilon
Sample problem: Determine the machine epsilon of a machine that uses 7-bit
word. Employ first digit for the sign of number, the next three digits for the sign and
magnitude of the exponent, and remaining digits for the magnitude of the mantissa.
1. Determine the number of significant digits in the mantissa.

2. Solve for the Machine Epsilon E


finally, let’s perform arithmetic operations on
computer number system…
1. Adding floating-point numbers
When two floating-point numbers are added, the mantissa of the number with the
smaller exponent is modified so that the exponents are the same.

Add 𝟎. 𝟏𝟓𝟓𝟕 ∙ 𝟏𝟎𝟏 and 𝟎. 𝟒𝟑𝟖𝟏 ∙ 𝟏𝟎−𝟏

Note: The mantissa of the final answer should be always normalized.


2. Subtracting floating-point numbers
Subtracting is performed identically to addition except that the sign of the
subtrahend is reversed.

Subtract 𝟎. 𝟑𝟔𝟒𝟏 ∙ 𝟏𝟎𝟐 𝐛𝐲 𝟎. 𝟐𝟔𝟖𝟔 ∙ 𝟏𝟎𝟐

Note: The mantissa of the final answer should be always normalized.


3. Multiplying and Dividing floating-point numbers
The exponents are added and the mantissas are multiplied for multiplication while
the exponents are subtracted and the mantissas are divided for division.

Multiply 𝟎. 𝟏𝟑𝟔𝟑 ∙ 𝟏𝟎𝟑 𝐛𝐲 𝟎. 𝟔𝟒𝟐𝟑 ∙ 𝟏𝟎−𝟏 and chopped to


four significant figures

Note: The mantissa of the final answer should be always normalized.


Numerical Analysis always involve the manipulation of numbers
with the help of a machine. Both the process of manipulation
and the machine itself are very prone to errors. It is essential to
analyse the effects of these errors in order to make our
numerical result as precisely accurate as possible!
Do not be anxious about anything, but in every
situation, by prayer and petition, with thanksgiving,
present your requests to God. And the peace of God,
which transcends all understanding, will guard your
hearts and your minds in Christ Jesus.
Philippians 4:6-7

God Bless!
References:
1. C. F. Gerald and P. O. Wheatley (2004). Applied Numerical Analysis (7th Ed.) Pearson
Education, Inc.
2. S. C. Chapra and R. P. Canale (2010). Numerical Methods for Engineers (6th Ed.)
McGraw-Hill, New York.

You might also like