Math.375 Fall 2005 I - Numbers and Formats

Slides:



Advertisements
Similar presentations
Roundoff and truncation errors
Advertisements

2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Math.375 Fall Errors in Numerical Computation Vageli Coutsias.
Floating Point (FLP) Representation A Floating Point value: f = m*r**e Where: m – mantissa or fractional r – base or radix, usually r = 2 e - exponent.
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
Round-Off and Truncation Errors
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Floating Point Numbers
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
ECEN 248 Integer Multiplication, Number Format Adopted from Copyright 2002 David H. Albonesi and the University of Rochester.
Floating Point Computation
IT 251 Computer Organization and Architecture Introduction to Floating Point Numbers Chia-Chi Teng.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Programming in C++ Computer Science Dept Va Tech August, 2000 © Barnette ND, McQuain WD, Keenan MA 1 Independent Representation.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 22, 2004 Lecture Number: 24.
Introduction to Numerical Analysis I
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
COMP 116: Introduction to Scientific Programming Lecture 28: Data types.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Figure 1.1 Block diagram of a digital computer. Functional Units.
Spring Floating Point Computation Jyun-Ming Chen.
Round-off Errors.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Integer and Fixed Point P & H: Chapter 3
IEEE Arithmetic UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 4 - Numerical Errors CVEN 302 June 10, 2002.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
14/02/ Floating Point Representation Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker Presented.
Numbers in Computers.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point (FLP) Representation
Introduction to Numerical Analysis I
Machine arithmetic and associated errors Introduction to error analysis Class II.
Number Representation
Integer Division.
Topics IEEE Floating Point Standard Rounding Floating Point Operations
CS 232: Computer Architecture II
IEEE floating point format
Complex Numbers Real part Imaginary part
April 2006 Saeid Nooshabadi
Modified from Sharon Guffy
Chapter 6 Floating Point
Topic 3d Representation of Real Numbers
Recall our hypothetical computer Marc-32
Roundoff and Truncation Errors
Number Representations
Data Representation Data Types Complements Fixed Point Representation
EEL 3705 / 3705L Digital Logic Design
Floating Point Representation
CS 105 “Tour of the Black Holes of Computing!”
Approximations and Round-Off Errors Chapter 3
CS 105 “Tour of the Black Holes of Computing!”
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
Floating Point Numbers
Math.375 Fall 2005 I - Numbers and Formats
Topic 3d Representation of Real Numbers
Machine epsilon eps returns the distance from 1.0 to the next largest floating point number. When eps is machine epsilon, the logic 1+eps>1 is TRUE.
CS 105 “Tour of the Black Holes of Computing!”
Roundoff and Truncation Errors
Number Representations
Presentation transcript:

Math.375 Fall 2005 I - Numbers and Formats Vageli Coutsias On the dangers of numerical computation: A bestiary

Introduction 1 + 1 = 0 or “machine epsilon”? » eps = 2.220446049250313e-016 How does matlab produce its numbers? Where we learn about number formats, truncation errors and roundoff

Matlab real number formats » format long %(default for  ) pi = 3.14159265358979 » format short pi = 3.1416 » format short e pi = 3.1416e+000 » format long e pi = 3.141592653589793e+000

Floating-point numbers Base or radix t Precision [L,U] Exponent range

The set F of f.p. numbers is the IEEE standard Basis b Significant digits t Range (U, L) F(b, t, U, L): F(2, 53, -1021, 1024) is the IEEE standard 11/11/2018

sign bit mantissa (52 bits) exponent (11 bits) (it is assumed d1= 1, so only need d2,…d53) exponent (11 bits) 11/11/2018

IEEE double precision standard If E=2047 and F is nonzero, then V=NaN ("Not a number") If E=2047 and F=0 and S=0,(1) then V=Inf, (-Inf) If E=0 and F=0 and S=0,(1), then V=0,(-0) If 0<E<2047 then V=(-1)**S * 2 ** (E-1023) * (1.F) where "1.F" denotes the binary number created by prefixing F with an implicit leading 1 and a binary point. If E=0 and F is nonzero, then V=(-1)**S * 2 ** (-1022) * (0.F) These are "unnormalized" values. 11/11/2018

contains “unnormalized” values, as allowed, e.g., in IEEE standard 11/11/2018

Floating point numbers The machine precision is the smallest nuber  such that:

Machine epsilon The distance from 1 to the next larger float Gives the relative error in representing a real number in the system F: (RELATIVE) ROUNDOFF ERROR 11/11/2018

Machine epsilon computed a = 1; b = 1; while a+b ~= a b = b/2; end b % b = 1.110223024625157e-016 % shows that a+b = a is satisfied by % numbers b not equal to 0 % here b = eps/2 is the largest such % number for a = 1 11/11/2018

Overflow does not only cause programs to crash! Arianne V’s short maiden flight on 7/4/96 was due to a floating exception.

FLOAT  INTEGER During the conversion of a 64-bit floating-point number to a 16-bit signed integer Caused by the float being outside the range representable by such integers The programming philosophy employed did not guard against software errors-a fatal assumption!

COMPLEX NUMBERS z = x + i*y x = Re(z) is the real part y = Im(z) is the imaginary part i^2 = -1 is the imaginary unit polar form complex conjugate 11/11/2018

>>% Cartesian form: x = real(z); y = imag(z) Matlab commands: >> z = 3+i*4 >>% Cartesian form: x = real(z); y = imag(z) >>% Polar form: theta = angle(z); rho = abs(z) So: z = abs(z)*(cos(angle(z)) + i*sin(angle(z))) x-i*y = conj(z) 11/11/2018

The complex plane z=[1+2*i, 3,-1+i, -i]; compass(z,’r’) defines an array of complex numbers which are plotted as vectors in the x-y plane 11/11/2018

Roots of complex numbers » x = -1 ; x^(1/3) ans = 0.5000 + 0.8660i Matlab assumes complex arithmetic, and returns automatically the root with the smallest phase angle ( the other two roots are -1 and 0.5000 - 0.8660i 11/11/2018

Types of errors in numerical computation Roundoff errors Pi = 3.14159 Pi = 3.1415926535897932384626 Truncation errors Cos x = 1 – x^2/2 Cos x = 1 – x^2/2 + x^4/4! Errors usually accumulate randomly (random walk) But they can also be systematic, and the reasons may be subtle!

x = linspace(1-2*10^-8,1+2*10^-8,401); f = x.^7-7*x.^6+21*x.^5-35*x.^4+35*x.^3-21*x.^2+7*x-1; plot(x,f) CANCELLATION ERRORS 11/11/2018

g = -1+x.*(7+x.*(-21+x.*(35+x.*(-35+x.*(21+x.*(-7+x)))))); plot(x,g) 11/11/2018

h = (x-1).^7; plot(x,h) 11/11/2018

plot(x,h,x,g,x,f) 11/11/2018

z(k+1) = 2^(k-1/2)*(1-(1-4^(1-k)*z(k)^2)^(1/2))^(1/2); end z(1) = 0; z(2) = 2; for k = 2:29 z(k+1) = 2^(k-1/2)*(1-(1-4^(1-k)*z(k)^2)^(1/2))^(1/2); end semilogy(1:30,abs(z-pi)/pi) 11/11/2018

I.ARITHMETIC OPERATIONS and symbols (1) format long, longe; format short, short e (2) +, *, ^, ~, /, - (3) suppress output: ending commands with “;” (4) Complex: real, imag, conj, i, j, angle, abs, compass (5) Machine constants and special variables: eps, realmin, realmax, pi (6) loops: loop until condition while (condition true) end 11/11/2018

Summary Roundoff and other errors Formats and floating point numbers Complex numbers

References Higham & Higham, Matlab Guide, SIAM SIAM News, 29(8), 10/98 (Arianne V failure) B5 Trailer; http://www.scifi.com/b5rangers/