Introductory Programming Fall 2006 Optimization ------------ Optimization is the general name for finding the maximum (or minimum) point in a design space. For example, imagine that you have a function called "baseball" that takes two input variables, launch velocity and launch angle, and that computes the flight distance of a baseball hit with the given velocity and angle. Now imagine that you would like to compute the optimal angle for a given velocity (the angle that maximizes the flight distance). How would you do it? Option 1: Choose two values that you are pretty sure bracket the root. (in this case, 0 and 90 degrees would do it!) Use linspace to enumerate a number of values in this range. (help linspace for details) Evaluate the function for each value in the range. Choose the value of x that maximizes f(x) in this case the angle that maximizes baseball(velocity, angle) Maximum error is the space between values in the range. Option 2: Same as option 1, but after the first iteration, run it again with the newly discovered two values that bracket the root. Option 3: Golden section search (see the handout from Numerical Recipes in C) Option 4: Brent's method (use a parabolic interpolation) ----- If you can evaluate the derivative of the function as well as the function itself, then there are two more option! Option 5: Use a root-finding algorithm (like fzero) on the derivative. (and check whether you found a minimum or a maximum!) Option 6: Amend Options 3 or 4 by using the derivative to decide which subinterval to search in.