Develop an M-file that is expressly designed to locate a maximum with the golden-section search. In other words, set it up so that it directly finds the maximum rather than finding the minimum of −f(x). The function should have the following features:
• Iterate until the relative error falls below a stopping criterion or exceeds a maximum number of iterations.
• Return both the optimal x and f(x).
Test your program with the same problem as Example 7.1.
Example 7.1:
Determining the Optimum Analytically by Root Location
Problem Statement. Determine the time and magnitude of the peak elevation based on Eq. (7.1). Use the following parameter values for your calculation: g = 9.81 m/s2, z0 = 100 m, υ0 = 55 m/s, m = 80 kg, and c = 15 kg/s.
Solution. Equation (7.1) can be differentiated to give
(E7.1.1)
Note that because υ = dz/dt, this is actually the equation for the velocity. The maximum elevation occurs at the value of t that drives this equation to zero. Thus, the problem amounts to determining the root. For this case, this can be accomplished by setting the derivative to zero and solving Eq. (E7.1.1) analytically for
Substituting the parameters gives
This value along with the parameters can then be substituted into Eq. (7.1) to compute the maximum elevation as
We can verify that the result is a maximum by differentiating Eq. (E7.1.1) to obtain the second derivative
The fact that the second derivative is negative tells us that we have a maximum. Further, the result makes physical sense since the acceleration should be solely equal to the force of gravity at the maximum when the vertical velocity (and hence drag) is zero.
Although an analytical solution was possible for this case, we could have obtained the same result using the root-location methods described in Chaps. 5 and 6. This will be left as a homework exercise.
Equation (7.1):
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.