Numerics and Error Analysis

Similar documents
How do computers represent numbers?

Notes for Chapter 1 of. Scientific Computing with Case Studies

Arithmetic and Error. How does error arise? How does error arise? Notes for Part 1 of CMSC 460

1 Backward and Forward Error

Lecture 7. Floating point arithmetic and stability

Chapter 1: Introduction and mathematical preliminaries

Introduction CSE 541

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Norms, Sensitivity and Conditioning

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

ECS 231 Computer Arithmetic 1 / 27

Linear Systems and LU

1 Floating point arithmetic

Chapter 1 Mathematical Preliminaries and Error Analysis

Floating-point Computation

Elements of Floating-point Arithmetic

Elements of Floating-point Arithmetic

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

ACM 106a: Lecture 1 Agenda

Linear Systems and LU

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Notes on floating point number, numerical computations and pitfalls

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

Numerical Algorithms. IE 496 Lecture 20

Binary floating point

Mathematical preliminaries and error analysis

CS412: Introduction to Numerical Methods

Chapter 4 Number Representations

Can ANSYS Mechanical Handle My Required Modeling Precision?

Number Systems III MA1S1. Tristan McLoughlin. December 4, 2013

Lecture 28 The Main Sources of Error

Errors. Intensive Computation. Annalisa Massini 2017/2018

Chapter 1 Error Analysis

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Tu: 9/3/13 Math 471, Fall 2013, Section 001 Lecture 1

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 5. Ax = b.

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

4.2 Floating-Point Numbers

Introduction and mathematical preliminaries

Lecture Notes 7, Math/Comp 128, Math 250

Math 411 Preliminaries

Lecture 12. Block Diagram

ROUNDOFF ERRORS; BACKWARD STABILITY

An Introduction to Numerical Analysis

Program 1 Foundations of Computational Math 1 Fall 2018

Binary Floating-Point Numbers

Numerical Methods in Physics and Astrophysics

Continuing discussion of CRC s, especially looking at two-bit errors

Remainders. We learned how to multiply and divide in elementary

Register machines L2 18

8/13/16. Data analysis and modeling: the tools of the trade. Ø Set of numbers. Ø Binary representation of numbers. Ø Floating points.

Introduction to Finite Di erence Methods

Numerical Methods - Preliminaries

Announce Statistical Motivation Properties Spectral Theorem Other ODE Theory Spectral Embedding. Eigenproblems I

MATH ASSIGNMENT 03 SOLUTIONS

BASIC COMPUTER ARITHMETIC

Announce Statistical Motivation ODE Theory Spectral Embedding Properties Spectral Theorem Other. Eigenproblems I

More General Functions Is this technique limited to the monomials {1, x, x 2, x 3,...}?

Floating Point Number Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Accurate polynomial evaluation in floating point arithmetic

Mathematics for Engineers. Numerical mathematics

Lecture 4 Modeling, Analysis and Simulation in Logic Design. Dr. Yinong Chen

Chemistry: The Study of Change Chang & Goldsby 12 th edition

Introduction to Scientific Computing Languages

Introduction to Scientific Computing Languages

SIGNIFICANT FIGURES. x 100%

INTRODUCTION TO COMPUTATIONAL MATHEMATICS

Eigenproblems II: Computation

Outline. Making Models with Polynomials: Interpolation Making Models with Monte Carlo Error, Accuracy and Convergence Floating Point

Algebra Year 9. Language

Ordinary Differential Equations I

A Brief Introduction to Numerical Methods for Differential Equations

The Euclidean Division Implemented with a Floating-Point Multiplication and a Floor

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Number Representation and Waveform Quantization

Numerical Methods. Dr Dana Mackey. School of Mathematical Sciences Room A305 A Dana Mackey (DIT) Numerical Methods 1 / 12

Tunable Floating-Point for Energy Efficient Accelerators

Chapter 1 Computer Arithmetic

Heinemann VCE Zone textbook reference General Mathematics

Applied Mathematics 205. Unit 0: Overview of Scientific Computing. Lecturer: Dr. David Knezevic

Measurement 4: Scientific Notation

Ex code

1 ERROR ANALYSIS IN COMPUTATION

Round-off Errors and Computer Arithmetic - (1.2)

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 2

Every time a measurement is taken, we must be aware of significant figures! Define significant figures.

Chapter 1. Numerical Errors. Module No. 1. Errors in Numerical Computations

Scientific Notation. Sig. Figs. Estimation Density. Unit cancelation

On various ways to split a floating-point number

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

CS4495/6495 Introduction to Computer Vision. 8C-L3 Support Vector Machines

Ordinary Differential Equations I

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

Advanced topic: Space complexity

ESO 208A: Computational Methods in Engineering. Saumyen Guha

Base unit-a defined unit of measurement based on an object or event in the physical world. Length

Homework 2 Foundations of Computational Math 1 Fall 2018

Transcription:

Numerics and Error Analysis CS 205A: Mathematical Methods for Robotics, Vision, and Graphics Doug James (and Justin Solomon) CS 205A: Mathematical Methods Numerics and Error Analysis 1 / 30

A Puzzle What is the value of the following expression? abs(3.*(4./3.-1.)-1.) CS 205A: Mathematical Methods Numerics and Error Analysis 2 / 30

A Puzzle What is the value of the following expression? abs(3.*(4./3.-1.)-1.) Machine precision ε m : smallest ε m with 1 + ε m = 1 CS 205A: Mathematical Methods Numerics and Error Analysis 2 / 30

Prototypical Example double x = 1.0; double y = x / 3.0; if (x == y*3.0) cout << "They are equal!"; else cout << "They are NOT equal."; CS 205A: Mathematical Methods Numerics and Error Analysis 3 / 30

Take-Away Mathematically correct Numerically sound CS 205A: Mathematical Methods Numerics and Error Analysis 4 / 30

Using Tolerances double x = 1.0; double y = x / 3.0; if (fabs(x-y*3.0) < numeric_limits<double>::epsilon) cout << "They are equal!"; else cout << "They are NOT equal."; CS 205A: Mathematical Methods Numerics and Error Analysis 5 / 30

Counting in Binary: Integer 463 = 256 + 128 + 64 + 8 + 4 + 2 + 1 = 2 8 + 2 7 + 2 6 + 2 3 + 2 2 + 2 1 + 2 0 1 1 1 0 0 1 1 1 1 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 CS 205A: Mathematical Methods Numerics and Error Analysis 6 / 30

Counting in Binary: Fractional 463.25 = 256 + 128 + 64 + 8 + 4 + 2 + 1 + 1 /4 = 2 8 + 2 7 + 2 6 + 2 3 + 2 2 + 2 1 + 2 0 + 2 2 1 1 1 0 0 1 1 1 1. 0 1 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 2 1 2 2 CS 205A: Mathematical Methods Numerics and Error Analysis 7 / 30

Familiar Problem 1 3 = 0.0101010101... 2 Finite number of bits CS 205A: Mathematical Methods Numerics and Error Analysis 8 / 30

Fixed-Point Arithmetic 1 1 0. 0 1 1 2 l 2 l 1 2 0 2 1 2 k+1 2 k Parameters: k, l Z k + l + 1 digits total Can reuse integer arithmetic (fast; GPU possibility): a + b = (a 2 k + b 2 k ) 2 k CS 205A: Mathematical Methods Numerics and Error Analysis 9 / 30

Two-Digit Example 0.1 2 0.1 2 = 0.01 2 = 0.02 Multiplication and division easily change order of magnitude! CS 205A: Mathematical Methods Numerics and Error Analysis 10 / 30

Demand of Scientific Applications 9.11 10 31 6.022 10 23 Desired: Graceful transition CS 205A: Mathematical Methods Numerics and Error Analysis 11 / 30

Observations Compactness matters: 6.022 10 23 = 602, 200, 000, 000, 000, 000, 000, 000 CS 205A: Mathematical Methods Numerics and Error Analysis 12 / 30

Observations Compactness matters: 6.022 10 23 = 602, 200, 000, 000, 000, 000, 000, 000 Some operations are unlikely: 6.022 10 23 + 9.11 10 31 CS 205A: Mathematical Methods Numerics and Error Analysis 12 / 30

Scientific Notation ± sign Store significant digits (d 0 + d 1 b 1 + d 2 b 2 + + d p 1 b 1 p ) significand Base: b N Precision: p N Range of exponents: e [L, U] b e exponent CS 205A: Mathematical Methods Numerics and Error Analysis 13 / 30

Properties of Floating Point 0 0.5 1 1.5 2 2.5 3 3.5 1.25 1.75 0.625 0.75 0.875 Unevenly spaced Machine precision ε m : smallest ε m with 1 + ε m = 1 CS 205A: Mathematical Methods Numerics and Error Analysis 14 / 30

Properties of Floating Point 0 0.5 1 1.5 2 2.5 3 3.5 0.625 0.75 0.875 1.25 Unevenly spaced 1.75 Machine precision ε m : smallest ε m with 1 + ε m = 1 Needs rounding rule (e.g. round to nearest, ties to even ) CS 205A: Mathematical Methods Numerics and Error Analysis 14 / 30

Properties of Floating Point 0 0.5 1 1.5 2 2.5 3 3.5 0.625 0.75 0.875 1.25 Unevenly spaced 1.75 Machine precision ε m : smallest ε m with 1 + ε m = 1 Needs rounding rule (e.g. round to nearest, ties to even ) Can remove leading 1 CS 205A: Mathematical Methods Numerics and Error Analysis 14 / 30

Infinite Precision Q = { a /b : a, b Z} Simple rules: a /b + c /d = (ad+cb) /bd Redundant: 1 /2 = 2 /4 Blowup: 1 100 + 1 101 + 1 102 + 1 103 + 1 104 + 1 105 = 188463347 3218688200 Restricted operations: 2 2 CS 205A: Mathematical Methods Numerics and Error Analysis 15 / 30

Bracketing Store range a ± ε Special case of Interval Arithmetic Keeps track of certainty and rounding decisions Easy bounds: (x±ε 1 )+(y ±ε 2 ) = (x+y)±(ε 1 +ε 2 +error(x+y)) Implementation via operator overloading CS 205A: Mathematical Methods Numerics and Error Analysis 16 / 30

Sources of Error Rounding Discretization Modeling Input CS 205A: Mathematical Methods Numerics and Error Analysis 17 / 30

Example What sources of error might affect a financial simulation? CS 205A: Mathematical Methods Numerics and Error Analysis 18 / 30

Example Catastrophic cancellation Consider the function near x = 0. f(x) = ex 1 x 1 CS 205A: Mathematical Methods Numerics and Error Analysis 19 / 30

Absolute vs. Relative Error Absolute Error The difference between the approximate value and the underlying true value CS 205A: Mathematical Methods Numerics and Error Analysis 20 / 30

Absolute vs. Relative Error Absolute Error The difference between the approximate value and the underlying true value Relative Error Absolute error divided by the true value CS 205A: Mathematical Methods Numerics and Error Analysis 20 / 30

Absolute vs. Relative Error Absolute Error The difference between the approximate value and the underlying true value Relative Error Absolute error divided by the true value 2 in ± 0.02 in 2 in ± 1% CS 205A: Mathematical Methods Numerics and Error Analysis 20 / 30

Relative Error: Difficulty Problem: Generally not computable CS 205A: Mathematical Methods Numerics and Error Analysis 21 / 30

Relative Error: Difficulty Problem: Generally not computable Common fix: Be conservative CS 205A: Mathematical Methods Numerics and Error Analysis 21 / 30

Computable Measures of Success Root-finding problem For f : R R, find x such that f(x ) = 0. Actual output: x est with f(x est ) 1 CS 205A: Mathematical Methods Numerics and Error Analysis 22 / 30

Backward Error Backward Error The amount the problem statement would have to change to make the approximate solution exact CS 205A: Mathematical Methods Numerics and Error Analysis 23 / 30

Backward Error Backward Error The amount the problem statement would have to change to make the approximate solution exact Example 1: x CS 205A: Mathematical Methods Numerics and Error Analysis 23 / 30

Backward Error Backward Error The amount the problem statement would have to change to make the approximate solution exact Example 1: x Example 2: A x = b CS 205A: Mathematical Methods Numerics and Error Analysis 23 / 30

Conditioning Well-conditioned: Small backward error = small forward error Poorly conditioned: Otherwise Example: Root-finding CS 205A: Mathematical Methods Numerics and Error Analysis 24 / 30

Condition Number Condition number Ratio of forward to backward error CS 205A: Mathematical Methods Numerics and Error Analysis 25 / 30

Condition Number Condition number Ratio of forward to backward error Root-finding example: 1 f (x ) CS 205A: Mathematical Methods Numerics and Error Analysis 25 / 30

Theme Extremely careful implementation can be necessary. CS 205A: Mathematical Methods Numerics and Error Analysis 26 / 30

Example: x 2 double normsquared = 0; for (int i = 0; i < n; i++) normsquared += x[i]*x[i]; return sqrt(normsquared); CS 205A: Mathematical Methods Numerics and Error Analysis 27 / 30

Improved x 2 double maxelement = epsilon; for (int i = 0; i < n; i++) maxelement = max(maxelement, fabs(x[i])); for (int i = 0; i < n; i++) { double scaled = x[i] / maxelement; normsquared += scaled*scaled; } return sqrt(normsquared) * maxelement; CS 205A: Mathematical Methods Numerics and Error Analysis 28 / 30

More Involved Example: i x i double sum = 0; for (int i = 0; i < n; i++) sum += x[i]; CS 205A: Mathematical Methods Numerics and Error Analysis 29 / 30

Motivation for Kahan Algorithm ((a + b) a) b =? 0 Store compensation value! Details in textbook Next CS 205A: Mathematical Methods Numerics and Error Analysis 30 / 30