MATLAB Function: Many evaluations. There are cases where the golden-section search algorithm may be a

7.3 MULTIDIMENSIONAL OPTIMIZATION 195 A simple expression of its syntax is [xmin, fval] = fminbndfunction,x1,x2 where x and fval are the location and value of the minimum, function is the name of the function being evaluated, and x1 and x2 are the bounds of the interval being searched. Here is a simple MATLAB session that uses fminbnd to solve the problem from Example 7.1. g=9.81;v0=55;m=80;c=15;z0=100; z=t -z0+mcv0+mgc1-exp-cmt-mgct; [x,f]=fminbndz,0,8 x = 3.8317 f = -192.8609 As with fzero , optional parameters can be specified using optimset . For example, we can display calculation details: options = optimsetdisplay,iter; fminbndz,0,8,options Func-count x fx Procedure 1 3.05573 -189.759 initial 2 4.94427 -187.19 golden 3 1.88854 -171.871 golden 4 3.87544 -192.851 parabolic 5 3.85836 -192.857 parabolic 6 3.83332 -192.861 parabolic 7 3.83162 -192.861 parabolic 8 3.83166 -192.861 parabolic 9 3.83169 -192.861 parabolic Optimization terminated: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-004 ans = 3.8317 Thus, after three iterations, the method switches from golden to parabolic, and after eight iterations, the minimum is determined to a tolerance of 0.0001.

7.3 MULTIDIMENSIONAL OPTIMIZATION

Aside from one-dimensional functions, optimization also deals with multidimensional functions. Recall from Fig. 7.3a that our visual image of a one-dimensional search was like a roller coaster. For two-dimensional cases, the image becomes that of mountains and valleys Fig. 7.3b. As in the following example, MATLAB’s graphic capabilities provide a handy means to visualize such functions. x 2 x 1 3 2 1 0 –2 –1 3 ⫹ ⫹ ⫹ ⫹ ⫹ ⫹ 3 ⫹ 4 1 2 ⫹ 3 ⫹ 2 ⫹ 4 ⫹6 ⫹ 7 8 ⫹ 5 7 6 a Contour plot b Mesh plot 2.5 2 1.5 x 2 x 1 f x 1 , x 2 1 0.5 –2 –1.5 –1 –0.5 8 6 4 2 FIGURE 7.9 a Contour and b mesh plots of a two-dimensional function. EXAMPLE 7.4 Visualizing a Two-Dimensional Function Problem Statement. Use MATLAB’s graphical capabilities to display the following function and visually estimate its minimum in the range –2 ≤ x 1 ≤ 0 and 0 ≤ x 2 ≤ 3: f x 1 , x 2 = 2 + x 1 − x 2 + 2x 2 1 + 2x 1 x 2 + x 2 2 Solution. The following script generates contour and mesh plots of the function: x=linspace-2,0,40;y=linspace0,3,40; [X,Y] = meshgridx,y; Z=2+X-Y+2X.2+2X.Y+Y.2; subplot1,2,1; cs=contourX,Y,Z;clabelcs; xlabelx_1;ylabelx_2; titlea Contour plot;grid; subplot1,2,2; cs=surfcX,Y,Z; zmin=floorminZ; zmax=ceilmaxZ; xlabelx_1;ylabelx_2;zlabelfx_1,x_2; titleb Mesh plot; As displayed in Fig. 7.9, both plots indicate that function has a minimum value of about f x 1 , x 2 = 0 to 1 located at about x 1 = − 1 and x 2 = 1.5.