Computational Methods. Sources of Errors

Similar documents
Scientific Computing: An Introductory Survey

Roundoff Errors and Computer Arithmetic

2.1.1 Fixed-Point (or Integer) Arithmetic

Scientific Computing: An Introductory Survey

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. What is scientific computing?

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers

CS321 Introduction To Numerical Methods

Outline. 1 Scientific Computing. 2 Approximations. 3 Computer Arithmetic. Scientific Computing Approximations Computer Arithmetic

Mathematical preliminaries and error analysis

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Computing Basics. 1 Sources of Error LECTURE NOTES ECO 613/614 FALL 2007 KAREN A. KOPECKY

Chapter 3. Errors and numerical stability

Review of Calculus, cont d

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

Computational Economics and Finance

CHAPTER 2 SENSITIVITY OF LINEAR SYSTEMS; EFFECTS OF ROUNDOFF ERRORS

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

CS321. Introduction to Numerical Methods

Computational Economics and Finance

AM205: lecture 2. 1 These have been shifted to MD 323 for the rest of the semester.

Truncation Errors. Applied Numerical Methods with MATLAB for Engineers and Scientists, 2nd ed., Steven C. Chapra, McGraw Hill, 2008, Ch. 4.

2 Computation with Floating-Point Numbers

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Binary floating point encodings

1.2 Round-off Errors and Computer Arithmetic

Floating-Point Arithmetic

2 Computation with Floating-Point Numbers

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

Computer Arithmetic. 1. Floating-point representation of numbers (scientific notation) has four components, for example, 3.

Floating-point representation

Objectives. look at floating point representation in its basic form expose errors of a different form: rounding error highlight IEEE-754 standard

Numerical Computing: An Introduction

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

fractional quantities are typically represented in computers using floating point format this approach is very much similar to scientific notation

Numerical Methods 5633

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Numerical Methods I Numerical Computing

Finite arithmetic and error analysis

Introduction to floating point arithmetic

New Mexico Tech Hyd 510

Floating Point Representation in Computers

Floating Point Arithmetic

Scientific Computing. Error Analysis

Divide: Paper & Pencil

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Accuracy versus precision

Introduction to Computational Mathematics

Lecture 03 Approximations, Errors and Their Analysis

What we need to know about error: Class Outline. Computational Methods CMSC/AMSC/MAPL 460. Errors in data and computation

Floating-Point Arithmetic

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Foundations of Computer Systems

Classes of Real Numbers 1/2. The Real Line

Computational Mathematics: Models, Methods and Analysis. Zhilin Li

Floating-point numbers. Phys 420/580 Lecture 6

Errors in Computation

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point Error Analysis. Ramani Duraiswami, Dept. of Computer Science

Chapter 2. Data Representation in Computer Systems

COS 323: Computing for the Physical and Social Sciences

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Data Representation Floating Point

Floating Point January 24, 2008

ME 261: Numerical Analysis. ME 261: Numerical Analysis

Computer Arithmetic Floating Point

Data Representation Floating Point

Floating Point Arithmetic

Class 5. Data Representation and Introduction to Visualization

Floating-Point Arithmetic

EE878 Special Topics in VLSI. Computer Arithmetic for Digital Signal Processing

Exponential Numbers ID1050 Quantitative & Qualitative Reasoning

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Chapter 4. Operations on Data


UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Floating Point. CSC207 Fall 2017

Numerical Methods for Eng [ENGR 391] [Lyes KADEM 2007]

Data Representation and Introduction to Visualization

AMTH142 Lecture 10. Scilab Graphs Floating Point Arithmetic

(Refer Slide Time: 02:59)

Floating-point representations

1.3 Floating Point Form

Floating-point representations

Scientific Computing Numerical Computing

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

COS 323: Computing for the Physical and Social Sciences

Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Numerical computing. How computers store real numbers and the problems that result

Floating Point Numbers

Floating Point Numbers

Bits, Words, and Integers

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Floating point. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

Representing and Manipulating Floating Points. Jo, Heeseung

Error in Numerical Methods

Number Systems. Both numbers are positive

Transcription:

Computational Methods Sources of Errors Manfred Huber 2011 1

Numerical Analysis / Scientific Computing Many problems in Science and Engineering can not be solved analytically on a computer Numeric solutions are often required Numeric solutions provide only approximate solutions Numeric solutions are not unique Different numeric algorithms might yield different approximations Numerical Analysis deals with the design and analysis of numeric algorithms Deals with continuous quantities Considers / analyzes the effects of approximations Manfred Huber 2011 2

Computational Problems and Numerical Algorithms Solving of computational problems usually involves the following steps: Mathematical modeling Develop a mathematical description for the problem Algorithm design Build an algorithm to solve the mathematical problem formulation Analyze the algorithm for its performance Implementation and Evaluation Implement the algorithm Evaluate its performance with real data Manfred Huber 2011 3

Computational Problems and Numerical Algorithms A problem is well-posed if A solution exists and is unique The solution depends continuously on the data Ill-posed problems are often sensitive to the data and solution algorithms are not stable Some ill-posed problems can be approximated by wellposed similar problems Even solutions to well-posed problems can be sensitive to data Computational algorithm should not increase sensitivity Manfred Huber 2011 4

Problem Solution Strategies Finding a solution (and subsequently an algorithm) for a computational problem often involves replacing a difficult problem with a simpler one with identical or closely related solution Replace infinite with finite formulations Replace differential equations with algebraic equations Replace non-linear formulations with linear ones Replace complicated functions with simpler ones Replace higher-order systems with lower-order ones Solutions may only approximate the original ones Manfred Huber 2011 5

Sources of Approximation Problem formulation and input data Simplifications in the original model of the problem Errors in measurements used as input data Approximations resulting from pre-computations Algorithm and implementation Truncation and discretization as part of the algorithm design (usually resulting from simplifications of the original mathematical model) Rounding as a result of the use of a finite resolution digital computer Manfred Huber 2011 6

Approximation and Error The accuracy of the solution produced by a numerical algorithm depends on errors introduced by the modeling and pre-computation and by the computation in the algorithm The first can usually not be addressed but have to be considered when analyzing an algorithm The problem and the solution algorithm can have major effects on the accuracy of the approximation The problem can amplify input error (sensitivity) The algorithm can amplify computation errors (stability) Manfred Huber 2011 7

Approximation and Error The total error is generally a result of errors in the data and errors arising through the computation Computational error : Propagated data error: Computational errors arise from simplifications in the algorithm and from numeric limitations f ˆ ( x ) f (x) = f ˆ ( x ) f ( x ) + f ( x ) f (x) f ˆ ( x ) f ( x ) f ( x ) f (x) Truncation error: Caused by the algorithm Rounding error: Caused by limited numeric precision Truncation and Rounding often trade off Manfred Huber 2011 8

Example: Finite Difference Compute the derivative using finite difference approximation: f (x + Δx) f (x) f '(x) Δx Truncation error is bounded by M Δx 2 Rounding error is bounded by 2 ε Δx Optimal step size: Δx 2 ε / M Sin(x) : Manfred Huber 2011 9

Absolute and Relative Error Absolute error: Relative error: ˆ y y ˆ y y y The true value, y, is generally unknown Relative error is often computed relative to the approximate value Error has to be approximated or calculated as a bound Manfred Huber 2011 10

Forward and Backward Error Error can be analyzed in the output space or in the input space of the algorithm Δy = y ˆ y = f ˆ (x) f (x) Forward error : error in the output of the algorithm for the same input Backward error: Δx = x ˆ x ; y ˆ = f ( x ˆ ) error in the correct input corresponding to the output Manfred Huber 2011 11

Backward Error Backward error can be a useful analysis tool Backward error captures sensitivity Measures how much the original problem has to change to result in exactly the approximate solution How much data error would explain the total error Approximate solution is good if it has a small backward error Backward error is often easier to estimate than forward error Manfred Huber 2011 12

Sensitivity and Conditioning A problem is sensitive (ill-conditioned) if a change in the input data can cause a much larger change in the output data Condition number captures sensitivity: A problem is sensitive if cond >> 1 cond = relative output error relative data error ( ) / f (x) ( ) / x = f ( x ˆ ) f (x) x ˆ x Condition number represents an amplification factor between relative backward and relative forward error = Δy / y Δx / x Manfred Huber 2011 13

Stability An algorithm is stable if the result is relatively insensitive to perturbations caused by the computation Similar to conditioning for problems An algorithm is stable if it results in a small backward error (i.e. if its result is the exact solution to a similar problem) If an algorithm is stable, the computational error is no worse than a small input error Manfred Huber 2011 14

Accuracy Accuracy measures the similarity of the true and the computed solution Accuracy depends on conditioning of the problem and stability of the algorithm Stability or well-conditioning alone do not guarantee accuracy A stable algorithm applied to an ill-conditioned problem can yield inaccuracy An unstable algorithm applied to a well-conditioned problem can yield inaccurate results To achieve accurate solutions a stable algorithm has to be applied to a well-conditioned problem Manfred Huber 2011 15

Number Representation and Rounding Errors Floating point numbers are used to represent continuous number Real numbers can not be represented accurately Operations on floating point numbers are not accurate Floating point numbers: Base β Precision p Exponent range [L,U] x = ± d 0 + d 1 β +... + d p 1 β p 1 β E Manfred Huber 2011 16

Floating Point Numbers Multiple floating point standards exist Most floating point systems are normalized so that the first bit of the mantissa is 1 No digits wasted on leading zeros (saves 1 bit) Manfred Huber 2011 17

Floating Point Numbers Underflow: smallest positive normalized number UFL = β L Overflow: largest floating point number OFL = (1 β p )β U +1 Machine precision: smallest number larger than 1 minus 1 ε mach = β 1 p Machine precision bounds the rounding error: With rounding to nearest: fl(x) x x 1 2 ε mach Manfred Huber 2011 18

Floating Point Number Example Representable numbers for a binary number with 3 bit mantissa and 2 bit exponent OFL = 3.5 UFL = 0.5 mach = 0.125 Manfred Huber 2011 19

Floating Point Arithmetic Floating point operations introduce rounding errors Addition and subtraction For addition and subtraction the mantissa has to be shifted until the exponents of the numbers are equal Multiplication Potential loss of significant bits in the smaller number Mantissas have to be multiplied, yielding theoretically a new mantissa with 2p digits which has to be rounded Division Quotient of mantissas can theoretically have an infinite number of digits which have to be rounded Manfred Huber 2011 20

Floating Point Arithmetic Besides rounding errors, floating point operations can result in unrepresentable numbers Overflow Results of an overflow (a number too large to be represented) possess no good approximation and can be catastrophic. Underflow On most computer systems overflow produces an error message Results of an underflow are usually approximated as 0. On many computer systems underflow is handled silently Manfred Huber 2011 21

Floating Point Arithmetic Many general arithmetic laws do not strictly hold in floating point arithmetic Addition and multiplication are commutative but not associative Underflow, overflow, and rounding can lead to incorrect results. 1 Infinite sum n =1 n While this sum diverges in reality (and thus has no result) numeric calculation of it yields a finite sum Partial sum no longer changes once 1/n is too small compared to the value of the partial sum Manfred Huber 2011 22

Relative Error and Loss of Significance Errors produced by well implemented arithmetic floating point operations can be modeled by fl(x op y) = (x op y)(1 + δ) ; δ ε mach Relative error bound fl(x op y) (x op y) ε mach (x op y) Error propagation can still lead to high relative error through loss of significance (or cancellation) When during subtraction leading digits cancel out the result uses fewer than p digits and thus looses precision Manfred Huber 2011 23

Loss of Significance Rounding results in a loss of the least significant digits while cancellation leads to a loss of the most significant digits It is generally a bad idea to compute a small number by subtracting large numbers The propagated rounding error through loss of significance might ultimately dominate the actual result Manfred Huber 2011 24

Loss of Significance To avoid cancellation errors, problems can sometimes be reformulated in a way that avoids the problem Multiplication with conjugate expressions: y x = ( y x)( y + x) y + x = y x 2 y + x Application of identities to restructure the expression: 1 cos x sin 2 x = 1 1 + cos x x = b ± b2 4ac 2c = 2a b b 2 4ac Manfred Huber 2011 25

Representation and Error Computations on digital computers produce approximations that yield errors Approximation should be taken into account when designing and analyzing algorithms Approximations break into multiple types Data errors Computation errors Truncation error due to algorithm Rounding error due to representation limitations Errors can propagate and be amplified Algorithm design should take errors into account Manfred Huber 2011 26