Numerical Methods 5633

Similar documents
Numerical Methods I Numerical Computing

Scientific Computing: An Introductory Survey

Mathematical preliminaries and error analysis

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

Computational Methods. Sources of Errors

Scientific Computing Numerical Computing

Scientific Computing: An Introductory Survey

Roundoff Errors and Computer Arithmetic

Floating-Point Arithmetic

Floating-point representation

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

2 Computation with Floating-Point Numbers

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers

2 Computation with Floating-Point Numbers

Floating Point Representation in Computers

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

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

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Floating Point Numbers

Finite arithmetic and error analysis

CS321 Introduction To Numerical Methods

Review of Calculus, cont d

Computational Economics and Finance

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

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

Computational Economics and Finance

Scientific Computing. Error Analysis

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

Data Representation Floating Point

Floating Point January 24, 2008


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

MATH 353 Engineering mathematics III

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

Data Representation Floating Point

1.2 Round-off Errors and Computer Arithmetic

CS321. Introduction to Numerical Methods

Numerical Methods 5633

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

Introduction to floating point arithmetic

Floating-point representations

Floating-point representations

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

2.1.1 Fixed-Point (or Integer) Arithmetic

Classes of Real Numbers 1/2. The Real Line

Foundations of Computer Systems

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

CHAPTER 2 SENSITIVITY OF LINEAR SYSTEMS; EFFECTS OF ROUNDOFF ERRORS

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

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

Computer Systems C S Cynthia Lee

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

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

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

Floating-Point Arithmetic

Representing and Manipulating Floating Points

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Floating Point Numbers

System Programming CISC 360. Floating Point September 16, 2008

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating Point Numbers

Floating Point Numbers

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

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

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

CSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.

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

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

Representing and Manipulating Floating Points

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

Numerical Methods 5633

Lecture Notes: Floating-Point Numbers

Giving credit where credit is due

FLOATING POINT NUMBERS

Numerical Computing: An Introduction

Giving credit where credit is due

Representing and Manipulating Floating Points. Jo, Heeseung

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

Representing and Manipulating Floating Points

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

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

FP_IEEE_DENORM_GET_ Procedure

Floating-point numbers. Phys 420/580 Lecture 6

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

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Divide: Paper & Pencil

CO212 Lecture 10: Arithmetic & Logical Unit

Floating Point Arithmetic

Floating-Point Arithmetic

ECE232: Hardware Organization and Design

Floating Point Numbers. Lecture 9 CAP

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

Chapter Three. Arithmetic

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

Floating Point Considerations

Transcription:

Numerical Methods 5633 Lecture 2 Marina Krstic Marinkovic mmarina@maths.tcd.ie School of Mathematics Trinity College Dublin Marina Krstic Marinkovic 1 / 15 5633-Numerical Methods

Organisational Assignment 0 - non assessed To appear Submission DL Assignment 1 14.10 28.10 Assignment 2 28.10 11.11 Assignment 3 18.11 09.12 Last 2 weeks - Tue. or Thurs. (+Fri.) lectures? 15.11/22.11 (14-16h) or 17.11/24.11 (14-16h) Module MA3463 (Computation theory and logic)? -> Tue. Marina Krstic Marinkovic 2 / 15 5633-Numerical Methods

Computational Errors A numerical method must use a finite representation for numbers and thus cannot possibly produce an exact answer for all problems For example, 3.14159 instead of π etc. Sources of error: Discretisation (approximation) error Truncation error Roundoff error Propagated error Statistical error References for this lecture: David Bindel, Jonathan Goodman Principles of Scientific Computing Sources of Error, Chapter Sources of Error Most of the material taken from: http://cims.nyu.edu/~donev/ Teaching/NMI-Fall2010/Lecture1.handout.pdf https://cran.r-project.org/doc/manuals/r-intro.pdf Marina Krstic Marinkovic 3 / 15 5633-Numerical Methods

Conditioning a Computational Problem A generic computational problem: Find solution x that satisfies a condition F(x,d)=0,for given data d Well posed problem has a unique solution that depends continuously on the data. Otherwise:ill-posed problem (no numerical method will work!) Conditioning number (K): x / x K =sup d6=0 d / d absolute error: relative error: ˆx = x + x ˆx =(1+ )x K is an important intrinsic property of a computational problem. K 1, problem is well-conditioned. Ill-conditioned problem: a given target accuracy of the solution cannot be computed for a given accuracy of the data, i.e. K is large! Marina Krstic Marinkovic 4 / 15 5633-Numerical Methods

Consistency, Stability and Convergence Discretisation error: F (x, d) =0! ˆF n (ˆx n, ˆd n )=0 replacing the computational problem with an easier-to-solve approximation for each n there is an algorithm that produces ˆx n given ˆdn A numerical method is: consistent - if the approximation error vanishes as n!1 stable - if propagated errors decrease as the computation progresses convergent - if the numerical error can be made arbitrarily small by increasing the computational effort Other very important features, determining the choice of NM: accuracy, reliability/robustness, efficiency Marina Krstic Marinkovic 5 / 15 5633-Numerical Methods

IEEE 754 Computers represent everything using bit strings, i.e., integers in base-2. Integers can thus be exactly represented. But not real numbers! IEEE Standard for floating-point arithmetic (est. 1985): Formats for representing and encoding real numbers using bit strings (single and double precision) Rounding algorithms for performing accurate arithmetic operations (e.g. addition,subtraction,division,multiplication) and conversions (e.g. single to double precision) Exception handling for special situations (e.g. division by zero and overflow) R programming: Some info on the implementation of the IEEE 754 standard in R: https://stat.ethz.ch/r-manual/r-devel/library/base/html/double.html Marina Krstic Marinkovic 6 / 15 5633-Numerical Methods

Floating Point Representation Assume we have a computer that represents numbers using a given (decimal) number system Representing real numbers, with N available digits: Fixed-point representation: x =( 1) s [a N 2 a N 3...a k a k 1...a 0 ] - Problem with representing large/small numbers: 9.872 but 0.009 Floating-point representation: x =( 1) s [0a 1 a 2...a t ] e =( 1) s m e t - Similar to the common scientific representation: 0.9872 10 1 and 0.9872 10-2 A floating-point number in base β is represented using: one sign bit s = 0 or 1 (positive or negative nr.) integer exponent giving its order of magnitude t-digit integer mantissa specifying actual digits of the number Marina Krstic Marinkovic 7 / 15 5633-Numerical Methods

IEEE Standard Representations IEEE representation example (single precision example): Take the number x = 2752 = 0.2752 10 4 1. Converting 2752 to the binary: x =2 11 +2 9 +2 7 +2 6 = (101011000000) 2 =2 11 (1.01011) 2 =( 1) 0 2 138 127 (1.01011) 2 =( 1) 0 2 (10001010) 2 127 (1.01011) 2 2. On the computer: x =( 1) s 2 p 127 (1.f) 2 x =[s p f] =[0 100, 0101, 0 010, 1100, 0000, 0000, 0000, 0000] = (452c0000) 16 IEEE non-normalised numbers value power p fraction f ±0 0 0 denormal (subnormal) 0 >0 ± (inf ) 255 0 Not a number (NaN) 255 >0 Marina Krstic Marinkovic 8 / 15 5633-Numerical Methods

IEEE Standard Representations Representation of single(a) and double(b) precision numbers: (a) (b) [Illustrations: By Codekaizen - Own work, GFDL, https://commons.wikimedia.org/w/index.php?curid=3595583] See wikipedia article on IEEE: https://en.wikipedia.org/wiki/ieee_754-1985 Marina Krstic Marinkovic 9 / 15 5633-Numerical Methods

IEEE Standard Representations R-script for conversion of integer to binary # function for converting integer to binary numbers binary<-function(p_number) { bsum<-0 bexp<-1 while (p_number > 0) { digit<-p_number %% 2 p_number<-floor(p_number / 2) bsum<-bsum + digit * bexp bexp<-bexp * 10 } return(bsum) } #predefined math function floor #floor(x) gives [x] p_number<-readline("decimal number: ") #reading a number decimal representation p_number<-as.numeric(p_number) #converts the input to integer bsum<-binary(p_number) #calls function to perform conversion to binary cat("binary: ", bsum) #prints binary number > source( binary.sh ) Decimal number: 2752 Binary: 1.01011e+11> Marina Krstic Marinkovic 10 / 15 5633-Numerical Methods

Important Facts about Floating-Point Not all real numbers x, or even integers, can be represented exactly as a floating-point number, instead, they must be rounded to the nearest floating point number The relative spacing or gap between a floating-point x and the nearest other one is at most ε = 2 Nf, sometimes called ulp (unit of least precision). In particular, 1 + ε is the first floatingpoint number larger than 1 Floating-point numbers have a relative rounding error that is smaller than the machine precision or roundoff-unit u. The rule of thumb is that single precision gives 7-8 digits of precision and double 16 digits Do not compare floating point numbers (especially for loop termination), or more generally, do not rely on logic from pure mathematics! Marina Krstic Marinkovic 11 / 15 5633-Numerical Methods

Floating-Point Exceptions Computing with floating point values may lead to exceptions, which may be trapped and halt the program: Divide-by-zero if the result is ± Invalid if the result is a NaN Overflow if the result is too large to be represented Underflow if the result is too small to be represented Numerical software needs to be careful about avoiding exceptions where possible Do not compare floating point numbers (especially for loop termination), or more generally, do not rely on logic from pure mathematics! Marina Krstic Marinkovic 12 / 15 5633-Numerical Methods

Numerical Cancellation If x and y are close to each other, x y can have reduced accuracy due to cancellation of digits. Note: If gradual underflow is not supported x y can be zero even if x and y are not exactly equal Benign cancellation: subtracting two exactly-known IEEE numbers results in a relative error of no more than an ulp. The result is precise Catastrophic cancellation occurs when subtracting two nearly equal inexact numbers and leads to loss of accuracy and a large relative error in the result For example, 1.1234 1.1223 = 0.0011 which only has 2 significant digits instead of 4. The result is not accurate Marina Krstic Marinkovic 13 / 15 5633-Numerical Methods

Avoiding Cancellation Rewriting in mathematically-equivalent but numericallypreferred form is the first try For example p x + p x! px + + p x to avoid catastrophic cancellation. But what about the extra cost? Sometimes one can use Taylor series or other approximation to get an approximate but stable result p x + p x 2 p x for x Marina Krstic Marinkovic 14 / 15 5633-Numerical Methods

Summary A numerical method needs to control the various computational errors (approximation, roundoff ) while balancing computational cost The IEEE standard (attempts to) standardises the single and double precision floating-point formats, their arithmetic, and exceptions. It is widely implemented (R, Matlab, ) Numerical overflow, underflow and cancellation need to be carefully considered and may be avoided Mathematically-equivalent forms are not numerically-equivalent Never compare floating point numbers! Especially for loop termination, or more generally, do not rely on logic from pure mathematics Some disastrous things might happen due to applying numerical methods in an incorrect way Marina Krstic Marinkovic 15 / 15 5633-Numerical Methods