What is The Error ?
How did it happen ?




                      1
Definition
• The Error in a computed quantity is defined
  as:

     Error = True Value – Approximate Value




                                                2
Examples:
a. True Value : phi = 3.14159265358979
    Appr. Value : 22/7 = 3.14285714285714
    Error = phi-22/7= -0.00126448926735
b. True Value : 12
   Appr. Value: 11.78
   Error = 12-11.78 = 0.22
c. True Value : 100
   Appr. Value: 95.5
   Error = 100-95.5 = 4.5
                                            3
Kind of Error
• The Absolute Error is measure the
  magnitude of the error
              Ea     Error
• The Relative Error is a measure of the error
  in relation to the size of the true value
                       Ea
            Er
                   True Value
                                             4
Examples
• True value : 10      Ea = 10-9 = 1
  Appr. Value : 9      Er = Ea/ 10 = 0.1
           Ea    1,     Er    0 .1

• True value : 1000    Ea = 1000-999= 1
  Appr. Value : 999    Er =Ea/1000=0.001
           Ea    1,     Er    0 . 001
• True value : 250     Ea =250-240= 10
  Appr. Value : 240    Er = Ea/250= 0.04
           Ea   10 ,     Er    0 . 04      5
Sources of Error

a.Truncation Error
b.Rounding Error


                         6
a. Truncation Error
• errors that result from using an approximation
  in place of an exact mathematical procedure




                                                   7
Example of Truncation Error
Taking only a few terms of a Maclaurin series to
approximate    e
                 x

                            2           3
         x              x       x
     e       1   x                          .......... ..........
                        2!      3!

 If only 3 terms are used,
                                                          2
                                    x                 x
   Truncation        Error      e           1   x
                                                      2!


                                        8
Example 1 —Maclaurin series
Calculate the value of e with an absolute
                                                               1 .2


relative approximate error of less than 1%.
                                        2          3
        1 .2                     1 .2       1 .2
    e          1       1 .2                                .......... .........
                                   2!         3!

    n                  1 .2
                                   Ea                      %
                   e                                   a

    1                    1                    __                            ___
    2                    2.2                  1.2                           54.545
    3                    2.92                 0.72                          24.658
    4                    3.208                0.288                         8.9776
    5                    3.2944               0.0864                        2.6226
    6                    3.3151               0.020736                      0.62550


                                    6 terms are required.
                                            9
Example 2 —Differentiation
                                                                                            f (x   x)       f ( x)
Find                  for                            using
                                                2
            f ( 3)             f ( x)       x                               f ( x)
                                                                                                    x
and         x        0 .2
            '         f (3    0 .2 )       f (3)
        f (3)
                                0 .2
                                                           2           2
                      f (3 .2 )    f (3)            3 .2           3              10 . 24     9    1 . 24
                                                                                                                6 .2
                             0 .2                       0 .2                          0 .2          0 .2

The actual value is
        '                       '
       f ( x)    2 x,         f (3)        2        3          6

Truncation error is then,                                      6           6 .2         0 .2

                                                10
Example 3 — Integration
Use two rectangles of equal width to approximate
the area under the curve for
        x over the interval [ 3,9 ]
         2
 f ( x)
       y

  90
                                        9
                 y = x2                      2
  60
                                            x dx
  30                                    3

  0                                 x
       0     3    6       9    12

                          11
Integration example (cont.)
Choosing a width of 3, we have
     9
          2           2                                            2
         x dx    (x )               (6           3)           (x )            (9   6)
                              x 3                                       x 6
     3
                      2                  2
                 (3 )3              ( 6 )3
                 27           108        135

Actual value is given by
     9                        9
                          3                  3            3
          2       x                      9            3
         x dx                                                          234
     3                3       3
                                                 3

Truncation error is then
     234        135            99
                                                              12
b. Rounding Errors
• Round-off / Chopping Errors

• Recognize how floating point arithmetic operations
  can introduce and amplify round-off errors

• What can be done to reduce the effect of round-off
  errors
                         13
There are discrete points on the
     number lines that can be
     represented by our computer.
     How about the space between ?



14
Implication of FP representations
• Only limited range of quantities may be
  represented.
  – Overflow and underflow

• Only a finite number of quantities within the range
  may be represented.
  – round-off errors or chopping errors




                             15
Round-off / Chopping Errors
              (Error Bounds Analysis)
Let
   z be a real number we want to represent in a computer, and
   fl(z) be the representation of z in the computer.


What is the largest possible value of                              ?
                                                               z       fl ( z )
                                                                     z
i.e., in the worst case, how much data are we losing due to round-off or chopping
     errors?


                                          16
Chopping Errors (Error Bounds Analysis)
Suppose the mantissa can only support n digits.
                                                         e
z      0 .a1a 2  a n a n 1a n       2
                                                            ,           a1    0
                                              e
fl ( z )         0 .a1a 2  a n

Thus the absolute and relative chopping errors are
                                                                 e                              e n
z    fl ( z )       ( 0 .00 ... 0 a n 1 a n
                          
                                                 2
                                                    )                   ( 0 .a n 1a n   2
                                                                                           )
                         n zeroes
                                                                     e
z     fl ( z )         ( 0 . 00 ... 0 a n 1 a n     2
                                                      )
                                                                         e
     z               ( 0 .a 1a 2  a n a n 1a n      2
                                                       )

Suppose ß = 10 (base 10), what are the values of ai such that
the errors are the largest?
                                                         17
Chopping Errors (Error Bounds Analysis)

 Because               0 .a n 1a n 2 a n     3
                                                               1
                                                          e n        e n                          e n
 z      fl ( z )       0 .a n 1a n     2
                                                                                  z   fl ( z )

                                                                         e
 z      fl ( z )         0 . 00 ... 0 a n 1 a n           2
                                                            
                                                                             e
        z              0 .a 1a 2  a n a n 1a n             2
                                                              
                          e n

                                                      e
     0 .a1a 2  a n a n 1a n          2
                                        
                         e n

                                                 e
     0 .100000 a n 1 a n
                              2
                                   
            n digits

            e n                 e n
                                                     e n ( e 1)              1 n
                                                                                   z   fl ( z )   1 n
                   e        1         e
     0 .1                                                                              z
                                                                    18
Round-off Errors (Error Bounds Analysis)

                                                    e
z            0 .a 1 a 2  a n a n   1
                                                       ,   a1       0

           1 ( sign )               base    e       exponent


                                           e
                 ( 0 .a 1 a 2  a n )                                    0     an    1
                                                                                             2
fl ( z )                                                                     Round down

                                                                 e
                 [( 0 .a 1 a 2  a n )     ( 0 ) ]
                                             00 ...
                                              .     01                          an       1
                                                        n                2
                                                                              Round up

fl(z) is the rounded value of z
                                               19
Round-off Errors (Error Bounds Analysis)
Absolute error of fl(z)
When rounding down
                                                                              e
 z   fl ( z )                0 . 00  0 a n 1 a n        a
                                                        2 n    3
                                                                 
                                                                    e n
                             0 .a n 1 a n     a
                                             2 n   3
                                                     
                                                              e n
 z       fl ( z )   0 .a n 1 a n      a
                                     2 n     3
                                               

                                         1                                                    1   e n
an   1
                    (. a n   1
                               )                                          z       fl ( z )
               2                         2                                                    2

Similarly, when rounding up
                                                                                              1
i.e., when                      an   1                                    z        fl ( z )
                                                                                                  e n

                       2                                                                      2
                                                   20
Round-off Errors (Error Bounds Analysis)
Relative error of fl(z)
                   1     e n
  z   fl ( z )
                   2
                              n
  z   fl ( z )     1
                                  e
      z            2 z
                                      n
                   1                                                                       e
                                           because       z          (. a 1 a 2  )
                   2 (. a 1 a 2  )
                             n
                   1
                                           because       (. a 1 )        ( 0 . 1)
                   2 (. 1)
                          n
                   1
                   2
                          1                     z    fl ( z )               1        1 n

                                                     z                      2

                                          21
Summary of Error Bounds Analysis
                 Chopping Errors                 Round-off errors
 Absolute                             e n                               1       e n
                     z    fl ( z )                  z       fl ( z )
                                                                        2

 Relative            z    fl ( z )    1 n
                                                        z    fl ( z )       1    1 n

                          z                                  z              2

 β       base
 n       # of significant digits or # of digits in the mantissa

Regardless of chopping or round-off is used to round the numbers,
the absolute errors may increase as the numbers grow in magnitude
but the relative errors are bounded by the same magnitude.

                                      22

Chap 1

  • 1.
    What is TheError ? How did it happen ? 1
  • 2.
    Definition • The Errorin a computed quantity is defined as: Error = True Value – Approximate Value 2
  • 3.
    Examples: a. True Value: phi = 3.14159265358979 Appr. Value : 22/7 = 3.14285714285714 Error = phi-22/7= -0.00126448926735 b. True Value : 12 Appr. Value: 11.78 Error = 12-11.78 = 0.22 c. True Value : 100 Appr. Value: 95.5 Error = 100-95.5 = 4.5 3
  • 4.
    Kind of Error •The Absolute Error is measure the magnitude of the error Ea Error • The Relative Error is a measure of the error in relation to the size of the true value Ea Er True Value 4
  • 5.
    Examples • True value: 10 Ea = 10-9 = 1 Appr. Value : 9 Er = Ea/ 10 = 0.1 Ea 1, Er 0 .1 • True value : 1000 Ea = 1000-999= 1 Appr. Value : 999 Er =Ea/1000=0.001 Ea 1, Er 0 . 001 • True value : 250 Ea =250-240= 10 Appr. Value : 240 Er = Ea/250= 0.04 Ea 10 , Er 0 . 04 5
  • 6.
    Sources of Error a.TruncationError b.Rounding Error 6
  • 7.
    a. Truncation Error •errors that result from using an approximation in place of an exact mathematical procedure 7
  • 8.
    Example of TruncationError Taking only a few terms of a Maclaurin series to approximate e x 2 3 x x x e 1 x .......... .......... 2! 3! If only 3 terms are used, 2 x x Truncation Error e 1 x 2! 8
  • 9.
    Example 1 —Maclaurinseries Calculate the value of e with an absolute 1 .2 relative approximate error of less than 1%. 2 3 1 .2 1 .2 1 .2 e 1 1 .2 .......... ......... 2! 3! n 1 .2 Ea % e a 1 1 __ ___ 2 2.2 1.2 54.545 3 2.92 0.72 24.658 4 3.208 0.288 8.9776 5 3.2944 0.0864 2.6226 6 3.3151 0.020736 0.62550 6 terms are required. 9
  • 10.
    Example 2 —Differentiation f (x x) f ( x) Find for using 2 f ( 3) f ( x) x f ( x) x and x 0 .2 ' f (3 0 .2 ) f (3) f (3) 0 .2 2 2 f (3 .2 ) f (3) 3 .2 3 10 . 24 9 1 . 24 6 .2 0 .2 0 .2 0 .2 0 .2 The actual value is ' ' f ( x) 2 x, f (3) 2 3 6 Truncation error is then, 6 6 .2 0 .2 10
  • 11.
    Example 3 —Integration Use two rectangles of equal width to approximate the area under the curve for x over the interval [ 3,9 ] 2 f ( x) y 90 9 y = x2 2 60 x dx 30 3 0 x 0 3 6 9 12 11
  • 12.
    Integration example (cont.) Choosinga width of 3, we have 9 2 2 2 x dx (x ) (6 3) (x ) (9 6) x 3 x 6 3 2 2 (3 )3 ( 6 )3 27 108 135 Actual value is given by 9 9 3 3 3 2 x 9 3 x dx 234 3 3 3 3 Truncation error is then 234 135 99 12
  • 13.
    b. Rounding Errors •Round-off / Chopping Errors • Recognize how floating point arithmetic operations can introduce and amplify round-off errors • What can be done to reduce the effect of round-off errors 13
  • 14.
    There are discretepoints on the number lines that can be represented by our computer. How about the space between ? 14
  • 15.
    Implication of FPrepresentations • Only limited range of quantities may be represented. – Overflow and underflow • Only a finite number of quantities within the range may be represented. – round-off errors or chopping errors 15
  • 16.
    Round-off / ChoppingErrors (Error Bounds Analysis) Let z be a real number we want to represent in a computer, and fl(z) be the representation of z in the computer. What is the largest possible value of ? z fl ( z ) z i.e., in the worst case, how much data are we losing due to round-off or chopping errors? 16
  • 17.
    Chopping Errors (ErrorBounds Analysis) Suppose the mantissa can only support n digits. e z 0 .a1a 2  a n a n 1a n 2  , a1 0 e fl ( z ) 0 .a1a 2  a n Thus the absolute and relative chopping errors are e e n z fl ( z ) ( 0 .00 ... 0 a n 1 a n    2 ) ( 0 .a n 1a n 2 ) n zeroes e z fl ( z ) ( 0 . 00 ... 0 a n 1 a n 2 ) e z ( 0 .a 1a 2  a n a n 1a n 2 ) Suppose ß = 10 (base 10), what are the values of ai such that the errors are the largest? 17
  • 18.
    Chopping Errors (ErrorBounds Analysis) Because 0 .a n 1a n 2 a n 3  1 e n e n e n z fl ( z ) 0 .a n 1a n 2  z fl ( z ) e z fl ( z ) 0 . 00 ... 0 a n 1 a n 2  e z 0 .a 1a 2  a n a n 1a n 2  e n e 0 .a1a 2  a n a n 1a n 2  e n e 0 .100000 a n 1 a n  2  n digits e n e n e n ( e 1) 1 n z fl ( z ) 1 n e 1 e 0 .1 z 18
  • 19.
    Round-off Errors (ErrorBounds Analysis) e z 0 .a 1 a 2  a n a n 1  , a1 0 1 ( sign ) base e exponent e ( 0 .a 1 a 2  a n ) 0 an 1 2 fl ( z ) Round down e [( 0 .a 1 a 2  a n ) ( 0 ) ] 00 ... . 01 an 1 n 2 Round up fl(z) is the rounded value of z 19
  • 20.
    Round-off Errors (ErrorBounds Analysis) Absolute error of fl(z) When rounding down e z fl ( z ) 0 . 00  0 a n 1 a n a 2 n 3  e n 0 .a n 1 a n a 2 n 3  e n z fl ( z ) 0 .a n 1 a n a 2 n 3  1 1 e n an 1 (. a n 1 ) z fl ( z ) 2 2 2 Similarly, when rounding up 1 i.e., when an 1 z fl ( z ) e n 2 2 20
  • 21.
    Round-off Errors (ErrorBounds Analysis) Relative error of fl(z) 1 e n z fl ( z ) 2 n z fl ( z ) 1 e z 2 z n 1 e because z (. a 1 a 2  ) 2 (. a 1 a 2  ) n 1 because (. a 1 ) ( 0 . 1) 2 (. 1) n 1 2 1 z fl ( z ) 1 1 n z 2 21
  • 22.
    Summary of ErrorBounds Analysis Chopping Errors Round-off errors Absolute e n 1 e n z fl ( z ) z fl ( z ) 2 Relative z fl ( z ) 1 n z fl ( z ) 1 1 n z z 2 β base n # of significant digits or # of digits in the mantissa Regardless of chopping or round-off is used to round the numbers, the absolute errors may increase as the numbers grow in magnitude but the relative errors are bounded by the same magnitude. 22