Docsity

Errors and Uncertainties in Computational Physics | PHYS 5322, Study notes of Physics

Partial preview of the text

Download Errors and Uncertainties in Computational Physics | PHYS 5322 and more Study notes Physics in PDF only on Docsity!

Errors and Uncertainties in

Computations

Igor Volobouev

Computational Physics (PHYS 5322)

Texas Tech University

Taxonomy of Errors

Bugs Wrong or Insufficient Models Hardware Errors Uncertainties in the Data Approximation Errors Round-Off Errors

Wrong or Insufficient Models

Learning how to get the models right is the one of themain purposes of this course Bodies move in elliptical orbits in a central gravitationalfield? Such a nice abstraction! Now, lets try to use GPSsatellite orbits so that we can determine our owncoordinates with ~1 m precision. Suddenly, we have totake into account that

Earth is neither round nor uniform, it rotates and has tides There are many other bodies in the solar system Sun exerts radiation pressure There is some residual atmosphere even at 20,000 km altitude Clocks run at different rates on the satellites and on the ground Signals move in curved trajectories (just as Einstein predicted) Atmosphere (ionosphere in particular) is a refractive medium

If you’ve done all you can and the model still does notwork – perhaps you have discovered new physics!

Hardware Errors

Usually easy to deal with

The computer actually tells you when your hard drivestarts dying. Just pay attention.

However, certain failure mechanisms are difficultto detect and control

Design mistakes (pentium FDIV bug) Electromigration Power glitches Single event upsets

Redundancy helps when calculations aremission-critical

Example: triple or quadruple computer redundancy isstandard on space systems and ICBMs You might want to repeat a long-running calculation

Approximation Errors

Bread and butter of applied mathematicsstudies We will see many examples in this course.Most often, there is a trade-off betweenthe time needed to run the algorithm andthe accuracy achieved.

0

0

N

x

e

n

x

n

x

e

x

N n

n

n

n

x

−

=

∞ =

−

Round-Off Errors

Numbers are represented in a computer withlimited range and accuracy

Hypothetical example: let say, computer keeps fourdecimal places. Then 1/3 = 0.3333 and 2/3 = 0.6667.Now, 2*(1/3) – 2/3 = – 0.

≠

Representing numbers in “double precisionfloating point” (every such number in a computeris encoded using 64 bits) is a reasonable trade-off between accuracy, range, and computationspeed

This may not be optimal for all types of applications.Arbitrary-precision arithmetic software packages doexist and can be used if necessary. They incur a hugehit in computation speed (FPU becomes useless).

IEEE 754 Representation for

Doubles

Number Type

s

e

, and

f

Value

Normal

e

Subnormal

e

f

Signed zero

e

f

s

e

f

+Inf

s

e

f

–Inf

Not a number

e

f

NaN

1023

  1. 1 ) 1 (

−

×

×

−

e

f

s

1022

  1. 0 ) 1 (

−

×

×

−

f

s

  1. 0 ) 1 (

×

−

s

Properties of IEEE 754 Doubles

Precision: 1 part in 2

52

(approximately 16 decimal

places) Range: from 4.9 × 10

to 1.8 × 10

308

Underflow: happens when result magnitude issmaller than the smallest positive number.Usually converted to 0. Overflow: happens when result magnitude islarger than the largest positive number. Usuallyconverted to Inf. 0/0, 0×

etc.

produce NaNs.

Round-Off Disasters

If you subtract two large numbers and endup with a small result, precision of theresult will be worse than the precision ofthe terms. This effect is called subtractivecancellation. Beware rapidly changing functions whichmap large numbers into small. This effectis known as error amplification.

Subtractive Cancellation

a = b – c in the computer turns into a

FP

= b

FP

  • c

FP

= b (1 +

b

) – c (1 +

c

Then a

FP

/a = 1 +

b

b/a –

c

c/a.

But a

FP

/a = 1 +

a

by definition. If a is small

then b

c, and

a

b/a (

b

c

b/a max(|

b

c

|) where

b/a is a large number.

Round-Off Error Accumulation^ a = b × c in the computer turns intoa

FP

= b

FP

× c

FP

= b (1 +

b

) × c (1 +

c

Then a

FP

/a = (1 +

b

c

b

c

That is, relative errors are added. Assume that all errors are uncorrelatedand of the order

m

. Then the overall error

from

N

multiplications grows as

m

N

Error Minimization

Approximation errors in algorithms often behaveas

α

N

k

(for large

N

) where

N

is the number of

steps and

α

and

k

are some empirical constants.

If we assume that round-off errors from differentsteps are uncorrelated then the total errorbehaves as

ε

total

α

N

k

β√

N

(where

β

is the

error from one step, usually on the order ofseveral

ε

m

). The first term dominates at small

N

and the second at large

N

. As a consequence,

there is an optimal value of

N

at which

ε

total

is

minimized.

Empirical Approach

Best way to study convergence: compare with a knownanswer for some parameter values in your problem If there is no reference case, study the behavior of yourresult,

R

, as a function of

N

. Plot

as a function of log

10

N

(

R

(

2N

) approximates the exact

answer)

.

If you obtain a straight line drop-off, you can

deduce the value of

k

from the slope. If your code is fast,

run until you see the onset of the round-off errordomination. Be sensible: the error model just described might not workfor your particular algorithm. Also, converged

≠

correct.

log

10

N
R
N
R
N
R

Let’s Play

Hopefully, this lecture will help you scratch yourhead in a more systematic manner when resultsof your calculations do not look right Let’s do some exercises now: http://highenergy.phys.ttu.edu/~igv/Computation alPhysics/Labs/lab1.html Reading assignment for the next class: chapters1 and 2 from Giordano & Nakanishi. Don’t forgetthe programming homework you already have.