Download presentation

Presentation is loading. Please wait.

Published byVeronica Lamb Modified about 1 year ago

1
E. T. S. I. Caminos, Canales y Puertos1 Part 1 Engineering Computation

2
E. T. S. I. Caminos, Canales y Puertos2 Introduction Numerical methods are techniques which allow us to formulate mathematical problems to be solved by basic arithmetic operations. They are able to handle large systems of equations, non- linearities, complicated geometries and allow us solving engineering problems which have no analytical solution. –The intelligent use of commercial software is favored by the knowledge of numerical methods. –They allow us to design ad hoc programs to solve concrete problems. –The allow us to become familiar with computers and understand the way they work. –They are a good tool to reinforce the mathematical knowledge, because one of their aims consists in transforming complicate problems into simple arithmetic operations.

3
E. T. S. I. Caminos, Canales y Puertos3 Introduction Roots of equations : –They are methods to solve – They try to find the values of a variable for it to satisfy one equation. –They are very useful in engineering projects, because in many occasions it is not possible to solve the design equations analytically.

4
E. T. S. I. Caminos, Canales y Puertos4 Introduction Systems of linear equations: –They are methods looking for the set of values that simultaneously satisfy a system of algebraic equations. –Calculus of structures, electric circuits, supply networks, fit of curves, etc.

5
E. T. S. I. Caminos, Canales y Puertos5 Introduction Optimization: –Determine the value x 0 leding to the optimal value of f(x). –They can be subject to constraints.

6
E. T. S. I. Caminos, Canales y Puertos6 Introduction Fitting curves. Fitting techniques can be divided into two groups: –Regression. It is used when one has errors in the experimental data. One looks for the curve showing the trend of the data. –Interpolation. It is used to fit tabulated data and predict intermediate values or extrapolated data.

7
E. T. S. I. Caminos, Canales y Puertos7 Introduction Integration: –Determine the area below a given curve. –It has many applications in engineering. Calculus of centers of gravity. Calculus of areas, volumes, etc. –It can also be used to solve differential equations.

8
E. T. S. I. Caminos, Canales y Puertos8 Introduction Ordinary differential equations : –They are very important because many problems can be stated in terms of variations and not in terms of magnitudes. –There are two types of problems: Initial value problems, and boundary value problems.

9
E. T. S. I. Caminos, Canales y Puertos9 Introduction Partial differential equations: –Used for characterizing engineering problems where the behavior of the physical magnitude can be expressed in terms of speed change with respect to two or more variables. –Approximation by finite differences or the finite element method.

10
E. T. S. I. Caminos, Canales y Puertos10 Mathematical Models A mathematical expression of a given model can be Analytic solution (t=0, v=0): Approximate solution:

11
E. T. S. I. Caminos, Canales y Puertos11 Mathematical Models To solve the problem numerically, one replaces the derivative by a divided finite difference, tus transforming the problem into a very simple one containing only simple algebraic operations:

12
E. T. S. I. Caminos, Canales y Puertos12 Numerical Differentiation Forward: Centered: How big a step size should we select? One- or two-sided formula: What are the advantages of each? How is optimal step size affected by: - precision of numerical calculations? - precision with which f is computed? - curvature of function f near x=1? - choice of formula?

13
E. T. S. I. Caminos, Canales y Puertos13 Numerical Methods Instead of solving for the exact solution we solve math problems with a series of arithmetic operations. analytical solution: ln(b) – ln(a) numerical solution e. g., Trapezoidal Rule Error Analysis (a) identify sources of error (b) estimate the magnitude of the error (c) determine how to minimize and control error Example: dx APPROXIMATION AND ERRORS

14
E. T. S. I. Caminos, Canales y Puertos14 Mathematical Models Comparing solutions:

15
E. T. S. I. Caminos, Canales y Puertos15 Approximations and Rounding Errors Unfortunately, computers introduce errors in calculations. However, since many engineering problems have not analytical solution, we are forced to used numerical methods (approximations). The only noption we have is to accept the error and try to reduce it up to a tolerable level. The only way of minimizing the errors is by knowing and understanding why they occur and how we can diminish them. The most frequent errors are: –Rounding errors, due to the fact that computers can work only with a finite representation of numbers. –Truncation errors, due to differences between the exact and the approximate (numeric) formulations of the mathematical problem being dealt with. Before centering in each one of them, we will see two important concepts on the computer representation of numbers.

16
E. T. S. I. Caminos, Canales y Puertos16 Approximations and Rounding Errors Significant figures of a number: –The significant figures of a number are those that can be used with confidence. –The speedometer and the odometer in the figure estimate up to three and seven significant figures, respectively, 49.5 and 87324.45. –This concept has two important implications: 1. An approximation is acceptable when it is exact for a given number of significant figures. 2. There are magnitudes or constants that cannot be represented exactly.

17
E. T. S. I. Caminos, Canales y Puertos17 Accuracy closeness of measured/computed values to the "true" value (vs. inaccuracy or bias) Biassystematic deviation from truth, "general trend" Precisioncloseness of measured/computed values with each other (spread or scatter), relates to the number of significant figures (vs. imprecision or uncertainty) Approximations and Rounding Errors

18
E. T. S. I. Caminos, Canales y Puertos18 Approximations and Rounding Errors Accuracy and precision: –The errors associated with nd measurements can be characterized observing their accuracy and precision. –Accuracy refers to how close the value is to the true value. –Precision refers to how close are different measured values using the same method. Numerical methods must be sufficiently exact (without bias) and precise to satisfy the requirements of engineering problems. From now on we will refer to error to refer to the inaccuracy and lack of precision of our predictions.

19
E. T. S. I. Caminos, Canales y Puertos19 (a) inaccuratimprecise (b) accurateimprecise (c) Inaccurate precise (d) Accurate precise Approximations and Rounding Errors

20
E. T. S. I. Caminos, Canales y Puertos20 Approximations and Rounding Errors Error definitions: –True value = approximation + absolute error. –Absolute error = true value - approximation. –Relative error = absolute error / true value. –In real cases not always one can know the true value, thus: –In many occasions, the error is calculated as the difference between the previous and the actual approximations.

21
E. T. S. I. Caminos, Canales y Puertos21 Approximations and Rounding Errors –Thus, the stopping criterium of a numerical method can be: –It is convenient to relate the errors with the number of significant figures.If the following relation holds, one can be sure that at least n significant figures are correct.

22
E. T. S. I. Caminos, Canales y Puertos22 Approximations and Rounding Errors Numerical systems: –A numerical system is a convention to represent quantities. Since we have 10 fingers in our hands, our most familiis the numerical system which basis is 10. It uses 10 different digits. –However, computers, due to the memory structure can only store two digits: 0 and 1. Thus, they use the binary system of numeric representation.

23
E. T. S. I. Caminos, Canales y Puertos23 Background: How are numbers stored in a computer? The fundamental unit, a "word," consists of a string of "bits" (binary digits). Because computers are made up of gates or switches which are either closed or open, we work in binary or base 2 system. Example: An 8 bit word representation of the integer "35" is 00100011 or 00100011 ±2 6 2 5 2 4 2 3 2 2 2 1 2 0 +0x2 6 1x2 5 0x2 4 0x2 3 0x2 2 1x2 1 1x2 0 =35 3221 Note: We can only represent a finite # of numbers; for our case: –127 to +127 (127 = 2 7 – 1) or a total of 255 numbers (including 0) Round-off Errors

24
E. T. S. I. Caminos, Canales y Puertos24 Approximations and Rounding Errors Representation of integer numbers: –To represent base 10 numbers in binary form the signed magnitude method is used. The first digit stores the sign (0, positive and 1, negative). The remaining bits are used to store the number. –A computer working with words of 16 bits can store integer numbers in the range -32768 to 32767.

25
E. T. S. I. Caminos, Canales y Puertos25 Approximations and Rounding Errors Floating point representation: –This representation is used for fractional quantities. It has the fraction part, called mantissa, and an integer part, called exponent or characteristic. –The mantissa is usually normalized, so that the value of m is limited:

26
E. T. S. I. Caminos, Canales y Puertos26 Approximations and Rounding Errors Hipothetical set: –We assume a hipothetical set of floating point numbers for a machine using 7 bits as word. –The smallest number that can be represented is 0.0625, and the largest is 7.

27
E. T. S. I. Caminos, Canales y Puertos27 Approximations and Rounding Errors

28
E. T. S. I. Caminos, Canales y Puertos28 EXAMPLE: “Our” Base 10 Machine: This "Machine" carries three significant decimal digits and one exponent digit. ± 0.DDDE ± e with: 0 < e < 9 100 < DDD < 999 We represent - 0.02778 in our machine: - 0.277E-1 w/ chopping t = 0.29% - 0.278E-1 w/ rounding t = 0.07% (most computers round, but some chop to save time) Round-off Errors

29
E. T. S. I. Caminos, Canales y Puertos29 Consequences of Computer Representation of #'s: Limited Range of quantities can be represented because there are a finite # of digits in both the mantissa and the exponent. smallest positive # 0.100E-9 or 10 -10 largest positive # 0.999E+9 almost 10 9 Finite number of floating-point values can be represented within the above range. ± (0.100 to 0.999) E-9 to E+9 2 x 900 #'s x 19 #'s = 34,200 #'s plus zero ( 0.000 E±e ) Thus, 34,201 #'s can be represented within the above range (zero appears only once). Round-off Errors

30
E. T. S. I. Caminos, Canales y Puertos30 The interval between successive represented numbers (quantization error) is not uniform, and increases as the numbers grow in magnitude. - "quantization" error, Dx, is proportional to the magnitude x. - normalizing | x | by | x | gives an approximation of "machine epsilon" - p, with both chopping and rounding, is represented by 0.314E+1 with:"quantizing error" = | x | = 0.01 | x | = 10.0 Consequences of Computer Representation of #'s

31
E. T. S. I. Caminos, Canales y Puertos31 Approximations and Rounding Errors Conclusions: –There is a limited range to represent quantities. The limits correspond to “underflow” and “overflow”. –There is a finite number of quantities that can be represented on a given range.

32
E. T. S. I. Caminos, Canales y Puertos32 Approximations and Rounding Errors –The interval between numbers increases as the numbers grow in magnitude. –This means that the errors are proportional to the magnitude of the number to be represented. Analyzing the relative error one gets: –where is the machine epsilon, that is the worst possible relative error. with chopping With rounding

33
E. T. S. I. Caminos, Canales y Puertos33 Machine Epsilon on "Our Base 10 Machine" Try 0.01 - - - > 0.100 E+1+0.100 E–1=0.101 E=1 1.0+0.01=1.01 Try 0.00999 - - - > 0.100 E+1+0.999 E-2=0.100 E+1 1.0+0.00999=1.00999 after chopping ==> 1.00 Therefore, Machine epsilon is 0.01; Quick formula: = b 1- t = 10 1-3 = 0.01 t = # of sig. figs. in mantissa Machine Epsilon : Smallest number such that: 1 + > 1 Machine Epsilon

34
E. T. S. I. Caminos, Canales y Puertos34 Trouble happens when you add (or subtract) a small number to a large number: For "our machine": 1,200 + 4 + 6 1,210 Working left-to-right: 1200+4= 1204 which is chopped to 1200 1200=0.120E+4 1200+6=1206which is chopped to 1200 Reverse the order: 4+6=10 which is ok 10+1200=1210 which is ok Remedy: add or subtract small numbers together first. Round-off Error due to Arithmetic Operations

35
E. T. S. I. Caminos, Canales y Puertos35 Subtractive Cancellation (subtracting numbers of almost equal size) – too few significant figures left Consider formulas such as : Problems arise when we try to subtract two numbers of almost equal size 32,232–32,181=51(Little precision left.) Our Machine ("chopper"): 0.322 E+5–0.321 E+5 32200–32100=100 With rounding: 0.322 E+5–0.322 E+5 32200–32200=0 Round-off Error due to Arithmetic Operations

36
E. T. S. I. Caminos, Canales y Puertos36 Smearing Occurs when individual terms are larger than summation itself. Consider the exponential series with x = -10 Consider formulas such as: With 7-decimal-digit accuracy: exact answer = 4.54 10 -05 computed answer = – 6.26 10 -05 ( differs from book value ) (45 terms) wrong sign ! Largest intermediate terms are: 9th = –2,755.732 & 10th = 2,755.732 Round-off Error due to Arithmetic Operations

37
E. T. S. I. Caminos, Canales y Puertos37 Single Precision: 32 BIT WORDS 24 BITS assigned to mantissa (including the sign bit) 8 BITS to signed exponent Double Precision: 64 BIT WORDS 56 BITS assigned to mantissa (including the sign bit) 8 BITS to signed exponent (not changed) 2 23 = 8,400,000 or almost 7 full decimal digits for single 2 55 = 4x10 16 or almost 17 decimal digits for double 2 7 – 1 = 127; 2 +127 ~ 2x10 38 for both single and double Modern Computers (IEEE standard)

38
E. T. S. I. Caminos, Canales y Puertos38 Error caused by the nature of the numerical technique employed to approximate the solution. Example: Maclaurin series expansion of e x If we use a truncated version of the series: Then the Truncation Error is: Truncation Error

39
E. T. S. I. Caminos, Canales y Puertos39 Approximations and Rounding Errors Precautions: –Sums of large and small numbers: due to equaling the exponent. They are common in sums of infinite series where the individual terms are very small when compared with the accumulated sum. This error can be reduced by summing first the small terms and using double precision. –Cancellation of the subtraction: The subtraction of very similar numbers. –Smearing: The individual terms are larger than the total sum. –Inner products: They are prone to rounding errors. Thus, it is convenient to use double precision in this type of calculations.

40
E. T. S. I. Caminos, Canales y Puertos40 Basic Idea: Predict the value of a function, ƒ, at a point x i+1 based on the value of the function and all of its derivatives, ƒ, ƒ', ƒ",… at a neighboring point x i Given x i, ƒ(x i ), ƒ'(x i ), ƒ"(x i ),... ƒ n+1 (x i ), we can predict or approximate ƒ(x i+1 ) Taylor Series Expansion

41
E. T. S. I. Caminos, Canales y Puertos41 General Form (Eq. 4.7 in C&C): h = "step size" = x i+1 – x i R n = remainder to account for all other terms = O (h n+1 ) with x not exactly known "on the order of h n+1 " Note: f(x) must be a function with n+1 continuous derivatives with x i x i+1 Taylor Series Expansion

42
E. T. S. I. Caminos, Canales y Puertos42 0 th order T.S. approx. (n = 0): f(x i+1 ) = f(x i ) + O (h 1 ) 1 st order T.S. approx. (n = 1): f(x i+1 ) = f(x i ) + hf '(x i ) + O (h 2 ) 2 nd order T.S. approx. (n = 2): n th order T.S. approximation will be exact for an n th order polynomial Taylor Series Expansion

43
E. T. S. I. Caminos, Canales y Puertos43 Zero order First order Second order f(x i ) f(x i+1 ) f(x i ) f(x i+1 ) f(x i )+f '(x i )h f(x i+1 ) f(x i )+f '(x i )h+ )+f "(x i )h 2 /2! f(x i+1 ) True f(x ) x i+1 xixi h x Taylor Series Expansion

44
E. T. S. I. Caminos, Canales y Puertos44 Objective: Evaluate the derivatives of function, ƒ(x i ), without doing it analytically. When would we want to do this? 1. function is too complicated to differentiate analytically: 2. function is not defined by an equation, i.e., given a set of data points (x i, ƒ(x i )), i=1,…,n i01234 x i 1.03.05.07.09.0 ƒ(x i )2.34.15.55.75.9 Numerical Differentiation from Taylor Series Expansion

45
E. T. S. I. Caminos, Canales y Puertos45 Numerical Differentiation from Taylor Series Expansion –First derivative with backward difference.

46
E. T. S. I. Caminos, Canales y Puertos46 Backward Difference Approx.: First Derivative: first backward difference Letting h = x i - x i-1 Numerical Differentiation from Taylor Series Expansion

47
E. T. S. I. Caminos, Canales y Puertos47 Using data below calculate ƒ'(x 1 ) : i01234 x i 1.03.05.07.09.0 ƒ(x i )2.34.15.55.75.9 First Backward Finite-Divided-Difference at x 1 : f ' (x 1 ) 0.9 { + O (h) } Example of 1st Backward FDD

48
E. T. S. I. Caminos, Canales y Puertos48 Second Derivative: + O([x i-2 – x i ] 3 ) withh = x i – x i-1 and 2h = x i – x i-2 The 2 nd order approximation to ƒ(x i-2 ) becomes: ƒ(x i-2 ) = ƒ(x i ) – 2hƒ'(x i ) + 2h 2 ƒ"(x i ) +O (h 3 ) [1] 2nd order approximation to ƒ(x i-1 ): [2] Backward Difference Approximation

49
E. T. S. I. Caminos, Canales y Puertos49 Subtracting 2*[2] from [1] yields: f(x i-2 ) – 2f(x i-1 ) = –f(x i ) + h 2 f"(x i ) + O (h 3 ) Rearranging: h 2 ƒ"(x i ) = f(x i ) – 2f(x i-1 ) + f(x i-2 ) + O (h 3 ) Second backward difference Backward Difference Approximation

50
E. T. S. I. Caminos, Canales y Puertos50 Using data below calculate ƒ"(x 2 ) : i01234 x i 1.03.05.07.09.0 ƒ(x i )2.34.15.55.75.9 Second Backward Finite-Divided-Difference at x 2 : f " (5.0) - 0.1 { + O (h) } Example of 2nd Backward FDD

51
E. T. S. I. Caminos, Canales y Puertos51 What points are used for each form? Backward: …, ƒ(x i-2 ), ƒ(x i-1 ), ƒ(x i ), ƒ(x i+1 ), ƒ(x i+2 ), … Forward: …, ƒ(x i-2 ), ƒ(x i-1 ), ƒ(x i ), ƒ(x i+1 ), ƒ(x i+2 ), … Centered: …, ƒ(x i-2 ), ƒ(x i-1 ), ƒ(x i ), ƒ(x i+1 ), ƒ(x i+2 ), … Other Forms of Numerical Differentiation

52
E. T. S. I. Caminos, Canales y Puertos52 Taylor Series and Truncation errors - Higher order divided differences. - Second finite central divided difference

53
E. T. S. I. Caminos, Canales y Puertos53 Forward: Centered: Other Forms of Numerical Differentiation

54
E. T. S. I. Caminos, Canales y Puertos54 Taylor Series and Truncation errors Use of the Taylor series to calculate derivatives. –First derivative with forward difference.

55
E. T. S. I. Caminos, Canales y Puertos55 Taylor Series and Truncation errors –First derivative with central differences.

56
E. T. S. I. Caminos, Canales y Puertos56 Questions: Which is a better approximation? Forward, Centered, or Backward? Why? When would you use which? Note: We also can get higher order forward, centered, and backward difference derivative approximations [C&C Chapter 23, tabulated in Figs. 23.1-3] Taylor Series and Truncation errors

57
E. T. S. I. Caminos, Canales y Puertos57 Determine h to minimize the total error of a forward finite- divided difference approximation for: x i x i+1 Round-off Error: Truncation Error: with = machine epsilon. As a result: Example Combining Roundoff and Truncation Error

58
E. T. S. I. Caminos, Canales y Puertos58 Total error = truncation error + roundoff error E = | Total Error | NOTE: Truncation error decreases as h decreases Round-off error increases as h decreases + Example Combining Roundoff and Truncation Error

59
E. T. S. I. Caminos, Canales y Puertos59 Example Combining Roundoff and Truncation Error

60
E. T. S. I. Caminos, Canales y Puertos60 To minimize total error E with respect to h, set the first derivative to zero: Solve for h and approximate f "( ) as f "(x i ): Example Combining Roundoff and Truncation Error

61
E. T. S. I. Caminos, Canales y Puertos61 Using the first forward-divided-difference approximation with error O(h) and a 5-decimal-digit machine: e = b 1-t = 10 1-5 = 10 -4 = 0.0001 f '(x) = ;f "(x) = 0 Linear Application: Determine h that will minimize total error for calculating f’(x) for f(x) = x at x = 1 Example Combining Roundoff and Truncation Error

62
E. T. S. I. Caminos, Canales y Puertos62 f(x+h)={exact: 3.1415} h (x+h) f(x+h)-f(x)[f(x+h)-f(x)]/h 03.1415 0.0000013.141500 0.000013.14160.000110 0.00013.14190.00044.0 0.0013.14470.00323.2 0.013.17300.03153.15 0.13. 45570.31423.142 16.28313.14163.146 Underlined digits are subject to round-off error. They are likely to be in error by ± one or two units. This does not cause much problem when h = 1, but causes large errors in the final result when h < 10 -4. Example Combining Roundoff and Truncation Error

63
E. T. S. I. Caminos, Canales y Puertos63 Nonlinear Application: Determine h for minimizing the total error for computing f’(x) for ƒ(x) = e x at x = 3 Using the first forward-divided-difference approximation with error O(h) and a 5-decimal-digit machine: e = b 1-t = 10 1-5 = 10 -4 = 0.0001 f(x) = f '(x) = f "(x) = e x = 20.0855; or about 0.01 Example Combining Roundoff and Truncation Error

64
E. T. S. I. Caminos, Canales y Puertos64 Underlined digits subject to roundoff error. Bold digits in error due to truncation. full precision hf(x+h)=e x+h f(x+h)-f(x)[f(x+h)-f(x)][f(x+h)-f(x)]h 020.085{exact = 20.085} 0.0000120.0850.0020.086 0.000120.0870.0022020.086 0.00120.1050.0202020.096 0.0120.2870.20220.220.18 0.122.1982.11321.1321.12 154.59834.51334.52334.512 RoundoffTruncation Example Combining Roundoff and Truncation Error

65
E. T. S. I. Caminos, Canales y Puertos65 Additional Error Terminology: Error Propagation Errors which appear because we are basing current calculations on previous calculations which also incurred some form of error Stability and Condition Number[see C&C 4.2.3] Numerically Unstable: Computations which are so sensitive to round-off errors that errors grow uncontrollably during calculations. Condition: sensitivity to such uncertainty; "well conditioned" vs. "ill conditioned" Condition Number: measure of the condition; i.e., extent to which uncertainty in x is amplified by ƒ(x) C.N. 1 ===> "well-conditioned" C.N. >> 1 ===> "ill-conditioned"

66
E. T. S. I. Caminos, Canales y Puertos66 Begin with Taylor Series: where is an approximation of x. Relative error of f(x)Relative error of x The condition number is the ratio of the two relative errors: Condition Number

67
E. T. S. I. Caminos, Canales y Puertos67 Condition Number CN contrasts the uncertainty in x with the uncertainty in f(x) C.N. 1===> "well-conditioned", i.e., The error in f(x) is similar to the error in x. C.N. >> 1 ===> "ill-conditioned", i.e., the error in f(x) is amplified and small errors in x can produce large errors in f(x). Condition Number

68
E. T. S. I. Caminos, Canales y Puertos68 Condition Number Example: Compute the condition number for f(x) = tan(x) f(x) = tan(x) = sin(x)/cos(x) f'(x) = sec 2 (x) = 1/cos 2 (x) CN = x/[cos(x) sin(x)] This becomes large (ill-conditioned) when the denominator approaches zero, i.e., when x 0, /2, , … Condition Number

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google