Sie sind auf Seite 1von 17

CAAM 353

Errors and Floating Point Notation

Types of Errors
Data Error vs. Computational Error = , = = , =

Error =
= + Computational (Sine Example) () Data

Types of Computational Errors


Rounding Truncation Accumulation Cancelation

Floating Point System


Real numbers can have infinite decimal representations, but computer memory is finite 0 1 2 1 = 0 + 1 + 2 + + 1 + 0 1 2 1 = 0 + 1 + 2 + + 1 = base of the number system = precision (# of digits) = Lower Bound on Exponent e = Upper Bound on Exponent e = 0 . . 1, 0 0

Chopping and Rounding


How do you cut off the infinite decimal representation to write fl(x)? Chop: Drop the (t, t+1, t+2, .) last Digits Round: If < /2 then chop else if > /2 , last digit 1 gets modified to be: 1 +1 else = /2, round to nearest even

Rounding Unit and Error


When we round, the WORST weve done is to create a relative error of:
||

1 1 2

Quantity:

1 1 2

known as Machine Precision

MATLAB: eps = 2.2204e-016

IEEE System
Many computer systems (including MATLAB) run on this system Base is 2 Single Precision = 32 bit word Double Precision = 64 bit word
1 bit for sign (0 = +, 1 = -) 11 bits for exponent, e = 2^11 possibilities 52 bits for the number (d0 to d51) Eps = * 2^(1-52) = 2^(-52)

IEEE System
Exponent possibilities 2^11 = 2048 exponent = b 1023 b = 11 bit number Infinity = 11111111111 = 2047-1023 = 1024 0 = 00000000000 = 0-1023 = -1023 Normal Numbers are in the exponent range 1023 -1022 1024 reserved for infinity, -1023 reserved for 0

How many numbers?


How many numbers can you represent with a , , , system? p= 1 1 + 1 2 + 1

How are these numbers spaced? Ex. = 2, = 2, = 1, = 1 1 0 + 21 1 2 (floatgui.m)

Floating Point Arithmetic


Add 4.567 101 and 4.567 103 Real answer: 0.4567 + 0.004567 = 0.46127 Rounded real answer: 0.4613 Answer in system with t = 4, with chop 0.4567 + 0.0045 = 0.4612 Most computer systems have guard digits to avoid this (allow leading zeros that dont count in the precision)

Floating Point Arithmetic


Multiplication: 4.567 101 times 4.567 103 Real Answer: 2.0857489 103 Chopped Answer for t=4: 2.085 103 If you use this number for another computation in your code, the error propagates called Error Accumulation

Another Interesting Example


From calculus, you should remember that the following series is the Taylyer series of exp(x)
=0 !

Lets look at this sum in MATLAB for: x = 10 and x = -10 Can you foresee a problem? (exptest.m)

Cancelation Error
Previous slides error for x = -10 can also be called cancelation error (loss of digits due to canceling of the beginning digits) Sometimes you can avoid cancellation error, by being smart with your arithmetic Example: 1 +

Subtracting Close Numbers


Back to our derivative example Solution should improve as h 0, right? WRONG
+ ()

Total Error: + (sinapprox.m)

Patriot Missile Failure


On February 25, 1991, during the Gulf War, an American Patriot Missile battery in Dharan, Saudi Arabia, failed to track and intercept an incoming Iraqi Scud missile. 28 people died, 100 injured The cause was an inaccurate calculation of the time since boot due to computer arithmetic errors

Patriot Missile Disaster


The time in tenths of second as measured by the system's internal clock was multiplied by 1/10 to produce the time in seconds Calculations done with 24-bit (base 2 numbers) 1/10 has a non-terminating rep. in base 2 Chop error, multiplied by the large time (in tenths of seconds) produced a time in seconds that was inaccurate

Patriot Missile Disaster


Detector had been on 100 hours = 3600000 tenths of seconds Multiply by base 2 (24-bit, roughly 6 digits of accuracy) version of 1/10 and you are off by about 0.34 sec A Scud travels at about 1,676 meters per second, and so travels more than half a kilometer in 0.34 sec!
http://www.ima.umn.edu/~arnold/disasters/patriot.html

Das könnte Ihnen auch gefallen