Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "E. T. S. I. Caminos, Canales y Puertos1 Engineering Computation Part 2."— Presentation transcript:

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

2 E. T. S. I. Caminos, Canales y Puertos2 Objective: Solve for x, given that f(x) = 0 -or- Equivalently, solve for x such that g(x) = h(x) ==> f(x) = g(x) – h(x) = 0 Roots of Equations

3 E. T. S. I. Caminos, Canales y Puertos3 p = pressure, T = temperature, R = universal gas constant, a & b = empirical constants Chemical Engineering (C&C 8.1, p. 187): van der Waals equation; v = V/n (= volume/# moles) Find the molal volume v such that Roots of Equations

4 E. T. S. I. Caminos, Canales y Puertos4 Civil Engineering (C&C Prob. 8.17, p. 205): Find horizontal component of tension, H, in a cable that passes through (0,y 0 ) and (x,y) w = weight per unit length of cable Roots of Equations

5 E. T. S. I. Caminos, Canales y Puertos5 L = inductance, C = capacitance, q 0 = initial charge Electrical Engineering (C&C 8.3, p. 194): Find the resistance, R, of a circuit such that the charge reaches q at specified time t Roots of Equations

6 E. T. S. I. Caminos, Canales y Puertos6 Mechanical Engineering (C&C 8.4, p. 196): Find the value of stiffness k of a vibrating mechanical system such that the displacement x(t) becomes zero at t= 0.5sec. The initial displacement is x 0 and the initial velocity is zero. The mass m and damping c are known, and λ = c/(2m). in which Roots of Equations

7 E. T. S. I. Caminos, Canales y Puertos7 Determine real roots of : Algebraic equations (including polynomials) Transcendental equations such as f(x) = sin(x) + e -x Combinations thereof Roots of Equations

8 E. T. S. I. Caminos, Canales y Puertos8 in which: PV= present value or purchase price = $7,500 A= annual payment = $1,000/yr n= number of years = 20 yrs i= interest rate = ? (as a fraction, e.g., 0.05 = 5%) Engineering Economics Example: A municipal bond has an annual payout of $1,000 for 20 years. It costs $7,500 to purchase now. What is the implicit interest rate, i ? Solution: Present-value, PV, is: Roots of Equations

9 E. T. S. I. Caminos, Canales y Puertos9 Engineering Economics Example (cont.): We need to solve the equation for i: Equivalently, find the root of: Roots of Equations

10 E. T. S. I. Caminos, Canales y Puertos10 Excel Roots of Equations

11 E. T. S. I. Caminos, Canales y Puertos11 Roots of Equations Graphical methods: –Determine the friction coefficient c necessary for a parachutist of mass 68.1 kg to have a speed of 40 m/seg at 10 seconds. –Reorganizing.

12 E. T. S. I. Caminos, Canales y Puertos12 Two Fundamental Approaches 1. Bracketing or Closed Methods - Bisection Method - False-position Method 2. Open Methods - One Point Iteration - Newton-Raphson Iteration - Secant Method Roots of Equations

13 E. T. S. I. Caminos, Canales y Puertos13 Bracketing Methods f(x) xlxl xuxu a) b) c) d) x x x x In Figure a) we have the case of f(x l ) and f(x u ) with the same sign, and there is no root in the interval (x l,x u ). In Figure b) we have the case of f(x l ) and f(x u ) With different sign, and there is a root in the interval (x l,x u ). In Figure c) we have the case of f(x l ) and f(x u ) with the same sign, and there are two roots. In Figure d) we have the case of f(x l ) and f(x u ) with different sign, and there is an odd number of roots.

14 E. T. S. I. Caminos, Canales y Puertos14 Though the cases above are generally valid, there are cases in which they do not hold. In Figure a) we have the case of f(x l ) and f(x u ) with different sign, but there is a double root. f(x) xlxl xuxu a) b) c) x x x In Figure b) We have the case of f(x l ) and f(x u ) With different sign, but there are two discontinuities. In Figure c) we have the case of f(x l ) and f(x u ) with the same sign, but there is a multiple root. Bracketing Methods

15 E. T. S. I. Caminos, Canales y Puertos15 f(x 1 ) f(x r ) > 0 x f(x) f(x u ) (x u ) (x 1 ) f(x 1 ) f(x r ) f(x u ) f(x 1 ) (x 1 ) (x u ) (x r ) f(x r ) x f(x) x r => x 1 Bracketing Methods (Bisection method) Bisection Method

16 E. T. S. I. Caminos, Canales y Puertos16 Bisection Method: Given lower and upper bounds, x l and x u, which bracket the root: f(x l ) f(x u ) < 0 1) Estimate the Root by midpoint: 2) Revise the bracket: f(x l ) f(x r ) x u, f(x l ) f(x r ) > 0,x r –> x l 3) Repeat steps 1-2 until: a) |f(x r )| < k,b)  a <  s, with  a = c) | x l – x u | <  d) maximum # of iterations is reached. (Always do this in iteration algorithms.) Bracketing Methods (Bisection method)

17 E. T. S. I. Caminos, Canales y Puertos17 Make conservative guesses at the upper and lower bounds: 100% interest rate,f(1.0) = 6,500 0% interest rate, f(0.0) = -12,500 Engineering Economics Example: We need to solve the equation for i: Equivalently, find the root of: Bracketing Methods (Bisection method)

18 E. T. S. I. Caminos, Canales y Puertos18 Excel Bracketing Methods (Bisection method)

19 E. T. S. I. Caminos, Canales y Puertos19 Engineering Economics Example: Score Sheet for Rootfinding Example: MethodInitial Est(s).  s = 2 E-2  s = 2 E-7 Bisection(0.00, 1.00)926 (0.05, 0.15)622 Convergence guaranteed: Bracketing Methods (Bisection method)

20 E. T. S. I. Caminos, Canales y Puertos20 Bracketing Methods (Bisection method) One important advantage of this method is that one can calculate the number of required iterations for a given error.

21 E. T. S. I. Caminos, Canales y Puertos21 Parachutist Example: Bracketing Methods (Bisection method)

22 E. T. S. I. Caminos, Canales y Puertos22 Parachutist Example: Bracketing Methods (Bisection method)

23 E. T. S. I. Caminos, Canales y Puertos23 Bisection Method Advantages: 1. Simple 2. Good estimate of maximum error: 3. Convergence guaranteed Disadvantages: 1. Slow 2. Requires two good initial estimates which define an interval around root:  use graph of function,  incremental search, or  trial & error Bracketing Methods (Bisection method)

24 E. T. S. I. Caminos, Canales y Puertos24 x False-position Method f(x) f(x u ) (x u ) (x 1 ) f(x 1 ) f(x r ) f(x 1 ) f(x r ) > 0 x 1 = x r f(x) f(x u ) f(x 1 ) (x 1 ) (x u ) (x r ) f(x r ) Bracketing Methods (False-position Method)

25 E. T. S. I. Caminos, Canales y Puertos25 Similar to bisection. Uses linear interpolation to approximate the root x r : 1) 2) Revise the bracket:f(x 1 ) f(x r ) x u, f(x 1 ) f(x r ) > 0,x r –> x 1 3) Repeat steps 1-2 until: a) |f(x r )| < k, b)  a <  s, with  a = c) |x u – x 1 | = d d) maximum # of iterations is reached. (Always do this in iteration algorithms.) Bracketing Methods (False-position Method)

26 E. T. S. I. Caminos, Canales y Puertos26 Excel Bracketing Methods (False-position Method)

27 E. T. S. I. Caminos, Canales y Puertos27 Bracketing Methods (False-position Method)

28 E. T. S. I. Caminos, Canales y Puertos28 Score Sheet for False-Position Example: MethodInitial Est(s).  s = 2 E-2  s = 2 E-7 Bisection(0.00, 1.00)926 (0.05, 0.15)622 False-pos.(0.00, 1.00)1128 (0.05, 0.15)314 Bracketing Methods (False-position Method)

29 E. T. S. I. Caminos, Canales y Puertos29 Parachutist Example: Bracketing Methods (False-position Method)

30 E. T. S. I. Caminos, Canales y Puertos30 Parachutist Example: Bracketing Methods (False-position Method)

31 E. T. S. I. Caminos, Canales y Puertos31 There are some cases in which the false position method is very slow, and the bisection method gives a faster solution. Bracketing Methods (False-position Method)

32 E. T. S. I. Caminos, Canales y Puertos32 Summary of False-Position Method: Advantages: 1. Simple 2. Brackets the Root Disadvantages: 1. Can be VERY slow 2. Like Bisection, need an initial interval around the root. Bracketing Methods (False-position Method)

33 E. T. S. I. Caminos, Canales y Puertos33 Roots of Equations - Open Methods Characteristics: 1. Initial estimates need not bracket the root 2. Generally converge faster 3. NOT guaranteed to converge Open Methods Considered: - One Point Iteration - Newton-Raphson Iteration - Secant Method Open Methods

34 E. T. S. I. Caminos, Canales y Puertos34 Open Methods An alternative method consists of separating the function into two parts.

35 E. T. S. I. Caminos, Canales y Puertos35 Fixed point Method  predict a value of x i+1 as a function of x i. Convert f(x) = 0 to x = g(x)  iteration steps:x i+1 = g(x i ) x(new) = g(x(old) ) Open Methods (Fixed point method)

36 E. T. S. I. Caminos, Canales y Puertos36 Example II: x = sin(x) –> x i+1 = sin(x i ) OR x = arcsin(x) –> x i+1 = arcsin(x i ) Example I: Open Methods (Fixed point method)

37 E. T. S. I. Caminos, Canales y Puertos37 Convergence: Does x move closer to real root (?) Depends on: 1. nature of the function 2. accuracy of the initial estimate Interested in: 1. Will it converge or will it diverge? 2. How fast will it converge ? (rate of convergence) Open Methods (Fixed point method)

38 E. T. S. I. Caminos, Canales y Puertos38 Convergence of the Fixed point Method: Root satisfies: x r = g(x r ) The Taylor series for function g is: x i+1 = g(x r ) + g'(x)(x i - x r )x r < x < x i Subtracting the second equation from the first yields (x r – x i+1 ) = g'(x) (x r – x i ) or 1. True error for next iteration is smaller than the true error in the previous iteration if |g'(x)| < 1.0 (it will converge). 2. Because g'(x) is almost constant, the new error is directly proportional to the old error (linear rate of convergence). Open Methods (Fixed point method)

39 E. T. S. I. Caminos, Canales y Puertos39 Further Considerations: Convergence depends on how f(x) = 0 is converted into x = g(x) So... Convergence may be improved by recasting the problem. Open Methods (Fixed point method)

40 E. T. S. I. Caminos, Canales y Puertos40 can be small, even though x new is not close to root. Remedy: Do not completely rely on  a to ensure that the problem is solved. Check to make sure |f(x new ) | < . Convergence Problem: For slowly converging functions Open Methods (Fixed point method)

41 E. T. S. I. Caminos, Canales y Puertos41 Open Methods (Fixed point method)

42 E. T. S. I. Caminos, Canales y Puertos42 Open Methods

43 E. T. S. I. Caminos, Canales y Puertos43 Two Fundamental Approaches 1. Bracketing or Closed Methods - Bisection Method - False-position Method 2. Open Methods - One Point Iteration - Newton-Raphson Iteration - Secant Method Roots of Equations

44 E. T. S. I. Caminos, Canales y Puertos44 Newton-Raphson Method: Geometrical Derivation: Slope of tangent at x i is Solve for x i+1 : [Note that this is the same form as the generalized one- point iteration, x i+1 = g(x i )] Open Methods (Newton-Raphson Method)

45 E. T. S. I. Caminos, Canales y Puertos45 Newton-Raphson Method x i = x i+1 Tangent w/slope=f '(x i ) x f(x) f(x i ) xixi f(x i+1 ) x f(x) f(x i ) (x i ) f(x i+1 ) x i+ 1 Open Methods (Newton-Raphson Method)

46 E. T. S. I. Caminos, Canales y Puertos46 First order Taylor Series Derivation: 0 = f( x r )  f(x i ) + f '(x i ) (x r – x i ) solve for x r to yield next guess x i+1 : This has the form x i+1 = g(x i ) with: Open Methods (Newton-Raphson Method)

47 E. T. S. I. Caminos, Canales y Puertos47 Newton-Raphson iteration: This iteration process is repeated until: 1.f(x i+1 )  0, i.e., | f(x i+1 ) | < , with  = small number Maximum number of iterations is reached. Open Methods (Newton-Raphson Method)

48 E. T. S. I. Caminos, Canales y Puertos48 Open Methods a) Inflection point in the neighboor of a root. b) Oscilation in the neighboor of a maximum or minimum. c) Jumps in functions with several roots. d) Existence of a null derivative.

49 E. T. S. I. Caminos, Canales y Puertos49 Bond Example: To apply Newton-Raphson method to: We need the derivative of the function: Open Methods (Newton-Raphson Method)

50 E. T. S. I. Caminos, Canales y Puertos50 Score Sheet for Newton-Raphson Example: MethodInitial Est(s).  s = 2 E-2  s = 2 E-7 Bisection(0.00, 1.00)926 (0.05, 0.15)622 False-pos.(0.00, 1.00)1128 (0.05, 0.15)314 N-R1.0divergesdiverges 0. 52, but wrong EXCEL Open Methods (Newton-Raphson Method)

51 E. T. S. I. Caminos, Canales y Puertos51 Error Analysis for N-R : Recall that Taylor Series gives: where x r  x  x i and f(x r ) = 0 Open Methods (Newton-Raphson Method)

52 E. T. S. I. Caminos, Canales y Puertos52 Dividing through by f '(x i ) yields E i+1 is proportional to E i 2 ==> quadratic rate of convergence. OR Open Methods (Newton-Raphson Method)

53 E. T. S. I. Caminos, Canales y Puertos53 Summary of Newton-Raphson Method: Advantages: 1.Can be fast Disadvantages: 1.May not converge 2. Requires a derivative Open Methods (Newton-Raphson Method)

54 E. T. S. I. Caminos, Canales y Puertos54 Secant Method Approx. f '(x) with backward FDD: Substitute this into the N-R equation: to obtain the iterative expression: Open Methods (Secant Method)

55 E. T. S. I. Caminos, Canales y Puertos55 Secant Method x i = x i+1 x f(x) f(x i ) xixi f(x i-1 ) f(x) x i-1 x i+ 1 x f(x i ) xixi f(x i-1 ) x i-1 x i+ 1 Open Methods (Secant Method)

56 E. T. S. I. Caminos, Canales y Puertos56 1) Requires two initial estimates: x i-1 and x i These do NOT have to bracket root ! 2) Maintains a strict sequence: Repeated until: a. | f(x i+1 ) | < k with k = small number b. c. Max. number of iterations is reached. 3. If x i and x i+1 were to bracket the root, this would be the same as the False-Position Method. BUT WE DON'T! Open Methods (Secant Method)

57 E. T. S. I. Caminos, Canales y Puertos57 Open Methods (Secant Method) –In the secant method, the values are replaced in a strict sequence, x i+1 to x i, and this to x i-1. Thus, the new values can be on the de same sode of the root, and sometimes diverge.

58 E. T. S. I. Caminos, Canales y Puertos58 Score Sheet for Secant Example: MethodInitial Est(s).  s = 2 E-2  s = 2 E-7 Bisection(0.00, 1.00)926 (0.05, 0.15)622 False-pos. (0.00, 1.00)1128 (0.05, 0.15)314 N-R1.0divergesdiverges 0.52, but wrong Secant(0, 1)divergesdiverges (0.00, 0.50)4, but wrong (chaotic)27 (0.05, 0.15)36 Open Methods (Secant Method)

59 E. T. S. I. Caminos, Canales y Puertos59 Why do open methods fail? Function may not look linear. Remedy: recast into a linear form. For example, Is a poorly constrained problem in that there is a large, nearly flat zone for which the derivative is near zero. Recast as: i f(i) = 0 = 7,500 i [ 1 - (1+i) -20 ] Open Methods

60 E. T. S. I. Caminos, Canales y Puertos60 Recast as:i f(i) = 0 = 7,500 i [ 1 - (1+i) -20 ] –The recast function, "i f(i) will have the same roots as f(i) plus an additional root at i = 0. –It will not have a large, flat zone, thus: h(i) = i f(i) = 7,500 i – 1000 [ 1 – (1+ i) –20 ] – To apply N-R we also need the first derivative: h'(i) = 7, ,000 (1+ i) -21 Open Methods

61 E. T. S. I. Caminos, Canales y Puertos61 Score Sheet for Open Methods: MethodInitial Est(s).  s = 2 E-2  s = 2 E-7 N-R1.0divergesdiverges 0. 52, but wrong Secant(0.00, 0.50)4, but wrong27 (0.05, 0.15)36 N-R [as i f(i)] crazy results** 0.03converges to i=0** Open Methods

62 E. T. S. I. Caminos, Canales y Puertos62 Cases of Multiple Roots Multiple Roots: f(x) = (x – 2) 2 (x – 4) x = 2 represents two of the three roots. Open Methods

63 E. T. S. I. Caminos, Canales y Puertos63 Problems and Approaches: Cases of Multiple Roots 1.Bracketing Methods fail locating x = 2. Note that f(x ) f(x r ) > At x = 2, f(x) = f '(x) = 0. Newton-Raphson and Secant methods may experience problems. Rate of convergence drops to linear. Luckily, f(x)  0 faster than f '(x)  0 3. Other remedies, recasting problem: Find x such that u(x) = 0 where : Note that u(x) and f(x) have same roots. Open Methods

64 E. T. S. I. Caminos, Canales y Puertos64 m = 1: linear convergence m = 2: quadratic convergence Method m Bisection1 False Position1 Secant, mult. root1 NR, mult. root1 Secant, single root1.618"super linear" NR, single root2 Accel. NR, mult. root (f(x)/f'(x)=0)2 Summary -- Rates of Convergence

65 E. T. S. I. Caminos, Canales y Puertos65 Solve f i (x 1,..., x n ) = 0 for i = 1,...,n Let X = (x 1,..., x n ) T  Given intial guess X t, try to solve where:  Obtain  X = (X i+1 – X i ) from linear equations: Multivariate (Multidimensional) Equations

66 E. T. S. I. Caminos, Canales y Puertos66 1.Always limit number of iterations using an outer DO loop. The problem may not converge and could try to go on forever. 2.Absolute error criteria for "small" differences: | x t - x t-1 | <  3. Relative error criteria for "relatively small" changes | x t – x t-1 | <  | x t | 4. Can combined error criteria 2 & 3 for large and small x-values: | x t – x t-1 | <  +  | x t | 5. Converge on zero residual | f(x t ) | <  Alternative Stopping Criteria

67 E. T. S. I. Caminos, Canales y Puertos67 Stopping Criteria: | x i – x i-1 | <  +  |x i | or| f(x i ) | <  orMax. iterations Convergence Criteria: | x i – x i-1 | <  +  |x i | and| f(x i ) | <  N-R and Secant Confirmation of Convergent Behavior: x in feasible region and| f(x i ) | ≤ 0.5 | f(x i-1 ) | and| x i – x i-1 | ≤ 0.6 | x i-1 – x i-2 | otherwise, do Bisection for a while. Three Performance Criteria

68 E. T. S. I. Caminos, Canales y Puertos68 A real rootfinding problem can be viewed as having three phases: 1) Opening moves: One needs to find the region of the parameter space in which desired root can be found. Understanding of problem, physical insight, and common sense are valuable. 2) Middle Game: Use robust algorithm to reduce initial region of uncertainty. 3) End game: Generate a highly accurate solution in a few iterations. Three Phase Rootfinding Strategy


Download ppt "E. T. S. I. Caminos, Canales y Puertos1 Engineering Computation Part 2."

Similar presentations


Ads by Google