Accuracy and Reliability Accuracy and Reliability Numerical - - PowerPoint PPT Presentation

accuracy and reliability accuracy and reliability
SMART_READER_LITE
LIVE PREVIEW

Accuracy and Reliability Accuracy and Reliability Numerical - - PowerPoint PPT Presentation

Accuracy and Reliability Accuracy and Reliability Numerical Precision Is the Very Soul of Science. Sir DArcy Wentworth Thompson y p (1860-1948) 1 Fall 2010 Fundamental Problems Fundamental Problems There are two fundamental problems


slide-1
SLIDE 1

Accuracy and Reliability Accuracy and Reliability

Numerical Precision Is the Very Soul of Science. Sir D’Arcy Wentworth Thompson

1

y p (1860-1948)

Fall 2010

slide-2
SLIDE 2

Fundamental Problems Fundamental Problems

There are two fundamental problems in There are two fundamental problems in numerical computation: The input values are not known exactly or The input values are not known exactly or cannot be represented exactly. S f th l l ti t b f d Some of the calculations cannot be performed exactly. Therefore, errors obtained may propagate to later calculations, causing an error growth, which can be very large.

2

slide-3
SLIDE 3

Inexact Values Inexact Values

There are a number of issues with respect to p the inexact value problem: Input values are not exact p Finite precision storage Number conversion is not exact Number conversion is not exact Overflow and underflow Some arithmetic laws may not hold Some arithmetic laws may not hold See the next few slides.

3

slide-4
SLIDE 4

Input Values are Not Exact Input Values are Not Exact

Since computers can only store a finite number Since computers can only store a finite number

  • f digits, some real numbers cannot be input to

computer precisely (e.g., , , π, 1/3, 1/7, etc).

2

3

computer precisely (e.g., , , π, 1/3, 1/7, etc). The following triangle cannot be input precisely because of

2

3 3

because of .

3

( )

0, 3n

4

( ,0) n ( ,0) n −

slide-5
SLIDE 5

Finite Precision Storage Finite Precision Storage

Computers store a real number, in a normal Computers store a real number, in a normal form such as ±0.xx….x×10±yyy, in two parts: fraction and exponent as shown below. fraction and exponent as shown below. Both parts have only finite number of digits. Th b h 1/3 d 1/7

2

3

Thus, numbers such as

, , π, 1/3 and 1/7

cannot be stored precisely.

2

3

± ±yyy xxx………xxx yyy

5

slide-6
SLIDE 6

Number Conversion Is Not Exact Number Conversion Is Not Exact

We use decimal system;

0.1 × 2 0.1 × 16

y ; however, computers use binary or hexadecimal

× 2

  • 0.2

× 2 × 16

  • 1.6

× 16

systems for floating-point number representations.

  • 0.4

× 2

  • 9.6

× 16

Conversion from decimal to binary or to hexadecimal i t t

  • 0.8

× 2

  • 9.6

× 16

is not exact. For example, 0.110 = 0 0001100110011 d

  • 1.6

× 2

  • 9.6

0.0001100110011….2 and 0.110 = 0.199999…..16.

  • 1.2

× 2

6

  • 0.4
slide-7
SLIDE 7

Number Conversion Revisited: 1/2 Number Conversion Revisited: 1/2

In computers, floating points are stored in a In computers, floating points are stored in a “normal” form as mentioned earlier. We know 0.310 = 0.01001 1001 10011001……2. 0.310 0.01001 1001 10011001……2. In a normal form, the fraction part is converted to the range of (-1 +1) Thus we have 0 3 = to the range of (-1,+1). Thus, we have 0.310 = 0.01001 1001 1001 1001……2 = 0.1001 1001 1001 1001 × 2-1 1001 1001 …… × 2 .

+ -1 1001 1001 1001 1001 ………

7

  • nly a portion of this part can be stored
slide-8
SLIDE 8

Number Conversion Revisited: 2/2 Number Conversion Revisited: 2/2

Moreover, integral and fraction parts should be Moreover, integral and fraction parts should be done separately. Thus, 277.3110 = 27710 + 0.3110. 277 = 115 and 0 31 = 0 4 F5C28 F5C28 27710 = 11516 and 0.3110 = 0.4 F5C28 F5C28 F5C28 …… 16. H 277 31 115 4 F5C28 F5C28 Hence, 277.3110 = 115.4 F5C28 F5C28 F5C28 …… 16 = 0.1154 F5C28 F6C28 F5C28 163 F5C28 …… × 163. + +3 1154 F5C28 F6C28 F5C28 ………

8

  • nly a portion of this part can be stored
slide-9
SLIDE 9

Overflow and Underflow : 1/2 Overflow and Underflow : 1/2

Due to finite precision, floating-point number p , g p calculations can cause overflow or underflow. Overflow and underflow mean the exponent p ±yyy of a number (in normal form) exceeds the limit of hardware’s capability. For example, if the hardware allows the exponent (base 16) in [-64,+64] , then 0.1×1670

70

causes overflow and 0.1×16-70 causes underflow. Computer hardware does report floating-point number over- and under- flow; but, usually integer over- and under- flows are ignored!

9

slide-10
SLIDE 10

Overflow and Underflow : 2/2 Overflow and Underflow : 2/2

One may use different formulas to avoid over- or y under- flow. Suppose we wish to compute . Even

c a b = +

2 2

pp p though the magnitude of c may be similar to the larger of a and b, a2 + b2 may cause overflow if one

  • f a or b is very large.

One way to overcome this is scaling the numbers down like the following, where k = MAX(|a|, |b|):

b ⎛ ⎞ ⎛ ⎞

2 2

Note that one of a/k and b/k is 1

c k a k b k = × ⎛ ⎝ ⎜ ⎞ ⎠ ⎟ + ⎛ ⎝ ⎜ ⎞ ⎠ ⎟

2 2

Note that one of a/k and b/k is 1. If a > b, a/k = 1 and |b/k| ≤ 1, and the number in SQRT() is small!

10

slide-11
SLIDE 11

Some Arithmetic Law s Do Not Hold Some Arithmetic Law s Do Not Hold

The commutative law holds; but, the associative The commutative law holds; but, the associative and distributive laws do not. Examples using 2 digit calculation Examples using 2-digit calculation.

Associative Law Fails Distributive Law Fails Associative Law Fails (0.12×0.34)×4 = 0.0408×4 0.041×4 (0.12 + 0.99)×5 = 1.11×5 1.1×5

(1.e-80 * 1.e+80)* 1.e+80 = 1.e+80 1.e-80 *(1.e+80 * 1.e+80)

= 0.164 0.16 0 12×(0 34×4) = 5.5 0.12×5 + 0.99×5 0 6 + 4 95

1.e 80 (1.e+80 1.e+80)

  • verflow

0.12×(0.34×4) = 0.12×1.36 0.12×1.4 = 0 168 = 0.6 + 4.95 0.6 + 5.0 = 5.6 very large exponent

11

= 0.168 0.17

slide-12
SLIDE 12

A Serious Failure: 1/2 A Serious Failure: 1/2

In an iterative computation, the next term xi+1 is In an iterative computation, the next term xi+1 is computed from xi using the following five mathematically equivalent forms, where x0 = 0.5 mathematically equivalent forms, where x0 0.5 and R = 3.0:

R R 1 ( ) ( ) x R x R x x x R x Rx x

i i i i i i i i

+ +

= + − = + −

1 1

1 1 ( ) ( ) ( ) ( ) x R x Rx x x R Rx x

i i i i i i i

+ +

+ = + −

1 1

1 1 ( ) ( ) (( ) ) x Rx Rx x x x R x x x

i i i i

+ =

+ − = +

1

1 ( ) ( )

12

x x R x x x

i i i i i

+ =

+ −

1

( )

slide-13
SLIDE 13

A Serious Failure: 2/2 A Serious Failure: 2/2

If we compute the values of xi up to the 1000th term and p

i

p display the results every 100 terms, we have the following shocking results due to the failure of the distributive law:

0 0.5 0.5 0.5 0.5 0.5 100 1 6782e 05 1 30277 0 506627 1 14111 0 355481 100 1.6782e-05 1.30277 0.506627 1.14111 0.355481 200 1.28383 0.97182 1.25677 1.04532 0.805295 300 0.745989 0.155282 1.32845 0.295785 0.0590719 400 0 0744125 0 354702 1 00514 0 882786 0 171617 400 0.0744125 0.354702 1.00514 0.882786 0.171617 500 0.788592 0.00176679 0.804004 0.496569 1.32348 600 0.0190271 0.35197 0.832942 0.518201 1.20776 700 0.377182 0.525322 0.31786 0.435079 0.525364 700 0.377182 0.525322 0.31786 0.435079 0.525364 800 0.1293 0.000277146 1.33159 0.0130949 0.954542 900 0.375104 0.00743761 1.27548 0.409476 0.00996984 1000 0.680855 1.03939 0.462035 0.0734742 1.26296

13

slide-14
SLIDE 14

Three Commonly Seen Issues Three Commonly Seen Issues

The following issues can cause significant The following issues can cause significant problems in numerical computation: Rounding Rounding Cancellation Recursion The next few slides will provide several examples.

14

slide-15
SLIDE 15

Rounding: Rounding: 1/4 1/4 Rounding: Rounding: 1/4 1/4

Because of finite number of significant digits, Because of finite number of significant digits, computed results may be rounded or truncated due to hardware design. due to hardware design. A rounding error in the optimal case is less than half of a unit in the last digit than half of a unit in the last digit. This introduces an error that may propagate to th t ti

  • ther computations.

The propagation of rounding errors is usually very complex and difficult to analyze.

15

slide-16
SLIDE 16

Rounding Rounding: 2/4 Rounding Rounding: 2/4

The following goes from 1 to 2 with step size 1/3 The following goes from 1 to 2 with step size 1/3 (i.e., 1, 1 1/3, 1 2/3, 2). However, it shows one more step (i.e., 5 steps)! more step (i.e., 5 steps)!

PROGRAM Rounding IMPLICIT NONE INTEGER, PARAMETER :: DOUBLE = SELECTED REAL KIND(15) , _ _ ( ) REAL(KIND=DOUBLE) :: a = 1.0_DOUBLE, b = 2.0_DOUBLE, x, h INTEGER :: n = 3 h (b )/ Output is h = (b - a)/n x = a WRITE(*,*) “x = ”, x DO x = 1.0 x = 1.3333333333333332 x = 1.6666666666666665 IF (x >= b) EXIT x = x + h WRITE(*,*) "x = ", x END DO x 1.6666666666666665 x = 1.9999999999999997 x = 2.333333333333333

1 1

16

END DO END PROGRAM Rounding rather than 1, , , 2

1 13 12 3

x < 2, so goes for one more iteration

slide-17
SLIDE 17

Rounding Rounding: 3/4 Rounding Rounding: 3/4

If b = 1.1, we have exactly four iterations! , y

PROGRAM Rounding IMPLICIT NONE INTEGER, PARAMETER :: DOUBLE = SELECTED_REAL_KIND(15) REAL(KIND=DOUBLE) :: a = 1.0 DOUBLE, b = 1.1 DOUBLE, x, h REAL(KIND DOUBLE) :: a 1.0_DOUBLE, b 1.1_DOUBLE, x, h INTEGER :: n = 3 h = (b - a)/n Output is x = a WRITE(*,*) “x = ”, x DO IF (x >= b) EXIT x = 1.0 x = 1.0333333333333334 x = 1 0666666666666668 IF (x > b) EXIT x = x + h WRITE(*,*) "x = ", x END DO i x = 1.0666666666666668 x = 1.1000000000000003 Now, it is correct!

17

END PROGRAM Rounding

slide-18
SLIDE 18

Rounding: Rounding: 4/4 Rounding: Rounding: 4/4

Suggestions: Suggestions: Use INTEGER to count the number of iterations This is the reason that REAL for

  • iterations. This is the reason that REAL for

counting DO-loop was dropped in Fortran 90. If one must use REAL for a counting DO loop If one must use REAL for a counting DO-loop, consider the use of IF (x >= b-h/2) EXIT where h=(b-a)/n is the step size. This would avoid the extra iteration.

18

slide-19
SLIDE 19

Cancellation: 1/8 Cancellation: 1/8

Cancellation usually occurs when subtracting two Cancellation usually occurs when subtracting two almost equal numbers. Suppose after rounding we have two numbers a = Suppose after rounding we have two numbers a = 1.243±0.0005 (i.e., a = 1.243∈[1.2425,1.2435]) and b = 1 234±0 0005 (i e b = 1 234∈[1 2335 1 2345]) = 1.234±0.0005 (i.e., b = 1.234∈[1.2335,1.2345]). Then, a – b = 0.009±0.001 (i.e., a-b = 0.009 ∈ [.008, 0 01] A lt th ibl f b i 0.01]. As a result, the possible range of a-b is very large, which may not be trust worthy. Moreover, the original 4-significant digits reduce to 1 significant digit only.

19

slide-20
SLIDE 20

Cancellation: 2/8 Cancellation: 2/8

Number representation contributes to cancellation. Number representation contributes to cancellation. Below we expect the result to be 4.111×10-12; but the subtraction yields 4 110933 ×10-12 but, the subtraction yields 4.110933...×10 . Only 3 to 4 digits can be trusted.

PROGRAM Cancellation IMPLICIT NONE INTEGER, PARAMETER :: DOUBLE = SELECTED_REAL_KIND(15) REAL(KIND=DOUBLE) :: x = 3.141592653589793 DOUBLE REAL(KIND=DOUBLE) :: x = 3.141592653589793_DOUBLE REAL(KIND=DOUBLE) :: y = 3.141592653585682_DOUBLE REAL(KIND=DOUBLE) :: z

  • utput

z = x - y WRITE(*,*) "x = ", x WRITE(*,*) "y = ", y WRITE(*,*) "x - y = ", z x = 3.141592653589793 y = 3.141592653585682 x - y = 4.11093381558203E-12

20

WRITE( , ) x y , z END PROGRAM Cancellation

slide-21
SLIDE 21

Cancellation: 3/8 Cancellation: 3/8

When subtracting two nearly equal values, we g y q , face loss of significant digits, an old story. Consider the solution to ax2 + bx + c = 0 with the textbook formula, where a = c = 1 and b =20000.

PROGRAM Eqn_2 IMPLICIT NONE IMPLICIT NONE REAL :: a = 1.0, b = 20000.0, c = 1.0, d, r1, r2 WRITE(*,*) "a = ", a WRITE(* *) "b = " b

a = 1.0

WRITE(*,*) "b = ", b WRITE(*,*) "c = ", c d = SQRT(b*b - 4.0*a*c) r1 = (-b + d)/(2 0*a)

b = 20000.0 c = 1.0 d 20000 0

r1 = (-b + d)/(2.0*a) r2 = (-b - d)/(2.0*a) WRITE(*,*) WRITE(*,*) "d = ", d WRITE(* *) "root 1 = " r1

d = 20000.0 root 1 = 0.0E+0 root 2 = -20000.0

This solution is obviously

21 WRITE(*,*) root 1 = , r1 WRITE(*,*) "root 2 = ", r2 END PROGRAM Eqn_2

s so ut o s obv ous y

  • incorrect. Why?
slide-22
SLIDE 22

Cancellation: 4/8 Cancellation: 4/8

Since a = 1, b = 20000 and c = 1, b2-4ac = Since a 1, b 20000 and c 1, b 4ac 400000000 – 4 ≈ 400000000 and (b2-4ac)1/2 ≈ b. As a result -b+(b2-4ac)1/2 would have a As a result, -b+(b -4ac) would have a cancellation issue. W id th b ll ti t l We may avoid the above cancellation to a large degree; but, due to the nature of the solution, ll ti i b2 4 i l id bl if b2 cancellation in b2-4ac is nearly unavoidable if b2 and 4ac are very close.

22

slide-23
SLIDE 23

Cancellation: 5/8 Cancellation: 5/8

We may take the following steps to avoid the We may take the following steps to avoid the subtraction, and hence cancellation: If b > 0 use b (b2-4ac)1/2 If b > 0, use –b – (b -4ac) If b < 0, use –b + (b2-4ac)1/2 In this way, no subtraction is performed, and

  • ne root is computed in a more reliable way.

Since the product of the roots is c/a in ax2+bx+c = 0, the other root can be computed with (c/a)/r1, where r1 is the root computed above.

23

slide-24
SLIDE 24

Cancellation: 6/8 Cancellation: 6/8

Here is a possible program: Here is a possible program:

PROGRAM Eqn_2 IMPLICIT NONE REAL :: a = 1.0, b = 20000.0, c = 1.0, d, r1, r2 WRITE(*,*) "a = ", a WRITE(*,*) "b = ", b WRITE(*,*) "c = ", c d = SQRT(b*b - 4.0*a*c) IF (b >= 0.0) THEN r1 = (-b - d)/(2.0*a)

a = 1.0 b = 20000.0 c = 1.0

ELSE r1 = (-b + d)/(2.0*a) END IF r2 = (c/a)/r1

d = 20000.0 root 1 = -20000.0 t 2 5 0E 5

WRITE(*,*) WRITE(*,*) "d = ", d WRITE(*,*) "root 1 = ", r1 WRITE(*,*) "root 2 = ", r2

root 2 = -5.0E-5

24 END PROGRAM Eqn_2

slide-25
SLIDE 25

Cancellation: 7/8 Cancellation: 7/8

A very useful formula to avoid cancellation is A very useful formula to avoid cancellation is a2 – b2 = (a-b)(a+b). For example if x ≈ 0 then (x + 1)1/2 1 will have For example, if x ≈ 0, then (x + 1) – 1 will have cancellation because (x+1)1/2 ≈ 1 . Th f ll i li i t th bt ti The following eliminates the subtraction:

( )

2

1 1 1 1 x +

( ) ( )

1 1 1 1 1 1 1 1 1 1 1 1 1 1 x x x x x x x x + − + + + − = + − × = = + + + + + +

If x = 0.0000001, on a 7-digit computer the

  • riginal form yields 0 (why?) and the

25

  • riginal form yields 0 (why?) and the

transformed form has 0.00000005!

slide-26
SLIDE 26

Cancellation: 8/8 Cancellation: 8/8

Let us try one more example. y p Evaluating (1-cos(x))/sin(x) if x ≈ 0 would cause cancellation because cos(x) ≈ 1. Applying a2 – b2 = (a-b)(a+b) yields the following:

2

1 cos( ) 1 cos( ) 1 cos( ) 1 cos ( ) sin( ) x x x x x − − + − 1 cos( ) 1 cos( ) 1 cos( ) 1 cos ( ) sin( ) sin( ) sin( ) 1 cos( ) sin( ) (1 cos( )) 1 cos( ) x x x x x x x x x x x + = × = = + × + +

Since there is no subtraction when x ≈ 0, there is no cancellation. Al d b t t li i t bt ti i Always do your best to eliminate subtractions in your program when the operands are nearly equal!

26

slide-27
SLIDE 27

Recursion Recursion

Many numerical algorithms compute a new Many numerical algorithms compute a new entity based on the previous ones with either an iterative or a recursive method. iterative or a recursive method. In both cases, errors can accumulate and eventually destroy the computation eventually destroy the computation. We have seen this when discussing the failure of th i ti d di t ib ti l the associative and distributive laws.

27

slide-28
SLIDE 28

Examples (Variance): 1/4 Examples (Variance): 1/4

The sample variance of n values x1, x2, …, xn is The sample variance of n values x1, x2, …, xn is defined as follows, where m is the sample mean:

n

1 s n x m

i i 2 2 1

1 1 = − −

=

∑ (

)

An alternative, theoretically equivalent, faster

  • ne-pass formula is:

s x x

i i n n 2 2 2

1 1 1 = − ⎛ ⎝ ⎜ ⎞ ⎠ ⎡ ⎢ ⎢ ⎤ ⎥ ⎥

∑ ∑

Whi h i b tt ?

n n

i i 1 1

1 − ⎝ ⎠ ⎣ ⎢ ⎦ ⎥

= =

∑ ∑

28

Which one is better?

slide-29
SLIDE 29

Examples (Variance): 2/4 Examples (Variance): 2/4

Consider x1 = 100000000, x2 = 100000001 and x3 Consider x1 100000000, x2 100000001 and x3 = 100000002. Since the mean value is m = 100000001, variance is s2 = 1. 100000001, variance is s 1. If you try these values with a statistical package, say Microsoft Excel the result may be s2 = 0! say Microsoft Excel, the result may be s = 0! The ghost of cancellation. The system may use th f l Si d

2

( )

x n

2 /

the one-pass formula. Since and are similar in magnitude when the input values l (d ’t f t di /t ti ) th

xi

2

( )

x n

i

/

are large (don’t forget rounding/truncation), the subtraction can yield a zero!

29

slide-30
SLIDE 30

Examples (Variance): 3/4 Examples (Variance): 3/4

Use the two-pass formula, because it always Use the two pass formula, because it always delivers good results unless n is very large. The one-pass formula although more efficient The one-pass formula, although more efficient than the two-pass one, can suffer from cancellation cancellation. It may also suffer from overflow! Where? This is an important lesson for you to rewrite and use formulas wisely and carefully.

30

slide-31
SLIDE 31

Examples (Variance): 4/4 Examples (Variance): 4/4

Item Exact Computed

1 x1

9000000

2 x2

9000001

3

9000002

3 x3

9000002

4 x1 + x2 + x3

27000003 27000000

5 (x1 + x2 + x3)2

729000000000000

5 (x1 + x2 + x3) 6 (x1 + x2 + x3)2/3

243000000000000

7 x1

2

81000000000000 81000000000000

8 x2

2

81000018000001 81000020000000

9 x3

2

81000036000004 81000040000000

10

2 + 2 + 2

243000060000000 243000100000000

10 x1

2 + x2 2 + x3 2

243000060000000 243000100000000

11 (10)-(5)

100000000

12 Variance=(11)/2

50000000

31

12 Variance (11)/2 Blue color: 7 significant digits

slide-32
SLIDE 32

Example (Average) Example (Average)

Computing average may also have problems. Computing average may also have problems. The following shows the result of computing the average of 5 01 and 5 03 with a 3-digit average of 5.01 and 5.03 with a 3-digit computer. Th lt i t id f th i t d i The result is outside of the input range, and is

  • bviously wrong, although it is accurate!

Finite precision is not always friendly.

(5.01 + 5.03)/2 = 10.04/2 10.0/2

32

10.0/2 = 5.0

slide-33
SLIDE 33

Example (Sum): 1/3 Example (Sum): 1/3

In fact, computing x1 + x2 + … + xn accurately In fact, computing x1 x2 … xn accurately and reliably is not easy. There was an extensive research in late 1960’s There was an extensive research in late 1960 s and early 1970’s. H i t ti d ti Here are some interesting and easy summation methods and comments without proofs. A typical summation procedure looks like this:

sum = 0 0 sum = 0.0 DO i = 1, n sum = sum + xi END DO

33

END DO

slide-34
SLIDE 34

Example (Sum): 2/3 Example (Sum): 2/3

Sort the data values so that |x1| ≤ |x2| ≤ |x3| ≤ … ≤ Sort the data values so that |x1| ≤ |x2| ≤ |x3| ≤ … ≤ |xn| or |x1| ≥ |x2| ≥ |x3| ≥ … ≥ |xn|, and use this

  • rder for summation.
  • rder for summation.

Pair-wise summation looks like a form of binary tree Adjacent values are summed until only one

  • tree. Adjacent values are summed until only one

value remains. Thus, x1 + x2 + x3 + x4 + x5 + x6 is computed as y = x + x y = x + x and y = x + computed as y1 = x1 + x2, y2 = x3 + x4 and y3 = x5 + x6, followed by z1 = y1 + y2, followed by s = z1 + y3. I ti ti If d t l t d i Insertion summation: If data values are sorted in some other, the sum of the first two values is i t d i t th li t til l l i

34

inserted into the list until only one value remains.

slide-35
SLIDE 35

Example (Sum): 3/3 Example (Sum): 3/3

There are other more advanced and more There are other more advanced and more complex summation algorithms. In general if all values are non-negative the In general, if all values are non-negative, the increasing order with a simple DO-loop, perhaps using higher precision is good enough using higher precision, is good enough. The pair-wise summation has a smaller error bound than that of the simple DO loop bound than that of the simple DO-loop.

35

slide-36
SLIDE 36

“Real” Problems: 1-1/2 Real Problems: 1 1/2

The Patriot missile is designed to operate a few The Patriot missile is designed to operate a few hours at one location to avoid detection. The incoming missile’s velocity is a floating- The incoming missile s velocity is a floating- point (i.e., REAL) number. Th i t l l k f th P t i t i il i The internal clock of the Patriot missile is an INTEGER with unit of 1/10 sec. This INTEGER l i lti li d b 0 1 24 bit bi value is multiplied by 0.110 as a 24-bit binary value before its use. The precision error is 9 5×10-8 i th i f t (D ll 9.5×10-8 in the conversion factor. (Do you recall this fact: 0.110 = 0.0001100110011….2?)

36

slide-37
SLIDE 37

“Real” Problems: 1-2/2 Real Problems: 1 2/2

The inaccuracy of the target’s position is The inaccuracy of the target s position is proportional to the product of the target velocity and the length of time the system has been and the length of time the system has been running. With the system up and running for 100 hours With the system up and running for 100 hours and a velocity of 1676 meters per second, an error of 573 meters is obtained error of 573 meters is obtained. As a result, a Scud missile was not intercepted f ll d kill d 28 ldi F b successfully and killed 28 soldiers on February 25, 1991, at Dhahran, Saudi Arabia.

37

slide-38
SLIDE 38

“Real” Problems: 2 Real Problems: 2

Vancouver Stock Exchange updated its index Vancouver Stock Exchange updated its index after each transaction. The index with 3 decimals was updated and The index, with 3 decimals, was updated and truncated. Aft 22 th th i d h d f ll f th After 22 months, the index had fallen from the initial value 1000.000 to 524.881; but, the tl l t d i d 1098 811 correctly evaluated index was 1098.811. This happened in 1982.

38

slide-39
SLIDE 39

“Real” Problems: 3 Real Problems: 3

On June, 1996, an unmanned Ariane 5 rocket On June, 1996, an unmanned Ariane 5 rocket launched by the European Space Agency exploded 40 seconds after lift-off from Kourou, exploded 40 seconds after lift off from Kourou, French Guiana. The failure was caused by the conversion of a 64- The failure was caused by the conversion of a 64- bit floating-point number to a 16-bit signed integer. A 16 bit i d i t i i th f 32768 A 16-bit signed integer is in the range of -32768 and 32767, and a 64 floating-point number can b l th 32767! be larger than 32767!

39

slide-40
SLIDE 40

“Real” Problems: 4 Real Problems: 4

In September, 1997, a crew member of the USS In September, 1997, a crew member of the USS Yorktown mistakenly entered a zero for a data value. value. This caused a division by zero, and the error cascaded and eventually shut down the ship’s cascaded and eventually shut down the ship s propulsion system. Th hi d d i th t f 2 h d The ship was dead in the water for 2 hours and 45 minutes.

40

slide-41
SLIDE 41

Some Commonly Used Terms Some Commonly Used Terms

Precision: the number of digits used for arithmetic Precision: the number of digits used for arithmetic and I/O Accuracy: the absolute or relative error of an Accuracy: the absolute or relative error of an approximate quantity. More on this later. R li bilit h “ ft ” ( t ) th Reliability: how “often” (as a percentage) the computation fails, in the sense that the true error is l th h t i t d larger than what is requested. Robustness: how “gracefully” the computation fails and its sensitivity to small changes in the problem. Stability: a method is stable if it guarantees as

41

accurate a solution as the data warrants.

slide-42
SLIDE 42

Absolute/Relative Error Absolute/Relative Error

Let x and x* be the computed value and true Let x and x be the computed value and true value. Absolute error is |x x*| Absolute error is |x – x | Relative error is |x – x*|/|x*| If the relative error is less than 1, -log10(|x – x*|/|x*|) gives the number of significant decimal Wh Wh ? digits in the computed value. Wh Why? Normally, relative error is not very useful if x* is close to zero. Thus, use relative error if |x – x*| ≥ 1. Otherwise, use absolute error.

42

slide-43
SLIDE 43

Condition: 1/3 Condition: 1/3

The condition of a problem is the sensitivity of p y the problem to perturbations in the data. A Problem is ill-conditioned if small changes in g the data can cause relatively large changes in the

  • solution. Otherwise, the problem is well-

conditioned. Note that condition is about the sensitivity of the problem and is independent of the method being used to solve the problem.

43

slide-44
SLIDE 44

Condition: 2/3 Condition: 2/3

The cubic equation x3-21x2+120x-100=0 has The cubic equation x 21x 120x 100 0 has roots x1=1, x2=x3=10. If the coefficient of x3 is perturbed to become If the coefficient of x is perturbed to become 0.99x3-21x2+120x-100=0, the roots are x1=1, x ≈11 17 x ≈9 041 x2≈11.17, x3≈9.041. If the coefficient of x3 is perturbed to become 1 01 3 21 2+120 100 0 th t 1 1.01x3-21x2+120x-100=0, the roots are x1=1, x2, x3≈9.896±1.044i. So, roots x2 and x3 are ill-conditioned; but, we cannot deduce the condition of root x1.

44

slide-45
SLIDE 45

Condition: 3/3 Condition: 3/3

The following system of linear equations has The following system of linear equations has solutions x1 = x2 = 1

99 98 197 ⎡ ⎤⎡ ⎤ ⎡ ⎤ x 99 98 100 99 197 199

1 2

⎡ ⎣ ⎢ ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ = ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ x x

If the upper-left corner value is perturbed as follows, the solutions are x1=100, x2=-99.

9899 98 100 99 197 199

1 2

. ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ = ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ x x

The problem is ill-conditioned.

2

⎣ ⎦⎣ ⎦ ⎣ ⎦

45

slide-46
SLIDE 46

Food for Thought (1) Food for Thought (1)

The following compensated summation The following compensated summation algorithm is due to Kahan (1965). There are other more advanced and better There are other more advanced and better methods.

sum = 0.0 ! computed sum c = 0.0 ! correction (i.e., a+b=sum+c) DO i = 1, n DO i 1, n temp = sum ! save the sum y = xi + c ! compensate xi sum = temp + y ! add the compensated to sum p y p c = (temp – sum) + y ! compute the new correction END DO Wh d ’ i i i !

46

Why don’t you write a program to give it a try!

slide-47
SLIDE 47

Food for Thought (2): 1/2 Food for Thought (2): 1/2

In computing the sample mean , it is

( )

x n

i n =

1

/

In computing the sample mean , it is possible that the summation could cause

  • verflow.

( )

i=

1

  • verflow.

There are so-called “updating formulas” for computing the mean so that overflow and other computing the mean so that overflow and other problems can be avoid to a large degree. L t (i i th f ( )/

k

k

Let (i.e., mk is the mean of x1, x2, …, xk). ( )

1

/

k i i

m x k

=

= ∑

The following is a possible updating formula. Prove it yourself.

47

( )

1 1

1

k k k k

m m x m k

− −

= + −

slide-48
SLIDE 48

Food for Thought (2): 2/2 Food for Thought (2): 2/2

There are updating formulas for computing the There are updating formulas for computing the sample variance. Let S be the sample variance of x x x Let Sk be the sample variance of x1, x2, …, xk. Here is a possible updating formula:

⎛ ⎞ S S k x m x m k

k k k k k k

= + − − − ⎛ ⎝ ⎜ ⎞ ⎠ ⎟

− − −

1 1 1

1 ( )( ) Prove the correctness yourself. These updating formulas for computing the These updating formulas for computing the sample mean and variance are more stable than the on-pass textbook formulas.

48

e o p ss e boo

  • u s.
slide-49
SLIDE 49

The End The End

49