MATH 353 Engineering mathematics III

Similar documents
Floating Point Arithmetic

2 Computation with Floating-Point Numbers

Floating-point representation

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

2 Computation with Floating-Point Numbers

COMP2611: Computer Organization. Data Representation

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

Floating Point Arithmetic

Number Systems. Both numbers are positive

Floating Point Numbers

Floating Point Numbers

Scientific Computing. Error Analysis

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Data Representation Floating Point

Data Representation Floating Point

1.2 Round-off Errors and Computer Arithmetic

Floating Point January 24, 2008

Computational Economics and Finance

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

FLOATING POINT NUMBERS

Chapter 3: Arithmetic for Computers

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

Foundations of Computer Systems

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

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. Today. IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.

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

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

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

Chapter Three. Arithmetic

Lecture Notes: Floating-Point Numbers

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

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

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

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

Floating-Point Numbers in Digital Computers

Floating-Point Numbers in Digital Computers

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

System Programming CISC 360. Floating Point September 16, 2008

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Computational Economics and Finance

Numeric Encodings Prof. James L. Frankel Harvard University

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


Chapter 4. Operations on Data

AMTH142 Lecture 10. Scilab Graphs Floating Point Arithmetic

Floating Point Numbers. Lecture 9 CAP

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Floating Point Numbers

Giving credit where credit is due

15213 Recitation 2: Floating Point

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

Floating Point Numbers

Giving credit where credit is due

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

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

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Computer Systems C S Cynthia Lee

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Integers and Floating Point

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

Binary floating point encodings

ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

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. Jo, Heeseung

ECE232: Hardware Organization and Design

A Level Computing. Contents. For the Exam:

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

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Floating Point. CSE 238/2038/2138: Systems Programming. Instructor: Fatma CORUT ERGİN. Slides adapted from Bryant & O Hallaron s slides

Independent Representation

Signed umbers. Sign/Magnitude otation

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

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

Finite arithmetic and error analysis

Representing and Manipulating Floating Points

Numerical Analysis First Term Dr. Selcuk CANKURT

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Mathematical preliminaries and error analysis

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

Chapter 2. Data Representation in Computer Systems

Today: Floating Point. Floating Point. Fractional Binary Numbers. Fractional binary numbers. bi bi 1 b2 b1 b0 b 1 b 2 b 3 b j

CS321 Introduction To Numerical Methods

Floating-Point Arithmetic

Introduction to Scientific Computing Lecture 1

CMPSCI 145 MIDTERM #2 SPRING 2017 April 7, 2017 Professor William T. Verts NAME PROBLEM SCORE POINTS GRAND TOTAL 100

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

Representing and Manipulating Floating Points

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Roundoff Errors and Computer Arithmetic

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Data Representation Floating Point

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Transcription:

MATH 353 Engineering mathematics III Instructor: Francisco-Javier Pancho Sayas Spring 2014 University of Delaware Instructor: Francisco-Javier Pancho Sayas MATH 353 1 / 20

MEET YOUR COMPUTER Instructor: Francisco-Javier Pancho Sayas MATH 353 2 / 20

Some lists of numbers >> format compact % Eliminates unnecessary blank lines >> 1:7 1 2 3 4 5 6 7 >> 1:2:9 % in twos 1 3 5 7 9 >> 1:2:10 % goes in 2s, never passing 10 1 3 5 7 9 >> 5:-1:2 % negative increments 5 4 3 2 % Guess the following ones >> 1:0.1:2 >> 1:-1:2 % Empty list >> 1:3:10 Instructor: Francisco-Javier Pancho Sayas MATH 353 3 / 20

Some functions Note the symbols.* and.ˆ >> f = @(x) x.^2+2*x.*(1-x)+8 % @(x) says x is the variable f = @(x)x.^2+2*x.*(1-x)+8 >> f(0) % Evaluate f at 0 8 >> f(1) 9 >> f(2) 8 >> f(0:2) % We can do this because of.* and.^ 8 9 8 Instructor: Francisco-Javier Pancho Sayas MATH 353 4 / 20

Exercises Define the function g = x 3 + 3 cos(x) (2 x) and evaluate it simultaneously at the points 0, 0.2, 0.4,..., 2. Figure out how to use fplot to draw the graph of g in the interval [0, 2]. Instructor: Francisco-Javier Pancho Sayas MATH 353 5 / 20

FLOATING POINT NUMBERS Instructor: Francisco-Javier Pancho Sayas MATH 353 6 / 20

Warning words Computers and calculators work with numbers in floating point in base 2. However, when they usually show results in floating point in base 10. In this section we will cheat by showing everything in base 10. There will be a mismatch with the base 2 representation, and we will see some strange behavior w.r.t. precision. Instructor: Francisco-Javier Pancho Sayas MATH 353 7 / 20

Floating point numbers Moving the point Every real number (except zero) can be written as ±0.m 1 m 2 m 3... 10 n, n integer, m 1 0. n is called the exponent and m 1 m 2... is called the mantissa. For instance, 1/3 = 0.333333... 10 0, 4/3 = 0.133333... 10 1, 1/11 = 0.0909090... = 0.9090909... 10 1 Note that 1 = 0.1 10 1 = 0.99999999... 10 0 Instructor: Francisco-Javier Pancho Sayas MATH 353 8 / 20

Storing a number 1 Check if the number is zero (0 is stored in a specific way) 2 Look at the sign at take it out 3 Write the unsigned number in floating point form 0.m 1 m 2 m 3... 10 n, n integer, m 1 0. 4 Limit magnitude (n min is negative, n max is positive): n min n n max, If n > n max assign, or give overflow. If n < n min assign 0 or give underflow. 5 Limit precision: store a fixed number of digits, say K, (round off the last one!) 0.m 1 m 2... 0.m 1 m 2...m K 1 m K { mk, if m m K = K +1 {0, 1, 2, 3, 4}, 1 + m K, if m K +1 {5, 6, 7, 8, 9}. If m K = 9 and m K +1 5, round off has to be carried to the left. Instructor: Francisco-Javier Pancho Sayas MATH 353 9 / 20

Example (warning: these are not the usual parameters) With the artificial limits (these are not the one used by computer and calculators!) we write 10 n 10, K = 5, 4 fl.pt = 0.13333 10 0, 3 130 6 = 21.666... fl.pt = 0.21667 10 2, 5 16 = 152587890625 = 0.152587890625 10 12 fl.pt = 5 16 = 6.5536 10 12 = 0.65536 10 11 fl.pt = 0 0.899999932 fl.pt = 0.90000 Instructor: Francisco-Javier Pancho Sayas MATH 353 10 / 20

Example (cont d) 10 n 10, 5 decimal digits The smallest positive number is 0.1000 10 10. To its left there s 0. The largest positive number is 0.99999 10 10. The number 10 10 is not stored anymore. It is infinity. In between, for a given exponent we have numbers ranging from 0.10000 10 n to 0.99999 10 n This means that there are 89999 different numbers between 1 and 10, between 10 and 100, etc... but also between 0.0001 and 0.001. The closer we are to zero, the more numbers there are. The machine ε is the distance between 1 and the following number on the right, that is, ε = 0.10001 10 1 0.10000 10 1 = 0.00001 10 1 = 0.0001. There are no numbers stored between 1 and 1 + ε. Instructor: Francisco-Javier Pancho Sayas MATH 353 11 / 20

Exercise With arbitrary magnitude and a precision of 3 decimal digits, store and compute (each computation has to be carried out after storing the numbers that appear in it!): 1 1/6 2 4372 3 4370 4 4370-4372 5 1000+1 6 π Instructor: Francisco-Javier Pancho Sayas MATH 353 12 / 20

The double precision standard In MATLAB, the magnitudes are more or less limited like 323 n 308 and the precision is of 16 digits. A 16 digit precision (not exactly 16 digits, because numbers are stored in base 2) is called double precision. The single precision standard involves more or less 8 digits. Some languages still keep the choice between single and double precision. Instructor: Francisco-Javier Pancho Sayas MATH 353 13 / 20

Large and small numbers in MATLAB >> 2^1023 8.988465674311580e+307 >> 2^1024 Inf >> 2^(-1074) 4.940656458412465e-324 >> 2^(-1075) 0 >> eps % MACHINE EPSILON 2.220446049250313e-016 Instructor: Francisco-Javier Pancho Sayas MATH 353 14 / 20

What we see on the screen Computers and calculators show large and small numbers written in scientific notation 1.243e+23 = 1.243 10 23 instead of in the floating point standard 0.1243 10 24. Normal sized numbers are shown without exponent (2.2) 4 = 23.4256 Real numbers are sometimes shown as integers (2.0) 5 = 32 Calculators make the transition from integers to floating point numbers when numbers become very large. MATLAB does not deal with integers at all. Instructor: Francisco-Javier Pancho Sayas MATH 353 15 / 20

What we see vs. what we compute MATLAB computes always in double precision, even if it doesn t show all the digits: >> format short % this is the default format >> 2^100 1.2677e+030 >> format long >> 2^100 1.267650600228229e+030 % look at the fifth digit! Instructor: Francisco-Javier Pancho Sayas MATH 353 16 / 20

Arithmetic effects of floating point The operations that most suffer from limited precision are the addition and the subtraction. The operations that most suffer from limited magnitude are product and division. With the double precision standard 23 fl.pt 16 fl.pt 1 + 10 = 1, 100 10 = 100 10 200 200 fl.pt 10 = +, 10 200 200 fl.pt 10 = 0. To avoid (as much as possible): adding numbers with very different magnitude subtracting very similar numbers Instructor: Francisco-Javier Pancho Sayas MATH 353 17 / 20

Subtraction Subtraction is a very precision losing operation: 0.333333456789 0.333333 = 0.000000456789 = 0.45678900000 10 6 Even worse, because the operation is done with binary digits, we get numerical garbage on the right >> 0.333333456789-0.333333 4.567890000140018e-007 Instructor: Francisco-Javier Pancho Sayas MATH 353 18 / 20

Foreseeing trouble Evaluating the function x + 1 x for large x is asking for trouble. Instead, we can evaluate ( x + 1 x ) x + 1 + x x + 1 + x = that has no subtractions. 1 x + 1 + x, >> f = @(x) sqrt(x+1)-sqrt(x) ; >> g = @(x) 1./(sqrt(x+1)+sqrt(x)); >> f(10^10) 4.999994416721165e-006 >> g(10^10) % we can expect this value to be better 4.999999999875000e-006 Instructor: Francisco-Javier Pancho Sayas MATH 353 19 / 20

Exercises Compare the values obtained by evaluation of the two mathematically identical functions for x = 10 10. f (x) = (x + 1) 2 x 2 g(x) = 2 x + 1 Compare the values given (if at all) by evaluation of the mathematically identical functions when x = 10. f (x) = x 1000 x 1000 + 1 g(x) = 1 1 + x 1000 Instructor: Francisco-Javier Pancho Sayas MATH 353 20 / 20