Download - Civ E 295 Lecture 1
-
7/27/2019 Civ E 295 Lecture 1
1/10
Civil Engineering Analysis II: CIV E 295
Youssef Belhamadia
7 janvier 2014
p. 1 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Plan
Plan
1 Chapter 1 : Roundoff and Truncation ErrorsIntroduction
Errors
Truncation Errors
Roundoff Errors
p. 2 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Plan
1 Chapter 1 : Roundoff and Truncation ErrorsIntroduction
Errors
Truncation Errors
Roundoff Errors
p. 3 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 4 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Introduction
What are numerical methods and why should you study them ?
Example 1
The roots of the quadratic formula ax2 +bx+c= 0 are :
x1=b+ b2 4ac
2a and x2=
b b2 4ac2a
.
1. Consider x2 3x+ 2 = 0 and try to find x1 :a) First method :
x1=b+ b2 4ac
2a = 2.
b) Second method :
x1=
b+ b2 4ac
2a
b b2 4acb b2 4ac
x1= 2c
b b2 4ac = 2.
The exact roots are x1= 2 and x2= 1.
p. 5 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 6 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
2/10
Chapter 1 : Roundoff and Truncation Errors Introduction
Introduction
What are numerical methods and why should you study them ?
Example 1
Consider x2 +62.10x+ 1 = 0, try to find x1 using four digitrounding :
1 First method :
x1 =b+
b2 4ac2a
=62.10+ 62.06
2.000= 0.020
.2 Second method :
x1 =
b+
b2 4ac2a
b
b2 4ac
b
b2 4ac
x1 = 2c
b
b2 4ac = 2.000
60.10 62.06 = 0.016
The exact roots are x1 = 0.01610723 and x2 = 62.08390.
p. 7 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 8 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
IntroductionExample 2
Evaluate f(x) = x3 6.1x2 + 3.2x+ 1.5 at x= 4.71 using three digit(rounding).
1 First method :
f(4.71) = (4.71)3 6.1(4.71)2 + 3.2(4.71) + 1.5f(4.71) = 105. 135.+ 15.1+ 1.5= 13.4
2 Second method :
f(x) = x3 6.1x2 + 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 abovetwo methods ?
p. 9 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 10 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Introduction
Example 3
1 Can you give the exact value of the integral 1
0
e(x) dx?
2 Can you give the exact value of the integral 1
0
e(x2) dx?
The second integral exists but has a value that cannot be expressedin a simple form.
Using numerical method we may obtain the following two values
1
0
e(x2) dx= 0.746809163 or
1
0
e(x2) dx= 0.746824133,
but which one is most accurate ?
p. 11 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 12 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
3/10
Chapter 1 : Roundoff and Truncation Errors Introduction
Introduction
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 complicatedgeometries that arecommon in engineeringand science and that
are impossibleto solve analytically.
2 Numerical methods are an efficient tools for learning to usecomputers.
p. 13 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Introduction
Comments
p. 14 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Plan
1 Chapter 1 : Roundoff and Truncation ErrorsIntroduction
Errors
Truncation Errors
Roundoff Errors
p. 15 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 16 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Introduction
1 Mathematical approximation and digital computers causeuncertain results.
2 Engineers need constantly to accomplish objectives and makedecision based on uncertain results.
3 Is it possible to understand, quantify and control such errors inorder to obtain acceptable results ?
p. 17 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 18 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
4/10
Chapter 1 : Roundoff and Truncation Errors Errors
Accuracy and Precision
Accuracy and precision are synonyms. However, they are completely different
Definition
1 Accuracy refers to how closely a computed or measured value agreeswith the true or actual value.
2 Precision refers to how closely a series of values agree or consistentwith each other.
a) inaccurate and imprecise
b) accurate and imprecise
c) inaccurate and precise
d) accurate and precise
See figure 4.1 page 90 inthe textbook.
p. 19 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 20 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Error DefinitionsDefinition
Consideruas the true value and vis as an approximation to u
1 True error,Et, is the difference between the true value and theapproximation.
True error= Et= u v2 Absolute error,|Et|, is the absolute difference between the true value
and the approximation.
Absolute error= |Et| = |u v|
3 Relative error is
Relative error= u v
u
4 True percent relative error, t, is
True percent relative error = t= u v
u 100%
p. 21 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 22 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Error Definitions
Example
Consider the true value of a bridge as u= 10000cmand the
approximate value is v=9999
cm.
Consider the true value of a rivet as = 10cmand theapproximate value is v= 9cm.
For both the true error is Et= 1cm. However, when look attheir percent relative errors :
Bridge :
t= u v
u 100% = 0.01%
Rivet
t= u v
u 100% = 10%
The bridge measurement is more accurate.
p. 23 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 24 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
5/10
Chapter 1 : Roundoff and Truncation Errors Errors
Error Definitions
Definition
In numerical methods and real-world applications, the true answer is rarelyknown. In this situation an alternative error is used
1 Approximate percent relative error
a=u v
u 100%,
where u is the present approximation and v is the previousapproximation.
2 When performing computations, the computation is repeated untilstopping criterion is satisfied
|a| < s,where s is a prespecified tolerance.
3 We can be assured that the result is correct to at least n significantfigures, if
s = 0.5 102n%p. 25 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 26 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Error Definitions
Example
Estimate e0.5 to three significant figures
1 s = 0.5 1023 = 0.05%2 Tylor formula forex at x= 0
ex = 1 +x+x2
2! + + x
n
n! +
3 Forn= 0 ex= 1 = e0.5= 14 Forn= 1 ex= 1 +x= e0.5= 1 +0.5= 1.5
|a| =
u vu
100% =
1.5 11.5
100% = 33.3%
5 forn= 2 e0.5= |a| = 6 forn= 3 e0.5= |a| =
p. 27 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 28 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Error Definitions
Example
Approximation ofe0.3
n e0.5= |t| |a|0 1 39.3 -1 1.5 9.02 33.32 1.625 1.44 7.693 1.645833333 0.175 1.274 1.648437500 0.0172 0.1585 1.648697917 0.00142 0.0158
After six terms, the approximate error falls below s = 0.05%, andthe computation is terminated.
The exact value is e0.5 = 1.648721
p. 29 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 30 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
6/10
Chapter 1 : Roundoff and Truncation Errors Errors
Errors
They are two major forms of numerical errors :
1 Roundoff error (due to computer approximations).
2 Truncation error (due to mathematical approximations).
The Taylor series is a very good example to express the idea oftruncation error mathematically.
p. 31 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Errors
Comments
p. 32 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Plan
1 Chapter 1 : Roundoff and Truncation ErrorsIntroduction
Errors
Truncation Errors
Roundoff Errors
p. 33 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 34 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Tylor Series
Taylor Theorem
The Taylor theorem states that any smooth function can be
approximated as a polynomial.
f(xi+1) = f(xi)+f(xi)h+
f(xi)
2! h2+
f(3)(xi)
3! h3+ +f
(n)(xi)
n! hn+
f(xi+1) = f(xi)+f(xi)h+
f(xi)
2! h2+
f(3)(xi)
3! h3+ +f
(n)(xi)
n! hn+Rn
where
Rn= fn+1()
(n+ 1)!hn+1,
h= xi+1 xi, the subscript ndenotes it is the remainder for thenth-order approximation and is a value ofxbetween xi and xi+1.
p. 35 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 36 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
7/10
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Tylor Series
See figure 4.7 page 104 in the textbook.
p. 37 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 38 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Tylor Series
1 In general, the n-th order Taylor series expansion will be exactfor an n-th order polynomial.
2 In other cases, it is usually necessary to truncate the seriesbecause it is not possible to carry out an infinite number ofadditions.
3 The remainder term Rn is of the order ofhn+1 :
Rn= O(hn+1)
1 The more terms are used, the smaller the error.
2 For a given number of terms, the smaller the spacing,h, thesmaller the error.
p. 39 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 40 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Example
Example
Use Taylor series expansions with n= 0 to 3 to approximate e0.3.
Compare the errors Et and Eaand find the upper bound ofRn.
Approximation ofe0.3
n Tylor approximation Et Ea Born of|Rn|0 1 0.3498 - 0.41 1.3 0.0498 0.3 0.062 1.345 0.0045 0.04 0.006073 1.3495 0.0003 0.004 0.000455
The exact value ofe(0.3) is 1.3498588.
p. 41 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 42 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
8/10
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Numerical Differentiation
Finite-difference approximations of the first derivative
1 The first order Taylor series can be used to calculate approximations toderivatives :Given :
f(xi+1) = f(xi) +f(xi)h+O(h
2)
Then :
f(xi) = f(xi+1) f(xi)
h +O(h)
2 This forward difference is one of many examples for approximating thederivatives numerically and that can be developed from the Taylorseries.
3 More accurate approximations of the first derivative can be developedby including higher-order terms of the Taylor series.
f(xi+1) = f(xi) +f(xi)h+
f(xi)
2! h2 +O(h3)
p. 43 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 44 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Finite-difference approximations of the first derivative
Finite-difference approximations of the first derivative
Forward, backward, and centeredfinite-difference approximations of the firstderivative
a) Forward :
f(xi) =f(xi+1) f(xi)
h +O(h)
b) Backward :
f(xi) = f(xi) f(xi1)
h +O(h)
c) Centered :
f(xi) =f(xi+1) f(xi1)
2h +O(h2)
See figure 4.10 page 111in the textbook.
figure 4.10 c2012 by The McGraw-Hill Companies, Inc.p. 45 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 46 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Example
Example
Approximatef(1) with f(x) = x3 +x2 +x.Approximation off(1)
h=1Forward Backward Centered
f(1) = 11 3 7.5|Et| 5 3 1.5
h= 0.5Forward Backward Centered
f(1) = 8.25 4.25 6.25Et 2.25 1.75 0.25
h= 0.25Forward Backward Centered
f(1) = 7.06 5.06 6.06Et 1.06 1.06 0.06
The exact value off(1)is 6.
p. 47 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Truncation Errors
Comments
p. 48 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
9/10
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Plan
1 Chapter 1 : Roundoff and Truncation ErrorsIntroduction
Errors
Truncation Errors
Roundoff Errors
p. 49 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 50 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Computer Number Representation
1 Digital computers have magnitude and precision limits on their abilityto represent numbers.
In the decimal system, any number x(other than zero) can berepresent in normalized floating-point form as
x= 0.d1d2d3 dn 10n
k-digit decimal machine numbers are of the form :
x= 0.d1d2d3 dk10n
The floating point representation is binary system is similar to thedecimal system.
2 By default, MATLAB has adopted the IEEE double-precision format inwhich eight bytes (64 bits) are used to represent floating-pointnumbers
p. 51 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 52 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Arithmetic Manipulations of Computer Numbers
Roundoff error can happen in several circumstances other thanjust storing numbers, for example : (x+ 1020) x= 1020mathematically, but x = 1 ; (x+ 1020)
xgives a 0 in
MATLAB!Certain numerical manipulations are highly sensitive to roundofferrors, for example,
1 Adding a Large and a Small Number
Example 1
0.4000 104+0.0000001 104=0.4000001 104which is chopped to 0.4000 104 by using a hypothetical computerwith the 4-digit mantissa and the 1-digit exponent.
p. 53 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 54 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
-
7/27/2019 Civ E 295 Lecture 1
10/10
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Arithmetic Manipulations of Computer Numbers
2 Large computations :if a process performs a large number ofcomputations, roundoff errors may build up to become significant
Example 2
function sout = sumdemo()s = 0;for i = 1 :10000
s = s + 0.0001 ;endsout = s;When this function is executed, the result is format long sumdemoans = 0.99999999999991
p. 55 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 56 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Arithmetic Manipulations of Computer Numbers
3 Substraction of nearly equal numbers
Example 3
Considerx2 +62.10x+ 1 = 0, try to find x1 using four digit rounding :
1 First method :
x1=b+ b2 4ac
2a =
62.10+ 62.062.000
= 0.02.2 Second method :
x1=
b+ b2 4ac
2a
b b2 4acb b2 4ac
x1= 2c
b b2 4ac=
0.01610
The exact roots are x1= 0.001610723 and x2= 62.08390.
p. 57 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 58 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Other Errors
The total numerical error is the summation of the truncation
and roundoff errors.
Blunders : errors caused by malfunctions of the computer orhuman imperfection.
Model errors : errors resulting from incomplete mathematicalmodels.
Data uncertainty : errors resulting from the accuracy and/orprecision of the data.
p. 59 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295
Chapter 1 : Roundoff and Truncation Errors Roundoff Errors
Comments
p. 60 cYoussef Belhamadia Civil Engineering Analysis II: CIV E 295