Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06...

27
Civil Engineering Computation Numerical Methods : Root Finding and Optimization

Transcript of Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06...

Page 1: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Civil Engineering Computation Numerical Methods : Root Finding and Optimization

Page 2: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

ROOT LOCATION WITH NUMERICAL METHODS

Root Finding and Optimization 2

Page 3: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location

¢ While Goal Seek provides us with a terrific tool to solve an equation, it is a bit of a black box method

¢ We really don’t know how it does its job.

Root Finding and Optimization 3

Page 4: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location

¢ There may be times when you really want to locate a specific root of an equation and Goal Seek doesn’t give you that type of control

¢  It is possible to program a numerical method in VBA that will give you better control and allow you to position the region that you are going to search for a root.

Root Finding and Optimization 4

Page 5: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method ¢ The Bisection method takes

advantage of the fact that the function we are searching must change sign as you move through a root.

¢ The Bisection method is a search method in which the interval is always divided in half.

Root Finding and Optimization 5

Page 6: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method ¢  If a function changes sign over an

interval, the function value at the midpoint is evaluated.

¢  The location of the root is then determined as lying within the subinterval where the sign change occurs.

¢  The subinterval then becomes the interval for the next iteration.

¢  The process is repeated until the root is known to the required precision.

Root Finding and Optimization 6

Page 7: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

Example 5.1, we can see that the function changes sign between values of 50 and 200. Theplot obviously suggests better initial guesses, say 140 and 150, but for illustrative purposeslet’s assume we don’t have the benefit of the plot and have made conservative guesses.Therefore, the initial estimate of the root xr lies at the midpoint of the interval

xr = 50 + 2002

= 125

Note that the exact value of the root is 142.7376. This means that the value of 125 calcu-lated here has a true percent relative error of

|!t | =!!!!142.7376 ! 125

142.7376

!!!! " 100% = 12.43%

Next we compute the product of the function value at the lower bound and at the midpoint:

f (50) f (125) = !4.579(!0.409) = 1.871

which is greater than zero, and hence no sign change occurs between the lower bound andthe midpoint. Consequently, the root must be located in the upper interval between 125 and200. Therefore, we create a new interval by redefining the lower bound as 125.

5.4 BISECTION 135

!6

!4

!2

0

250 100 150

First iteration

Second iteration

Third iteration

Fourth iteration

Root

f (m)

m

xl xr xu

xl xr xu

xl xr xu

xl xr xu

FIGURE 5.5A graphical depiction of the bisection method. This plot corresponds to the first four iterationsfrom Example 5.3.

cha01102_ch05_123-150.qxd 12/17/10 8:01 AM Page 135

Root Finding and Optimization 7

Page 8: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method ¢ Back to the bungee jumper problem

when we ignored the buoyance force we found a closed form solution for the velocity at any time t.

v = gmcdtanh gcd

mt

⎝⎜⎞

⎠⎟Root Finding and Optimization 8

Page 9: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method ¢ 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 m/s2 and the drag coefficient (cd) is 0.25 kg/m.

v = gmcdtanh gcd

mt

⎝⎜⎞

⎠⎟

Root Finding and Optimization 9

Page 10: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

-8.00

-7.00

-6.00

-5.00

-4.00

-3.00

-2.00

-1.00

0.00

1.00

2.00

0 50 100 150 200 250 300 350

Velo

city

Diff

eren

ce (m

/s)

Jumper Mass (kg)

Root Finding and Optimization 10

Page 11: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ From plotting the difference between the desired velocity and the actual velocity, we can make a good estimate that the mass value is between 130 and 150 kg.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 11

Page 12: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ Since the sign of the difference in velocities goes through 0 (assuming a continuous function), the mass where the velocity difference is 0 should be between 130 and 150 kg.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 12

Page 13: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ We can make the lower estimate for the root (the value where the function where be equal to 0) as 130 kg and the upper estimate for the root as 150 kg.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 13

Page 14: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ Based on these estimates, the next estimate for the root will be the average of the upper and lower estimates (remember these are the root values not the function values).

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 14

Page 15: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ This would mean that the next estimate for the root would be 140 kg.

¢  If the tolerance for the function evaluation at the new estimate was good enough, we could quit.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 15

Page 16: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢  In this case the function evaluation at 140 kg is -0.06 so we will continue.

¢ We need to look at the original function evaluations and find the one whose sign our new function evaluation matches.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 16

Page 17: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢  f(130)=-0.28 ¢  f(150)=0.14 ¢  f(140)=-0.06 ¢  An easy way to find which

it matches if to multiply the function evaluation at each end by the function evaluation at the midpoint

¢  It will match the one that gives a positive value for the multiplication.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 17

Page 18: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢  f(130)*f(140)=0.016 ¢  f(150)*f(140)=-0.008 ¢  In this case, the sign of

the middle point evaluation is the same as the sign of the first point

¢  It will be easier to call then xlower, xmid, and xupper.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 18

Page 19: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ We will replace either the upper or lower estimate with the middle estimate.

¢ The one with the matching sign for the evaluation will be replaced.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 19

Page 20: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢  If the sign of f(xupper)*f(xmid) > 0 then l xupper=xmid

¢ Else l xlower=xmid

¢ End if

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 20

Page 21: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢  In our example, xmid (140) would replace xlower (130)

¢ Now we restart the process with the new limits. l xlower=140 l xupper=150 l xmid=(xlower+xupper)/2=145

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 21

Page 22: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ Our new estimate for the root would be 145 which evaluates to 0.05

¢  If this was within tolerance, we could stop.

¢  If not we check signs of the function evalutions

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 22

Page 23: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Location – Bisection Method

¢ Since the sign of f(xmid) and f(xupper) are the same we replace xupper with xmid and begin the process again until we reach a tolerance that is acceptable.

130   -­‐0.28  131   -­‐0.26  132   -­‐0.24  133   -­‐0.21  134   -­‐0.19  135   -­‐0.17  136   -­‐0.14  137   -­‐0.12  138   -­‐0.10  139   -­‐0.08  140   -­‐0.06  141   -­‐0.04  142   -­‐0.02  143   0.01  144   0.03  145   0.05  146   0.07  147   0.08  148   0.10  149   0.12  150   0.14  

Root Finding and Optimization 23

Page 24: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Finding and Optimization 24

Page 25: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Finding and Optimization 25

Page 26: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Finding and Optimization 26

Page 27: Civil Engineering Computation - Memphis Finding and Optimization.… · 138 0.10 139 0.08 140 0.06 141 0.04 142 0.02 143 0.01 144 0.03 145 0.05 146 0.07 147 0.08 148 0.10 149 0.12

Root Finding and Optimization 27