You are on page 1of 10

Plan

Plan

Civil Engineering Analysis II: CIV E 295


1

Youssef Belhamadia

Chapter 1 : Roundo and Truncation Errors Introduction Errors Truncation Errors Roundo Errors

7 janvier 2014

p. 1

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 2

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Plan

Comments

Chapter 1 : Roundo and Truncation Errors Introduction Errors Truncation Errors Roundo Errors

p. 3

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 4

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Introduction
What are numerical methods and why should you study them ?
Example 1 The roots of the quadratic formula ax 2 + bx + c = 0 are : b b2 4ac b + b2 4ac and x2 = . x1 = 2a 2a 2 1. Consider x 3x + 2 = 0 and try to nd x1 : a) First method : b + b2 4ac = 2. x1 = 2a b) Second method : b + b2 4ac b b2 4ac x1 = 2a b b2 4ac x1 = b 2c = 2. b2 4ac

Comments

The exact roots are x1 = 2 and x2 = 1.


p. 5 c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 6

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Introduction
What are numerical methods and why should you study them ? Example 1 Consider x 2 + 62.10x + 1 = 0, try to nd x1 using four digit rounding :
1

Comments

2.000 2c = 0.016 = 60.10 62.06 b b2 4ac The exact roots are x1 = 0.01610723 and x2 = 62.08390. x1 =
p. 7 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 8 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

First method : b + b2 4ac 62.10 + 62.06 x1 = = = 0.020 2a 2.000 . Second method : b b2 4ac b + b2 4ac x1 = 2a b b2 4ac

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Introduction
Example 2 Evaluate f (x ) = x 3 6.1x 2 + 3.2x + 1.5 at x = 4.71 using three digit (rounding).
1

Comments

First method : f (4.71) = (4.71)3 6.1(4.71)2 + 3.2(4.71) + 1.5 f (4.71) = 105. 135. + 15.1 + 1.5 = 13.4

Second method : f (x ) = x 3 6.1x 2 + 3.2x + 1.5 = ((x 6.1)x + 3.2)x + 1.5 f (4.71) = 14.2

The exact value is -14.263899. Question : How many additions and multiplications are in the above two methods ?
p. 9 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 10 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Introduction
Example 3
1
1

Comments

Can you give the exact value of the integral


0 1

e (x ) dx ? e (x ) dx ?
2

Can you give the exact value of the integral


0

The second integral exists but has a value that cannot be expressed in a simple form. Using numerical method we may obtain the following two values
1 0

e (x ) dx = 0.746809163 or
0

e (x ) dx = 0.746824133,

but which one is most accurate ?


p. 11 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 12 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Introduction

Chapter 1 : Roundo and Truncation Errors

Introduction

Introduction

Comments

What are numerical methods and why should you study them ?
1

Numerical methods are capable to solve (or provide an answer) nonlinearities, large systems of equations, and complicated geometries that are common in engineering and science and that are impossible to solve analytically. Numerical methods are an ecient tools for learning to use computers.

p. 13

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 14

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Plan

Comments

Chapter 1 : Roundo and Truncation Errors Introduction Errors Truncation Errors Roundo Errors

p. 15

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 16

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Introduction

Comments

Mathematical approximation and digital computers cause uncertain results. Engineers need constantly to accomplish objectives and make decision based on uncertain results. Is it possible to understand, quantify and control such errors in order to obtain acceptable results ?

p. 17

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 18

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Accuracy and Precision


Accuracy and precision are synonyms. However, they are completely dierent Denition
1

Comments

Accuracy refers to how closely a computed or measured value agrees with the true or actual value. Precision refers to how closely a series of values agree or consistent with each other.

a) inaccurate and imprecise b) accurate and imprecise c) inaccurate and precise d) accurate and precise See gure 4.1 page 90 in the textbook.

p. 19

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 20

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Error Denitions
Denition
Consider u as the true value and v is as an approximation to u
1

Comments

True error, Et , is the dierence between the true value and the approximation. True error = Et = u v Absolute error, |Et |, is the absolute dierence between the true value and the approximation. Absolute error = |Et | = |u v |

Relative error is Relative error =

uv u

True percent relative error,

t,

is
t

True percent relative error =


p. 21

uv 100% u
p. 22 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

E and

are subscripted with a t to signify that the error is based on

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Error Denitions
Example Consider the true value of a bridge as u = 10000cm and the approximate value is v = 9999cm . Consider the true value of a rivet as = 10cm and the approximate value is v = 9cm . For both the true error is Et = 1cm . However, when look at their percent relative errors :
Bridge :
t

Comments

= =

uv 100% = 0.01% u uv 100% = 10% u

Rivet
t

The bridge measurement is more accurate.


p. 23 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 24 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Error Denitions
Denition
In numerical methods and real-world applications, the true answer is rarely known. In this situation an alternative error is used
1

Comments

Approximate percent relative error u v 100%, a = u where u is the present approximation and v is the previous approximation.

When performing computations, the computation is repeated until stopping criterion is satised | a| < s, where
s

is a prespecied tolerance.

We can be assured that the result is correct to at least n signicant gures, if 2n % s = 0.5 10
c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 26 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

p. 25

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Error Denitions
Example
Estimate e 0.5 to three signicant gures
1 2

Comments

Tylor formula for e x at x = 0 ex = 1 + x +

= 0.5 1023 = 0.05%

x2 xn + + + 2! n!

3 4

For n = 0 e x =1 = 1 = e 0.5 x For n = 1 e = 1 + x = e 0.5 = 1 + 0.5 = 1.5 | a| =

1.5 1 u v 100% = 100% = 33.3% u 1.5

5 6

for n = 2 e 0.5 = | a| = 0 .5 for n = 3 e = | a | =


c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 28 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

p. 27

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Error Denitions
Example n 0 1 2 3 4 5 Approximation of e 0.3 e 0 .5 | t| | a| = 1 39.3 1.5 9.02 33.3 1.625 1.44 7.69 1.645833333 0.175 1.27 1.648437500 0.0172 0.158 1.648697917 0.00142 0.0158
s

Comments

After six terms, the approximate error falls below the computation is terminated. The exact value is e 0.5 = 1.648721
p. 29 c Youssef Belhamadia

= 0.05%, and

Civil Engineering Analysis II: CIV E 295

p. 30

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Errors

Chapter 1 : Roundo and Truncation Errors

Errors

Errors

Comments

They are two major forms of numerical errors :


1

Roundo error (due to computer approximations). Truncation error (due to mathematical approximations).

The Taylor series is a very good example to express the idea of truncation error mathematically.

p. 31

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 32

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Plan

Comments

Chapter 1 : Roundo and Truncation Errors Introduction Errors Truncation Errors Roundo Errors

p. 33

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 34

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Tylor Series
Taylor Theorem The Taylor theorem states that any smooth function can be approximated as a polynomial. f (n ) (xi ) n f (xi ) 2 f (3) (xi ) 3 h + h + + h + 2! 3! n! f (n ) (xi ) n f (xi ) 2 f (3) (xi ) 3 h + h + + h + Rn 2! 3! n! f n +1 ( ) n +1 h , (n + 1)!

Comments

f (xi +1 ) = f (xi )+f (xi )h + f (xi +1 ) = f (xi )+f (xi )h + where

Rn =

h = xi +1 xi , the subscript n denotes it is the remainder for the n th-order approximation and is a value of x between xi and xi +1 .
p. 35 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 36 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Tylor Series

Comments

See gure 4.7 page 104 in the textbook.

p. 37

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 38

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Tylor Series
1

Comments

In general, the n -th order Taylor series expansion will be exact for an n -th order polynomial. In other cases, it is usually necessary to truncate the series because it is not possible to carry out an innite number of additions. The remainder term Rn is of the order of h n +1 : R n = O (h n + 1 )
1 2

The more terms are used, the smaller the error. For a given number of terms, the smaller the spacing, h , the smaller the error.
c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 40 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

p. 39

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Example
Example Use Taylor series expansions with n = 0 to 3 to approximate e 0.3 . Compare the errors Et and Ea and nd the upper bound of Rn . Approximation of e 0.3 Tylor approximation Et Ea 1 0.3498 1.3 0.0498 0.3 1.345 0.0045 0.04 1.3495 0.0003 0.004

Comments

n 0 1 2 3

Born of |Rn | 0.4 0.06 0.00607 0.000455

The exact value of e (0.3) is 1.3498588.


p. 41 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 42 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Numerical Dierentiation
Finite-dierence approximations of the rst derivative
1

Comments

The rst order Taylor series can be used to calculate approximations to derivatives : Given : f (xi +1 ) = f (xi ) + f (xi )h + O (h 2 ) Then : f (xi ) = f (xi +1 ) f (xi ) + O (h ) h

This forward dierence is one of many examples for approximating the derivatives numerically and that can be developed from the Taylor series. More accurate approximations of the rst derivative can be developed by including higher-order terms of the Taylor series. f (xi +1 ) = f (xi ) + f (xi )h + f (xi ) 2 h + O (h 3 ) 2!
p. 44 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

p. 43

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Finite-dierence approximations of the rst derivative


Finite-dierence approximations of the rst derivative
Forward, backward, and centered nite-dierence approximations of the rst derivative a) Forward : f (xi ) = b) Backward : f (xi ) = c) Centered : f (xi ) =
gure 4.10 p. 45

Comments

f (xi +1 ) f (xi ) + O (h ) h See gure 4.10 page 111 in the textbook. f (xi ) f (xi 1 ) + O (h ) h

f (xi +1 ) f (xi 1 ) + O (h 2 ) 2h
Civil Engineering Analysis II: CIV E 295 p. 46 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

c 2012 by Thec McGraw-Hill Companies, Inc. Youssef Belhamadia

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Chapter 1 : Roundo and Truncation Errors

Truncation Errors

Example
Example Approximate f (1) with f (x ) = x 3 + x 2 + x .
Approximation of f (1) h=1 Forward Backward Centered 11 3 7.5 5 3 1.5 h = 0.5 Forward Backward Centered 8.25 4.25 6.25 2.25 1.75 0.25 h = 0.25 Forward Backward Centered 7.06 5.06 6.06 1.06 1.06 0.06

Comments

f (1) = |Et | f (1) = Et f (1) = Et

The exact value of f (1) is 6.


p. 47 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 48 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Plan

Comments

Chapter 1 : Roundo and Truncation Errors Introduction Errors Truncation Errors Roundo Errors

p. 49

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 50

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Computer Number Representation


1

Comments

Digital computers have magnitude and precision limits on their ability to represent numbers. In the decimal system, any number x (other than zero) can be represent in normalized oating-point form as x = 0.d1 d2 d3 dn 10n k-digit decimal machine numbers are of the form : x = 0.d1 d2 d3 dk 10n The oating point representation is binary system is similar to the decimal system.

By default, MATLAB has adopted the IEEE double-precision format in which eight bytes (64 bits) are used to represent oating-point numbers
c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 52 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

p. 51

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Arithmetic Manipulations of Computer Numbers


Roundo error can happen in several circumstances other than just storing numbers, for example : (x + 1020 ) x = 1020 mathematically, but x = 1 ; (x + 1020 ) x gives a 0 in MATLAB ! Certain numerical manipulations are highly sensitive to roundo errors, for example, 1 Adding a Large and a Small Number Example 1 0.4000 104 + 0.0000001 104 = 0.4000001 104 which is chopped to 0.4000 104 by using a hypothetical computer with the 4-digit mantissa and the 1-digit exponent.
p. 53 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Comments

p. 54

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Arithmetic Manipulations of Computer Numbers


2 Large computations : if a process performs a large number of computations, roundo errors may build up to become signicant Example 2 function sout = sumdemo() s = 0; for i = 1 :10000 s = s + 0.0001 ; end sout = s ; When this function is executed, the result is format long sumdemo ans = 0.99999999999991
p. 55 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Comments

p. 56

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Arithmetic Manipulations of Computer Numbers


3 Substraction of nearly equal numbers Example 3
Consider x 2 + 62.10x + 1 = 0, try to nd x1 using four digit rounding :
1

Comments

First method : x1 = b +

b2 4ac 62.10 + 62.06 = = 0.02 2a 2.000 b2 4ac 2a b b2 4ac b b2 4ac

. Second method : x1 = b + x1 =

2c = 0.01610 b2 4ac

The exact roots are x1 = 0.001610723 and x2 = 62.08390.


p. 57 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295 p. 58 c Youssef Belhamadia Civil Engineering Analysis II: CIV E 295

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Chapter 1 : Roundo and Truncation Errors

Roundo Errors

Other Errors

Comments

The total numerical error is the summation of the truncation and roundo errors. Blunders : errors caused by malfunctions of the computer or human imperfection. Model errors : errors resulting from incomplete mathematical models. Data uncertainty : errors resulting from the accuracy and/or precision of the data.

p. 59

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

p. 60

c Youssef Belhamadia

Civil Engineering Analysis II: CIV E 295

You might also like