Page 318 - MATLAB an introduction with applications
P. 318

Optimization ———  303

                                                                      2
                                                          2  2
                   Example E5.21: Minimize f (x , x ) = 90 (x  –x )  + (1 – x )  using the starting point
                                                          1
                                            1
                                                       2
                                                                    1
                                               2
                                     x  = –1.1, x  = 1.0
                               1
                                       2
                   Solution:
                   The minimum = 0 at x = 1, y = 1
                   EDU>> Run_EN_5_21
                   x =
                          1.0000      1.0000
                   fval =
                          7.2476e–010
                   Run_EN_5_21
                   y=@(x)90*(x(2)–x(1)^2)^2+(1–x(1))^2;
                   x,fval]=fminsearch(y,[–1.1,1.0])

                                                          2
                                                                   –1
                   Example E5.22: Minimize f = 0.60 – 0.70/(1. + x ) – 0.5*tan (1/x)
                   Solution:
                   The minimum value of the function is f =  – 0.8286 at x =  0.1001

                   EDU>> Run_EN_5_22
                   f =
                       @(x)0.60–0.70/(1. + x.^2)–0.5*atan(1/x)
                   x =
                        0.1001
                   f =z
                      –0.8286
                   Run_EN_5_22
                   f = @(x)0.60 – 0.70/(1. + x.^2)– 0.5*atan(1/x)
                   x = fminbnd(f, .1,1.0)
                   f = 0.60 – 0.70/(1. + x.^2) – 0.5*atan(1/x)

                   Example E5.23: Use the MATLAB fminbnd function to find the maximum of
                                                  2
                                           y = (3*(sin(x)) – (x /12)
                   Solution:
                   The graph of this function is given below. By inspection, the maximum value of the function is close to 2.8
                   and occurs at approximately x = 1.5.
   313   314   315   316   317   318   319   320   321   322   323