Physics 331 Introduction to Numerical Techniques in Physics

Similar documents
Floating Point Arithmetic

Scientific Computing. Error Analysis

Chapter Three. Arithmetic

Chapter 3. Errors and numerical stability

Finite arithmetic and error analysis

Data Representation Floating Point

FLOATING POINT NUMBERS

Data Representation Floating Point

IEEE-754 floating-point

Computational Economics and Finance

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

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

Floating Point Representation in Computers

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

2 Computation with Floating-Point Numbers

2.1.1 Fixed-Point (or Integer) Arithmetic

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

Up next. Midterm. Today s lecture. To follow

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

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

Floating-point representations

Floating-point representations

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

Computational Economics and Finance

COMP Overview of Tutorial #2

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

Chapter 3: Arithmetic for Computers

MATH 353 Engineering mathematics III

1.3 Floating Point Form

CS321. Introduction to Numerical Methods

CS101 Lecture 04: Binary Arithmetic

1.2 Round-off Errors and Computer Arithmetic

Roundoff Errors and Computer Arithmetic

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

3.5 Floating Point: Overview

Variables and Data Representation

Floating Point Numbers

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

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Floating-Point Arithmetic

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

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

CS 6210 Fall 2016 Bei Wang. Lecture 4 Floating Point Systems Continued

Review of Calculus, cont d

Computer Arithmetic Floating Point

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

Classes of Real Numbers 1/2. The Real Line

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating-Point Numbers in Digital Computers

Data Representation Floating Point

Floating-Point Numbers in Digital Computers

COMP2611: Computer Organization. Data Representation

ECE232: Hardware Organization and Design

Floating-point representation

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Introduction to Scientific Computing Lecture 1

Foundations of Computer Systems

2 Computation with Floating-Point Numbers

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Representing and Manipulating Floating Points. Jo, Heeseung

CS321 Introduction To Numerical Methods

Computational Methods. Sources of Errors

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

Outline. What is Performance? Restating Performance Equation Time = Seconds. CPU Performance Factors

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

Inf2C - Computer Systems Lecture 2 Data Representation

Numerical Representations On The Computer: Negative And Rational Numbers

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Introduction to Computers and Programming. Numeric Values

Numerical Representations On The Computer: Negative And Rational Numbers

15213 Recitation 2: Floating Point

Floating Point Arithmetic

Module 2: Computer Arithmetic

Signed umbers. Sign/Magnitude otation

Floating-Point Arithmetic

Divide: Paper & Pencil

Floating Point Numbers

Floating Point Numbers

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

IEEE Standard 754 Floating Point Numbers

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Floating Point Numbers. Lecture 9 CAP

4.1 QUANTIZATION NOISE

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

Scientific Computing: An Introductory Survey

Lecture Notes: Floating-Point Numbers


Representing and Manipulating Floating Points

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

Computers and programming languages introduction

Data Representation 1

Computer Numbers and their Precision, I Number Storage

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Topic Notes: Bits and Bytes and Numbers

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

Transcription:

Physics 331 Introduction to Numerical Techniques in Physics Instructor: Joaquín Drut Lecture 2

Any logistics questions?

Today: Number representation Sources of error Note: typo in HW! Two parts c. Call them c1 and c2.

Representing numbers on a computer

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties?

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties? Reals form a field (6 axioms about + and. )

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties? Reals form a field (6 axioms about + and. ) Reals are ordered (3 axioms allowing to define > and < )

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties? Reals form a field (6 axioms about + and. ) Reals are ordered (3 axioms allowing to define > and < ) Reals are complete (every convergent sequence has a real limit)

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties? Reals form a field (6 axioms about + and. ) Reals are ordered (3 axioms allowing to define > and < ) Reals are complete (every convergent sequence has a real limit) Real numbers contain rational as well as irrational numbers. This is a problem! Why?

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers... What makes real numbers so special? What are their defining properties? Reals form a field (6 axioms about + and. ) Reals are ordered (3 axioms allowing to define > and < ) Reals are complete (every convergent sequence has a real limit) Real numbers contain rational as well as irrational numbers. This is a problem! Why? How many rationals are there? How many irrationals?

Numbers Our understanding of nature has led us to a description in terms of real and complex numbers...... but computers use a discrete and finite set of numbers. You can already imagine that the range and precision of numbers we can represent will somehow be limited. An engineering decision had to be made regarding how to manage such limitations. But there is more to consider

Digital computers In digital computers, everything is ultimately reduced to on and off, or 0 and 1. Numbers on such a computer are encoded in base 2: Base 10 Base 2 1 0 0 0 1 2 0 0 1 0 3 0 0 1 1 4 0 1 0 0 5 0 1 0 1 6 0 1 1 0 7 0 1 1 1 bits

Decimal and binary representations The decimal representation of numbers is so common that we often forget why we count the way we do. (Why?)

Decimal and binary representations The decimal representation of numbers is so common that we often forget why we count the way we do. Decimal Take the number 23,488.386 What does this mean in the decimal representation?

Decimal and binary representations The decimal representation of numbers is so common that we often forget why we count the way we do. Decimal Take the number 23,488.386 What does this mean in the decimal representation? 23,488.386 2 x 10 4 + 3 x 10 3 + 4 x 10 2 + 8 x 10 1 + 8 x 10 0 + 3 x 10-1 + 8 x 10-2 + 6 x 10-3

Decimal and binary representations Binary We only have 1 and 0, and then we move on to the next digit! You may have something like... 11100101001.0010 What does this mean?

Decimal and binary representations Binary We only have 1 and 0, and then we move on to the next digit! You may have something like... 11100101001.0010 What does this mean? Exercise: What number is this in decimal representation? Take 2 minutes and try to figure it out!

Decimal and binary representations Binary We only have 1 and 0, and then we move on to the next digit! You may have something like... 11100101001.0010 What does this mean? Exercise: What number is this in decimal representation? Take 2 minutes and try to figure it out! Exercise: What number is 21 in binary representation? Take 2 minutes and try to figure it out!

On a computer, numbers are represented in terms of bits, but that s not all there is to it

Floating point representations Decimal floating point representation (a.k.a. scientific notation) d.ddddddd x 10 p d: 0,1,..,9 mantissa think precision exponent think order of magnitude Example f =+1.2546 10 135

Floating point representations Decimal floating point representation (a.k.a. scientific notation) d.ddddddd x 10 p d: 0,1,..,9 mantissa think precision exponent think order of magnitude In general To find the first digit d (from the left), and thus the mantissa as well, divide by the highest power of 10 that is less than the number you want to represent. That power is the exponent p.

Floating point representations Binary floating point representation (a.k.a. most of you have never seen this before) 1.bbbbbbb x 2 bbb b: 0,1 mantissa exponent

Floating point representations IEEE standard: f = s M B e E There is also quadruple precision! SP sign exponent mantissa

Floating point representations IEEE standard: f = s M B e E Overflow 0 Underflow Overflow Note: - There is a largest positive number! Overflow - There is a smallest positive number! Underflow - Only a finite number of exact values! - Interval between numbers depends on exponent!

Examples f =+1.2546 10 135 f = s M B e E

Examples f =+1.2546 10 135 f = s M B e E f = 478.043

Examples f =+1.2546 10 135 f = s M B e E f = 478.043 f = 0.000465

Floating point representations IEEE standard: f = s M B e E There is also quadruple precision! SP sign exponent mantissa What range of values can we represent for the exponent with 8 bits?

The exponent e : true exponent f = s M B e E E : bias (127 in SP; 1023 in DP)

Sources of error

Sources of error when programming... Syntax errors (aka compile errors: code does not even compile) Runtime errors (e.g. seg-fault; code compiles but fails when running) Numerical errors (more on this soon!) Physics errors (not a programming error: the code does what you want and it does it right... you just have the physics wrong!)

Sources of error when programming... Syntax errors (aka compile errors: code does not even compile) Runtime errors (e.g. seg-fault; code compiles but fails when running) Numerical errors (more on this soon!) Physics errors (not a programming error: the code does what you want and it does it right... you just have the physics wrong!) We will put aside discussions of the model/approach used to represent the physics. These could give... Systematic errors (controlled approximations; e.g. finite volume, finite mesh) Uncontrolled errors (the model may involve an approximation )

Sources of numerical error... Round-off errors (computers have finite precision) Round-off errors will propagate in iterative methods and potentially produce instabilities and give useless results.

Sources of numerical error... Round-off errors (computers have finite precision) Round-off errors will propagate in iterative methods and potentially produce instabilities and give useless results. Statistical error (e.g. if your method uses random numbers, like in MC) You just need more statistics - it s almost like a systematic error... but it can be much harder to deal with!

Statistical error / signal-to-noise problem. Example 15 10 1 cosi loghxl x 0 x M x > 0.162177 5 0.2 0.4 0.6 0.8 1.0-5 -10-15

Statistical error / signal-to-noise problem. Example 15 10 1 cosi loghxl x 0 x M x > 0.162177 5 0.2 0.4 0.6 0.8 1.0-5 -10-15

Sources of numerical error... Round-off errors (computers have finite precision) Round-off errors will propagate in iterative methods and potentially produce instabilities and give useless results. Statistical error (e.g. if your method uses random numbers, like in MC) You just need more statistics - it s almost like a systematic error... but it can be much harder to deal with!

Sources of numerical error... Round-off errors (computers have finite precision) Round-off errors will propagate in iterative methods and potentially produce instabilities and give useless results. Statistical error (e.g. if your method uses random numbers, like in MC) You just need more statistics - it s almost like a systematic error... but it can be much harder to deal with! Truncation errors (caused by the numerical method) How do you estimate the value of complicated functions, series expansions, integrals, derivatives...? Should be a systematic error, i.e. something we can treat. Why?

Total error Total error = True solution - Numerical solution Total relative error = True solution - Numerical solution True solution Usually we do not know the true solution; that is what we are looking for! The numerical solution can be systematically improved. Ideally the only error left is just the round-off error. We will always be limited by this!