Civil Engineering Computation Numerical Methods : Root Finding and Optimization – Part 2 2 Root Finding and Optimization - Part 2 ROOT LOCATION WITH NUMERICAL METHODS

3 Root Finding and Optimization - Part 2 Root Location – False Position ¢ Another method of root location that is relatively easy to program is the method of False Position ¢ Successive iteration of the root estimate are made using

f (xupper )(xlower − xupper ) xnew = xupper − f (xlower ) − f (xupper )

4 Root Finding and Optimization - Part 2 Root Location – False Position

¢ Now we can try with the same problem.

gm ⎛ gcd ⎞ v = tanh⎜ t⎟ cd ⎝ m ⎠

5 Root Finding and Optimization Root Location – False Position

¢ The problem is to determine the mass of the bungee jumper (m) such that a velocity (v) of 36 m/s is attained after a time (t) of 4 s. ¢ The acceleration of gravity (g) is 9.81 2 m/s and the drag coefficient (cd) is 0.25 kg/m.

gm ⎛ gcd ⎞ v = tanh⎜ t⎟ cd ⎝ m ⎠

6 Root Finding and Optimization cha01102_ch05_123-150.qxd 12/17/10 8:01 AM Page 148 Problem 1

¢ The saturation concentration of dissolved148 oxygenROOTS: in freshwater BRACKETING METHODScan be calculated with the equation 5.8 The saturation concentration of dissolved oxygen in and freshwater can be calculated with the equation y2 Ac 3y 1.575701 105 = + 2 ln osf 139.34411 × Solve for the critical depth using the graphical method, = − + Ta (a) 6.642308 107 1.243800 1010 (b) bisection, and (c) false position. For (b) and (c) use 2 × 3× initial guesses of xl 0.5 and xu 2.5, and iterate until the − Ta + Ta = = 11 approximate error falls below 1% or the number of iterations 8.621949 10 exceeds 10. Discuss your results. 4× − Ta 5.11 The Michaelis-Menten model describes the kinetics of where o the saturation concentration of dissolved oxy- 7 Rootsf Finding and Optimization - Part 2 enzyme mediated reactions: = 1 gen in freshwater at 1 atm (mg L− ); and Ta absolute = dS S temperature (K). Remember that Ta T 273.15, where vm dt = − ks S T temperature (°C). According to this= equation,+ saturation + where S substrate concentration (moles/L), v maxi- decreases= with increasing temperature. For typical natural m mum uptake= rate (moles/L/d), and k the half-saturation= waters in temperate climates, the equation can be used to de- s constant, which is the substrate level at= which uptake is half termine that oxygen concentration ranges from 14.621 mg/L of the maximum [moles/L]. If the initial substrate level at at 0 °C to 6.949 mg/L at 35 °C. Given a value of oxygen con- t 0 is S0, this differential equation can be solved for centration, this formula and the bisection method can be = S S0 vm t ks ln(S0/S) used to solve for temperature in °C. = − + (a) If the initial guesses are set as 0 and 35 °C, how many Develop an M-file to generate a plot of S versus t for the bisection iterations would be required to determine tem- case where S0 8 moles/L, vm 0.7 moles/L/d, and = = perature to an absolute error of 0.05 °C? ks 2.5 moles/L. = (b) Based on (a), develop and test a bisection M-file function 5.12 Areversible chemical reaction to determine T as a function of a given oxygen concen- 2A B → C tration. Test your function for osf 8, 10 and 14 mg/L. + = ← Check your results. can be characterized by the equilibrium relationship 5.9 Abeam is loaded as shown in Fig. P5.9. Use the bisec- c K c tion method to solve for the position inside the beam where 2 = cacb there is no moment. where the nomenclature c represents the concentration of con- 5.10 Water is flowing in a trapezoidal channel at a rate of i stituent i. Suppose that we define a variable x as representing Q 20 m3/s. The critical depth y for such a channel must the number of moles of C that are produced. Conservation of satisfy= the equation mass can be used to reformulate the equilibrium relationship as Q2 0 1 B (cc,0 x) 3 K = − gAc +2 = (ca,0 2x) (cb,0 x) where g 9.81 m/s2, A the cross-sectional (m2), − − c where the subscript 0 designates the initial concentration and B the= width of the channel= at the surface (m). For this of each constituent. If K 0.016, c 42, c 28, and case, the= width and the cross-sectional area can be related to a,0 b,0 c 4, determine the value= of x. = = depth y by c,0 = (a) Obtain the solution graphically. B 3 y = + (b) On the basis of (a), solve for the root with initial guesses of xl 0 and xu 20 to εs 0.5%. Choose either bisection or 100 lb/ft 100 lb false= position= to obtain =your solution. Justify your choice. 5.13 Figure P5.13a shows a uniform beam subject to a lin- early increasing distributed load. The equation for the result- ing elastic curve is (see Fig. P5.13b) w y 0 ( x5 2L2x3 L4x) (P5.13) = 120EIL − + − 3’ 3’ 4’ 2’ Use bisection to determine the point of maximum deflection (i.e., the value of x where dy/dx 0). Then substitute this value into Eq. (P5.13) to determine= the value of the maximum FIGURE P5.9 deflection. Use the following parameter values in your Problem 1

¢ Where osf = the saturation concentration of dissolved oxygen in −1 freshwater at 1 atm (mg L ); and Ta = absolute temperature (K).

¢ Remember that Ta = T + 273.15, where T = temperature (°C). ¢ According to this equation, saturation decreases with increasing temperature.

8 Root Finding and Optimization - Part 2 Problem 1

¢ For typical natural waters in temperate climates, the equation can be used to determine that oxygen concentration ranges from 14.621 mg/L at 0 °C to 6.949 mg/L at 35 °C. ¢ Given a value of oxygen concentration, this formula and the bisection method can be used to solve for temperature in °C. ¢ If the initial guesses are set as 0 and 35 °C, how many bisection iterations would be required to determine temperature to an absolute error of 0.05 °C and what is the temperature?

9 Root Finding and Optimization - Part 2 cha01102_ch05_123-150.qxd 12/17/10 8:01 AM Page 148

148 ROOTS: BRACKETING METHODS

5.8 The saturation concentration of dissolved oxygen in and freshwater can be calculated with the equation y2 Ac 3y 1.575701 105 = + 2 ln osf 139.34411 × Solve for the critical depth using the graphical method, = − + Ta (a) 6.642308 107 1.243800 1010 (b) bisection, and (c) false position. For (b) and (c) use 2 × 3× initial guesses of xl 0.5 and xu 2.5, and iterate until the − Ta + Ta = = 11 approximate error falls below 1% or the number of iterations 8.621949 10 exceeds 10. Discuss your results. 4× − Ta 5.11 The Michaelis-Menten model describes the kinetics of where osf the saturation concentration of dissolved oxy- enzyme mediated reactions: = 1 gen in freshwater at 1 atm (mg L− ); and Ta absolute = dS S temperature (K). Remember that Ta T 273.15, where vm dt = − ks S T temperature (°C). According to this= equation,+ saturation + where S substrate concentration (moles/L), v maxi- decreases= with increasing temperature. For typical natural m mum uptake= rate (moles/L/d), and k the half-saturation= waters in temperate climates, the equation can be used to de- s constant, which is the substrate level at= which uptake is half termine that oxygen concentration ranges from 14.621 mg/L of the maximum [moles/L]. If the initial substrate level at at 0 °C to 6.949 mg/L at 35 °C. Given a value of oxygen con- t 0 is S0, this differential equation can be solved for centration, this formula and the bisection method can be = S S0 vm t ks ln(S0/S) used to solve for temperature in °C. = − + (a) If the initial guesses are set as 0 and 35 °C, how many Develop an M-file to generate a plot of S versus t for the bisection iterations would be required to determine tem- case where S0 8 moles/L, vm 0.7 moles/L/d, and = = perature to an absolute error of 0.05 °C? ks 2.5 moles/L. = (b) Based on (a), develop and test a bisection M-file function 5.12 Areversible chemical reaction to determine T as a function of a given oxygen concen- 2A B → C tration. Test your function for osf 8, 10 and 14 mg/L. + = ← Check your results. can be characterized by the equilibrium relationship 5.9 Abeam is loaded as shown in Fig. P5.9. Use the bisec- c K c tion method to solve for the position inside the beam where 2 Problem 2 = cacb there is no moment. where the nomenclature ci represents the concentration of con- 5.10¢ WaterWater is flowing is in aflowing trapezoidal in a trapezoidal channel at a rate of 3 stituent i. Suppose that we define a variable x as representing Qchannel20 at m a rate3/s. of The Q = 20 critical m /s. The depth y for such a channel must critical= depth y for such a channel the number of moles of C that are produced. Conservation of satisfymust satisfy the theequation equation mass can be used to reformulate the equilibrium relationship as Q2 0 1 B (cc,0 x) = − gA3 K + c = (c 2x)2(c x) 2 2 a,0 b,0 where g 9.81 m/s , Ac the cross-sectional area (m ), − − 10 Root Finding and Optimization - Part 2 where the subscript 0 designates the initial concentration and B the= width of the channel= at the surface (m). For this of each constituent. If K 0.016, c 42, c 28, and case, the= width and the cross-sectional area can be related to a,0 b,0 c 4, determine the value= of x. = = depth y by c,0 = (a) Obtain the solution graphically. B 3 y = + (b) On the basis of (a), solve for the root with initial guesses of xl 0 and xu 20 to εs 0.5%. Choose either bisection or 100 lb/ft 100 lb false= position= to obtain =your solution. Justify your choice. 5.13 Figure P5.13a shows a uniform beam subject to a lin- early increasing distributed load. The equation for the result- ing elastic curve is (see Fig. P5.13b) w y 0 ( x5 2L2x3 L4x) (P5.13) = 120EIL − + − 3’ 3’ 4’ 2’ Use bisection to determine the point of maximum deflection (i.e., the value of x where dy/dx 0). Then substitute this value into Eq. (P5.13) to determine= the value of the maximum FIGURE P5.9 deflection. Use the following parameter values in your Problem 2

2 ¢ where g = 9.81 m/s , Ac = the cross- sectional area (m2), and B = the width of the channel at the surface (m). For this case, the width and the cross- sectional area can be related to depth y by B = 3+ y

11 Root Finding and Optimization - Part 2 Problem 2

¢ and y2 A = 3y + c 2

12 Root Finding and Optimization - Part 2 Problem 2

¢ Solve for the critical depth using l bisection, and l false position.

¢ Use initial guesses of xl = 0.5 and xu = 2.5, and iterate until the approximate error falls below 0.1% or the number of iterations exceeds 20.

13 Root Finding and Optimization - Part 2 Problem 3

¢ For fluid flow in pipes, friction is described by a dimensionless number, the Fanning friction factor f. ¢ The Fanning friction factor is dependent on a number of parameters related to the size of the pipe and the fluid, which can all be represented by another dimensionless quantity, the Reynolds number Re.

14 Root Finding and Optimization - Part 2 cha01102_ch05_123-150.qxd 12/17/10 8:01 AM Page 149

PROBLEMS 149

5.16 The resistivity ρ of doped silicon is based on the w0 charge q on an electron, the electron density n, and the elec- tron mobility µ. The electron density is given in terms of

the doping density N and the intrinsic carrier density ni. The electron mobility is described by the temperature T, the ref-

erence temperature T0, and the reference mobility µ0. The equations required to compute the resistivity are L 1 ρ (a) = qnµ where 2.42 1 2 2 T − (x = L, y =0) n N N 4ni and µ µ0 = 2 + + = T0 (x = 0, y =0) ! " # ! # x Determine N, given T0 300 K, T 1000 K, µ0 2 1 = 19 = 9 =3 1360 cm (V s)− , q 1.7 10− C, ni 6.21 10 cm− , and a desired ρ =6.5 ×106 Vs cm/C.= Employ× initial = × guesses of N 0 and 2.5 1010. Use (a) bisection and = × (b) (b) the false position method. 5.17 Atotal charge Q is uniformly distributed around a ring- shaped conductor with radius a. A charge q is located at a FIGURE P5.13 distance x from the center of the ring (Fig. P5.17). The force exerted on the charge by the ring is given by 1 qQx 2 F computation: L 600 cm, E 50,000 kN/cm , I 2 2 3/2 = = = = 4πe0 (x a ) 30,000 cm4,andw 2.5 kN/cm. + 0 = 12 2 2 5.14 You buy a $35,000 vehicle for nothing down at $8,500 where e0 8.9 10− C /(N m ). Find the distance x where = × 5 the force is 1.25 N if q and Q are 2 10− Cforaringwitha per year for 7 years. Use the bisect function from Fig. 5.7 × to determine the interest rate that you are paying. Employ radius of 0.85 m. initial guesses for the interest rate of 0.01 and 0.3 and a stop- 5.18 For fluid flow in pipes, friction is described by a di- ping criterion of 0.00005. The formula relating present mensionless number, the Fanning friction factor f. The Fan- worth P, annual payments A, number of years n, and interest ning friction factor is dependent on a number of parameters rate i is relatedProblem to the size3 of the pipe and the fluid, which can i(1 i)n all be represented by another dimensionless quantity, the A P + Reynolds¢ A formulanumber thatRe. predicts A formula f given Re that is predicts f given Re is = (1 i)n 1 the von Karman equation: + − the von Karman equation: 5.15 Many fields of engineering require accurate population 1 estimates. For example, transportation engineers might find 4 log Re f 0.4 √ f = 10 − it necessary to determine separately the population growth Typical values for$ the %Reynolds& number for turbulent flow trends of a city and adjacent suburb. The population of the are 10,000 to 500,000 and for the Fanning friction factor are urban area is declining with time according to 0.00115 to 0.01.Root Finding Develop and Optimization - Part a 2 function that uses bisection to solve ku t Pu(t) Pu,maxe− Pu,min = + for f given a user-supplied value of Re between 2,500 and while the suburban population is growing, as in P ( ) s,max Ps t k t = 1 [Ps,max/P0 1]e s + − − a where P , k , P , P , and k empirically derived pa- u,max u s,max 0 s = x rameters. Determine the time and corresponding values of q Pu(t) and Ps(t) when the suburbs are 20% larger than the city. The parameter values are P 80,000, k 0.05/yr, u,max = u = Q Pu,min 110,000 people, Ps,max 320,000 people, P0 10,000= people, and k 0.09/yr. =To obtain your solutions,= s = FIGURE P5.17 use (a) graphical, and (b) false-position methods. Problem 3

¢ Typical values for the Reynolds number for turbulent flow are 10,000 to 500,000 and for the Fanning friction factor are 0.001 to 0.01. ¢ Develop a macro that uses bisection to solve for f given a user-supplied value of Re between 2,500 and 1,000,000. ¢ Design the macro so that it ensures that the error in the result is < 0.000005 or that the number of iterations does not exceed 50. Utilize Double for real variables.

16 Root Finding and Optimization - Part 2 Root Location – Secant Method ¢ The two methods we considered so far are known as closed methods because they require that we choose bounds for the interval in which the root will lay ¢ There are other methods known as Open methods that do not put this constraint on the search

17 Root Finding and Optimization - Part 2 Root Location – Secant Method ¢ One of the most commonly used of these methods is known as the Secant Method.

¢ In this case, we don’t have an xupper, xlower, and xmid. ¢ We have successive iterations of the root

which we label x1, x2, x3, x4, etc.

18 Root Finding and Optimization - Part 2 cha01102_ch06_151-181.qxd 12/17/10 8:05 AM Page 162

162 ROOTS: OPEN METHODS

inconvenient to evaluate. For these cases, the derivative can be approximated by a back- ward finite divided difference:

f (xi 1) f (xi ) f !(xi ) − − =∼ xi 1 xi − − This approximation can be substituted into Eq. (6.6) to yield the following iterative equation:

f (xi )(xi 1 xi ) xi 1 xi − − (6.8) + = − f (xi 1) f (xi ) − − Equation (6.8) is the formula for the secant method. Notice that the approach requires two initial estimates of x. However, because f (x) is not required to change signs between the estimates, it is not classified as a bracketing method. Rather than using two arbitrary values to estimate the derivative, an alternative ap- proach involves a fractional perturbation of the independent variable to estimate f !(x),

Root Locationf (xi δ–x iSecant) f (xi ) f !(xi ) ∼ + − Method= δxi ¢ The formula used to generate the next root wherefrom the δ currenta smalliteration perturbation is fraction. This approximation can be substituted into Eq. (6.6) to= yield the following iterative equation:

δxi f (xi ) xi 1 xi (6.9) + = − f (xi δxi ) f (xi ) + − We call this the modified secant method. As in the following example, it provides a nice means to attain the efficiency of Newton-Raphson without having to compute derivatives. 19 Root Finding and Optimization - Part 2

EXAMPLE 6.5 Modified Secant Method Problem Statement. Use the modified secant method to determine the mass of the bungee jumper with a drag coefficient of 0.25 kg/m to have a velocity of 36 m/s after 4 s of free fall. Note: The acceleration of gravity is 9.81 m/s2. Use an initial guess of 50 kg and a 6 value of 10− for the perturbation fraction.

Solution. Inserting the parameters into Eq. (6.9) yields First iteration: x 50 f (x ) 4.57938708 0 = 0 = − x δx 50.00005 f (x δx ) 4.579381118 0 + 0 = 0 + 0 = − 10 6(50)( 4.57938708) x 50 − − 1 = − 4.579381118 ( 4.57938708) − − − 88.39931( εt 38.1% εa 43.4%) = | |= ;| |= cha01102_ch06_151-181.qxd 12/17/10 8:05 AM Page 162

162 ROOTS: OPEN METHODS

inconvenient to evaluate. For these cases, the derivative can be approximated by a back- ward finite divided difference:

f (xi 1) f (xi ) f !(xi ) − − =∼ xi 1 xi − − This approximation can be substituted into Eq. (6.6) to yield the following iterative equation:

f (xi )(xi 1 xi ) xi 1 xi − − (6.8) + = − f (xi 1) f (xi ) − − Equation (6.8) is the formula for the secant method. Notice that the approach requires two initial estimates of x. However, because f (x) is not required to change signs between the estimates, it is not classified as a bracketing method. Rather than using two arbitrary values to estimate the derivative, an alternative ap- proach involves a fractional perturbation of the independent variable to estimate f !(x),

Root Locationf (xi δ–x iSecant) f (xi ) f !(xi ) ∼ + − Method= δxi ¢ The δ is some small fractional value known whereas a perturbation δ a small factor. perturbation fraction. This approximation can be substituted into Eq. (6.6) to= yield the following iterative equation:

δxi f (xi ) xi 1 xi (6.9) + = − f (xi δxi ) f (xi ) + − We call this the modified secant method. As in the following example, it provides a nice means to attain the efficiency of Newton-Raphson without having to compute derivatives. 20 Root Finding and Optimization - Part 2

EXAMPLE 6.5 Modified Secant Method Problem Statement. Use the modified secant method to determine the mass of the bungee jumper with a drag coefficient of 0.25 kg/m to have a velocity of 36 m/s after 4 s of free fall. Note: The acceleration of gravity is 9.81 m/s2. Use an initial guess of 50 kg and a 6 value of 10− for the perturbation fraction.

Solution. Inserting the parameters into Eq. (6.9) yields First iteration: x 50 f (x ) 4.57938708 0 = 0 = − x δx 50.00005 f (x δx ) 4.579381118 0 + 0 = 0 + 0 = − 10 6(50)( 4.57938708) x 50 − − 1 = − 4.579381118 ( 4.57938708) − − − 88.39931( εt 38.1% εa 43.4%) = | |= ;| |= Root Location – Secant Method ¢ Returning to the bungee jumper problem.

δ 0.00001

Iteraon x f(x) x+δx f(x+δx) 1 150 0.14 150.0015 0.14 2 142.4045322 -0.01 142.4059562 -0.01 3 142.7369355 0.00 142.7383628 0.00 4 142.7376331 0.00 142.7390605 0.00 5 142.7376331 0.00 142.7390605 0.00 6 142.7376331 0.00 142.7390605 0.00

21 Root Finding and Optimization - Part 2 cha01102_ch06_151-181.qxd 12/17/10 8:05 AM Page 181

PROBLEMS 181

where G(s) system gain, C(s) system output, N(s) guesses of xi 1 0 and xi 1. Assuming that conver- system input,= and s Laplace transform= complex frequency.= gence is not an− issue,= choose the= technique that is best suited Use MATLAB to find= the roots of the numerator and de- to this problem. Justify your choice. nominator and factor these into the form 6.29 You must determine the root of the following easily differentiable function: (s a1)(s a2)(s a3) G(s) + + + 0.5x = (s b1)(s b2)(s b3)(s b4) e 5 5x + + + + = − where ai and bi the roots of the numerator and denomina- Pick the best numerical technique, justify your choice, and Problem 4 = tor, respectively. then use that technique to determine the root. Note that it is ¢ The6.25 ManningThe equation Manning can be equation written for acan be written for a rectangular known that for positive initial guesses, all techniques except rectangular open channel as open channel as fixed-point iteration will eventually converge. Perform iter- √S(BH)5/3 ations until the approximate relative error falls below 2%. If Q you use a bracketing method, use initial guesses of xl 0 = n(B 2H)2/3 = + and xu 2. If you use the Newton-Raphson or the modified 3 = where Q flow (m /s), S slope (m/m), H depth (m), secant method, use an initial guess of xi 0.7. If you use = = = = and n the Manning roughness coefficient. Develop a the secant method, use initial guesses of xi 1 0 and 22 Root= Finding and Optimization - Part 2 − = fixed-point iteration scheme to solve this equation for H xi 2. = given Q 5, S 0.0002, B 20, and n 0.03. Perform the 6.30 (a) Develop an M-file function to implement Brent’s = = = = computation until εa is less than εs 0.05%. Prove that root-location method. Base your function on Fig. 6.10, but your scheme converges for all initial guesses= greater than or with the beginning of the function changed to equal to zero. function [b,fb] = fzeronew(f,xl,xu,varargin) 6.26 See if you can develop a foolproof function to compute % fzeronew: Brent root location zeroes the friction factor based on the Colebrook equation as %[b,fb] = fzeronew(f,xl,xu,p1,p2,...): described in Sec. 6.7. Your function should return a precise % uses Brent’s method to find the root of f 7 result for Reynolds number ranging from 4000 to 10 and for % input: ε/D ranging from 0.00001 to 0.05. % f = name of function 6.27 Use the Newton-Raphson method to find the root of % xl, xu = lower and upper guesses 0.5x % p1,p2,... = additional parameters used by f f (x) e− (4 x) 2 = − − % output: Employ initial guesses of (a) 2, (b) 6, and (c) 8. Explain your % b = real root results. % fb = function value at root Given 6.28 Make the appropriate modifications so that the function per- f (x) 2x6 1.5x4 10x 2 forms as outlined in the documentation statements. In addi- = − − + + tion, include error traps to ensure that the function’s three Use a root-location technique to determine the maximum of required arguments (f,xl,xu) are prescribed, and that the this function. Perform iterations until the approximate rela- initial guesses bracket a root. tive error falls below 5%. If you use a bracketing method, (b) Test your function by using it to solve for the root of the use initial guesses of x 0 and x 1. If you use the l u function from Example 5.6 using Newton-Raphson or the modified= secant= method, use an ini- tial guess of xi 1. If you use the secant method, use initial >> [x,fx] = fzeronew(@(x,n) x^n-1,0,1.3,10) = Problem 4

¢ Where Q = flow (m3/s), S = slope (m/m), H = depth (m), and n = the Manning roughness coefficient. ¢ Use the Secant method to solve this equation for H given Q = 5, S = 0.0002, B = 20, and n = 0.03. ¢ Perform the computation until your error is less than 0.05% or your number of iterations is greater than 50.

23 Root Finding and Optimization - Part 2 OPTIMIZATION

24 Root Finding and Optimization - Part 2 Optimization –

¢ There are times when rather than locate a root, we need to locate the point at which a function is either at a maximum or a minimum ¢ While similar to finding a root, it is not exactly the same. ¢ One method for locating a maximum or minimum is known as a Golden Search utilizing the Golden Ratio, ϕ

25 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ The value of the golden ratio is equal to

1+ 5 φ = = 1.61803398874989...... 2

Your hand creates a golden section in relation to your arm, as the ratio of the of your forearm to the length of your hand is also 1.618

26 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

Given a having sides in the ratio 1:x, ϕ (phi) is defined as the unique number x such that partitioning the original rectangle into a and new rectangle as illustrated above results in a new rectangle which also has sides in the ratio 1:x (i.e., such that the yellow shown above are similar). Such a rectangle is called a golden rectangle, and successive points dividing a golden rectangle into lie on a logarithmic spiral, giving a figure known as a whirling square.

27 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ This ratio appears as the ratio between consecutive terms in the Fibonacci series. ¢ None of that is really critical to the use of the golden ratio in this search, it just is a useful use of the ratio.

1+ 5 φ = = 1.61803398874989...... 2

28 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ In this example, we are going to try and find a

maximum of a function

¢ To begin, the limits of the search xupper and xlower are selected, in this case they do not have to have different signs. ¢ After the limits are selected, we need to generate two internal points using the golden ratio.

29 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ The internal points are generated using

d = (φ −1)(xupper − xlower )

x1 = xlower + d

x2 = xupper − d

30 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ Now the function is evaluated at the internal

points x1 and x2 to generate f(x1) and f(x2).

31 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ If, as shown, f (x1)> f (x2), then the domain of x to the left of x2, from xlower to x2, can be eliminated because it does not contain the maximum.

¢ For this case, x2 becomes xlower for the next round.

32 Root Finding and Optimization - Part 2 Optimization – Golden Ratio

¢ If f (x2)> f (x1), then the domain of x to the right of x1, from x1 to xupper would be eliminated. For this case, x1 becomes xupper for the next round.

33 Root Finding and Optimization - Part 2 Golden Search - Example

¢ Use the golden-section search to find the maximum of x2 f (x) = 2sin x − 10

¢ within the interval from xlower = 0 to xupper = 4.

34 Root Finding and Optimization - Part 2 2

1

0

-1 f(x)

-2

-3

-4 0 0.5 1 1.5 2 2.5 3 3.5 4 x

35 Root Finding and Optimization - Part 2 36 Root Finding and Optimization - Part 2 Problem 5

¢ The deflection of a uniform beam subject to a linearly increasing distributed load can be computed as 5 2 3 4 ¢ y = w0 (−x + 2L x − L x) /(120EIL ) ¢ Given that L = 600 cm, E = 50,000 kN/cm2, I = 4 30,000 cm , and w0 = 2.5 kN/cm, determine the point of maximum deflection using the golden-section search until the approximate error falls below 0.01% with initial guesses of xlower = 0 and xupper = L.

37 Root Finding and Optimization - Part 2 Parabolic Interpolation

¢ A second method of optimization over an interval is known as Parabolic Interpolation ¢ Once again, we start with an interval within which we consider that the maximum (or minimum) occurs ¢ You can identify this by first graphing the function

38 Root Finding and Optimization - Part 2 Parabolic Interpolation

¢ Once you have the interval end points (x0 and x2), you can select a third point within the interval (x1) such that x0

calculate a fourth point (x3) using this formula

2 2 2 2 2 2 f (x0 )(x1 − x2 ) + f (x1 )(x2 − x0 ) + f (x2 )(x0 − x1 ) x3 = 2 f (x0 )(x1 − x2 ) + 2 f (x1 )(x2 − x0 ) + 2 f (x2 )(x0 − x1 )

39 Root Finding and Optimization - Part 2 Parabolic Interpolation

¢ The function is now evaluated at x3 and a process similar to the one we used to reduce the interval in Golden Search is used.

2 2 2 2 2 2 f (x0 )(x1 − x2 ) + f (x1 )(x2 − x0 ) + f (x2 )(x0 − x1 ) x3 = 2 f (x0 )(x1 − x2 ) + 2 f (x1 )(x2 − x0 ) + 2 f (x2 )(x0 − x1 )

40 Root Finding and Optimization - Part 2 Parabolic Interpolation

¢ If f(x3) is greater than f(x1), then the maximum is between x1 and x2 so we can replace the lower bound (x0) with the current x1

¢ If f(x3) is less than f(x1), then the maximum is between x0 and x1 so we can replace the upper bound (x2) with the current x1 2 2 2 2 2 2 f (x0 )(x1 − x2 ) + f (x1 )(x2 − x0 ) + f (x2 )(x0 − x1 ) x3 = 2 f (x0 )(x1 − x2 ) + 2 f (x1 )(x2 − x0 ) + 2 f (x2 )(x0 − x1 )

41 Root Finding and Optimization - Part 2 Problem 6

¢ Develop a macro using parabolic interpretation that will determine the maximum height of a ball if its height is determined by the equation

g 2 y = (tanθ0 )t − 2 2 t + y0 2v0 cos θ0

42 Root Finding and Optimization - Part 2 Problem 6

43 Root Finding and Optimization - Part 2 30

25

20

15 Elevation (m) Elevation

10

5

0 0 10 20 30 40 50 60 70 80 90 100 Elapsed Time (sec)

44 Root Finding and Optimization - Part 2 Problem 6

¢ Where y = the height (m), θ0 = the initial (radians), v0 = the initial velocity (m/ s), g = the gravitational constant = 9.81 m/ 2 s , and y0 = the initial height (m), t is the elapsed time of the ball flight (sec) ¢ Iteration your solution until your error falls below 0.01% or you have made 25 iterations. ¢ Use type Double for your variables.

45 Root Finding and Optimization - Part 2