Round-Off and Truncation Errors

Slides:



Advertisements
Similar presentations
Part 1 Chapter 4 Roundoff and Truncation Errors PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
Advertisements

Roundoff and truncation errors
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Floating Point Numbers
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Fall 2006AE6382 Design Computing1 Numeric Representation in a Computer Learning Objectives Understand how numbers are stored in a computer and how the.
Approximations and Errors
1 CSE1301 Computer Programming Lecture 30: Real Number Representation.
Lecture 2: Numerical Differentiation. Derivative as a gradient
CSE1301 Computer Programming Lecture 33: Real Number Representation
Dr Damian Conway Room 132 Building 26
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 3 Approximations and Errors.
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Floating Point Numbers
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 31.
Simple Data Type Representation and conversion of numbers
2.2 Errors. Why Study Errors First? Nearly all our modeling is done on digital computers (aside: what would a non-digital analog computer look like?)
Binary Real Numbers. Introduction Computers must be able to represent real numbers (numbers w/ fractions) Two different ways:  Fixed-point  Floating-point.
James Tam Number systems and logic What is the decimal based number system How does the binary number system work Converting between decimal and binary.
Computer Science 111 Fundamentals of Programming I Number Systems.
Chapter 1 Data Storage(3) Yonsei University 1 st Semester, 2015 Sanghyun Park.
Lecture 2 Number Representation and accuracy
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
CISE301_Topic11 CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4:
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
ME 142 Engineering Computation I Computer Precision & Round-Off Error.
5.2 Errrors. Why Study Errors First? Nearly all our modeling is done on digital computers (aside: what would a non-digital analog computer look like?)
Round-off Errors.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Round-off Errors and Computer Arithmetic. The arithmetic performed by a calculator or computer is different from the arithmetic in algebra and calculus.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter.
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
Meeting 15 Introduction to Numerical Methods Error Analysis.
Lecture 4 - Numerical Errors CVEN 302 June 10, 2002.
Introduction to computing
1 Approximation. 2 Taylor Series 3 Truncation Error  In general, the nth order Taylor series expansion will be exact for an nth order polynomial  In.
Numerical Analysis CC413 Propagation of Errors.
Binary Arithmetic.
Errors in Numerical Methods
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.7 Instructor: Lin Chen Sept 2013.
ESO 208A/ESO 218 LECTURE 2 JULY 31, ERRORS MODELING OUTPUTS QUANTIFICATION TRUE VALUE APPROXIMATE VALUE.
Numerical Analysis CC413 Propagation of Errors. 2 In numerical methods, the calculations are not made with exact numbers. How do these inaccuracies propagate.
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Chapter 2 Errors in Numerical Methods and Their Impacts.
Introduction to Numerical Analysis I
Machine arithmetic and associated errors Introduction to error analysis Class II.
Programming and Data Structure
ME 142 Engineering Computation I
Number Systems and Binary Arithmetic
Chapter 6 Floating Point
Chapter 2 ERROR ANALYSIS
Roundoff and Truncation Errors
Fundamentals of Programming I Number Systems
Approximations and Round-Off Errors Chapter 3
Storing Negative Integers
Chapter 1 / Error in Numerical Method
Roundoff and Truncation Errors
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Presentation transcript:

Round-Off and Truncation Errors CHAPTER 4 Round-Off and Truncation Errors

Numerical Accuracy Truncation error : Method dependent Errors which result from using an approximation rather than an exact procedure Round-off error : Machine dependent Errors which result from not being able to adequately represent the true value Result from using an approximate number to represent exact number

Taylor Series Expansion Construction of finite-difference formula Numerical accuracy: discretization error a x Base point x = a

Taylor series expansions

Taylor Series and Remainder Taylor series (base point x = a) Remainder

Truncation Error (xi = 0, h = x  xi+1 = x) Taylor series expansion Example (higher-order terms truncated) (xi = 0, h = x  xi+1 = x)

Power series Polynomials The function becomes more nonlinear as m increases

A MATLAB Script Filename: fun_exp.m function sum = exp(x) % Evaluate exponential function exp(x) % by Taylor series expansion % f(x)=1 + x + x^2/2! + x^3/3! + … + x^n/n! clear all x = input(‘enter the value of x = ’); n = input(‘enter the order n = ’); term =1 ; sum= term; for i = 1 : n term = term*x/i; sum = sum + term; end

MATLAB For Loops Filename: fun_exp2.m function sum = exp(x) % Evaluate exponential function exp(x) % by Taylor series expansion % f(x)=1 + x + x^2/2! + x^3/3! + … + x^n/n! x = input(‘enter the value of x =’); n = input(‘enter the order n = ’); term(1) =1 ; sum(1)= term(1); for i = 1 : n term(i+1) = term(i)*x/i; sum(i+1) = sum(i) + term(i+1); end % Display the results disp(‘i term(i) sum(i)’) a = 1:n+1; [a’ term’ sum’]

Truncation Error n term sum n term sum

Truncation Error n term sum n term sum How to reduce error?

Round-off Errors Computers can represent numbers to a finite precision Most important for real numbers - integer math can be exact, but limited How do computers represent numbers? Binary representation of the integers and real numbers in computer memory

MATLAB uses double precision 32 bits (23, 8, 1) 28 = 256 64 bits (52, 11, 1) 211 = 2048 MATLAB uses double precision

Order of operation Addition problem: exact result with 3-digit arithmetic: Round-off error

Cancellation error If b is large, r is close to b Difference of two numbers very close to each other  potential for greater error! Rationalize:

Try b = 97 x2 (r = 96.9794) (3 sig. figs.) exact: 0.01031 standard: 0.01050 rationalized: 0.01031 Corresponding to “cancellation, critical arithmetic”

Significant Figures 48.9 mph? 48.95 mph?

Significant Digits The places which can be used with confidence 32-bit machine: 7 significant digits 64-bit machine: 17 significant digits Double precision: reduce round-off error, but increase CPU time

False Significant Figures 3.25/1.96 = 1.65816326530162... (from MATLAB) But in practice only report 1.65 (chopping) or 1.66 (rounding)! Why?? Because we don’t know what is beyond the second decimal place

Accuracy and precision Accuracy - How closely a measured or computed value agrees with the true value Precision - How closely individual measured or computed values agree with each other Accuracy is getting all your shots near the target. Precision is getting them close together. More Accurate More Precise

Numerical Errors The difference between the true value and the approximation Approximation = true value + true error Et = true value  approximation = x*  x or in percent

Approximate Error But the true value is not known If we knew it, we wouldn’t have a problem Use approximate error

Number Systems 1 lb = 16 oz, 1 ft = 12 in, ½”, ¼”, ….. Base-10 (Decimal): 0,1,2,3,4,5,6,7,8,9 Base-8 (Octal): 0,1,2,3,4,5,6,7 Base-2 (Binary): 0,1 – off/on, close/open, negative/positive charge Other non-decimal systems 1 lb = 16 oz, 1 ft = 12 in, ½”, ¼”, …..

Decimal System (base 10) Binary System (base 2)

Integer Representation Signed magnitude method Use the first bit of a word to indicate the sign – 0: negative (off), 1: positive (on) Remaining bits are used to store a number + 1 0 1 0 0 1 0 1 1 0 Sign Number off / on, close / open, negative / positive

Integer Representation 8-bit word +/- 0000000 are the same, therefore we may use “-0” to represent “-128” Total numbers = 28 = 256 (-128 127) Sign Number

Integer Representation 16-bit word Range: -32,768 to 32,767 Overflow: > 32,767 (cannot represent 43,000 A&M students) Underflow: < -32,768 (magnitude too large) 32-bit word Range: -2,147,483,648 to 2,147,483,647 9 significant digits Overflow: world population 6 billion Underflow: budget deficit -$100 billion

Integer Operations So 123 + 45 = overflow and -74 * 2 = underflow Integer arithmetic can be exact as long as you don't get remainders in division 7/2 = 3 in integer math or overflow the maximum integer For a 8-bit computer max = 128 (or -127) So 123 + 45 = overflow and -74 * 2 = underflow

Floating-Point Representation Real numbers (also called floating-point numbers) are represented differently For fraction or very large numbers Store as sign is 1 or 0 for negative or positive exponent is maximum value (positive or negative) of base mantissa contains significant digits sign signed exponent mantissa

Floating-Point Representation sign of number signed exponent mantissa m: mantissa B: Base of the number system e: “signed” exponent Note: the mantissa is usually “normalized” if the leading digit is zero

Integer representation Floating-point number representation

Decimal Representation 8-bit word sign signed exponent number 1|095|1467 (base: B = 10) mantissa: m = -(1*10-1 + 4*10-2 + 6*10-3 + 7*10-4 ) = -0.1467 signed exponent: e = + (9*101 + 5*100) = 95

Floating-Point Representation 8-bit word (without normalization) sign signed exponent number 0|111|0101 (base: B = 2) mantissa: m = +(0*2-1 + 1*2-2 + 0*2-3 + 1*2-4 ) = 5/16 signed exponent: e = - (1*21 + 1*20) = -3

Normalization (Less accurate) (Normalization) Remove the leading zero by lowering the exponent (d1 = 1 for all numbers) if m < 1/2, multiply by 2 to remove the leading 0 floating-point allow fractions and very large numbers to be represented, but take up more memory and CPU time

Binary Representation 8-bit word (with normalization) sign signed exponent number 1|011|1001 (base: B = 2) mantissa: m = -(1*2-1 + 0*2-2 + 0*2-3 + 1*2-4 ) = -9/16 signed exponent: e = + (1*21 + 1*20) = 3

Single Precision 23 for the digits 32 bits 8 for the signed exponent A real variable (number) is stored in four words, or 32 bits (64 bits for Supercomputers) bit (binary digit): 0 or 1 byte: 4 bits, 24 = 16 possible values word: 2 bytes = 8 bits, 28 = 256 possible values 23 for the digits 32 bits 8 for the signed exponent 1 for the sign

Double Precision signed exponent  210 =  1024 52 for the digits A real variable is stored in eight words, or 64 bits 16 words, 128 bits for supercomputers signed exponent  210 =  1024 52 for the digits 64 bits 11 for the signed exponent 1 for the sign

Round-off Errors Example - three significant digits Floating point characteristics contribute to round-off error (limited bits for storage) Limited range of quantities can be represented A finite number of quantities can be represented The interval between numbers increases as the numbers grow Example - three significant digits 0.0100 0.0101 0.0102 …… 0.0999 (0.0001 increment) 0.100 0.101 0.102 ……. 0.999 (0.001 increment) 1.00 1.01 1.02 ……. 9.99 (0.01 increment)

MATLAB MATLAB uses double precision Finite number of real quantities (integers, real numbers or text) can be represented For 8-bit, 28 = 256 quantities For 16-bit, 216 = 65536 quantities MATLAB uses double precision 4 bytes = 64 bits more than 1019 (264) quantities