主要内容

优化Using the GPS Algorithm

This example shows how to solve an optimization problem using the GPS algorithm, which is the default for thepatternsearchsolver. The example uses the Optimize Live Editor task to complete the optimization using a visual approach.

目标函数

This example uses the objective functionps_example., which is included withGlobal Optimization Toolboxsoftware. View the code for the function by entering the following command.

typeps_example.

该图显示了该功能的曲线图。

2-D plot of a nonsmooth function

Code for creating the figure

找到函数的最小值

To find the minimum ofps_example.using the优化Live Editor task, complete the following steps.

  1. Create a new live script by clicking theNew Live Scriptbutton in the文件section on theHometab.

    New Live Script button

  2. Insert an Optimize Live Editor task. Click the Insert tab and then, in the Code section, select Task > Optimize.

    插入优化按钮

    优化task in Live Editor: Choose between problem-based (recommended) and solver-based

  3. Click theSolver-based任务。

    优化Live Editor task

  4. 有关输入问题数据,请通过单击插入新部分Section Breakbutton on theInserttab. New sections appear above and below the task.

  5. 在里面new section above the task, enter the following code to define the initial point and objective function.

    x0 = [2.1 1.7];有趣= @ps_example;
  6. 要将这些变量放入工作区,请按按键运行该部分Ctrl + Enter..

  7. 在里面指定问题类型section of the task, click theObjective > Nonsmoothbutton.

  8. Ensure that the selected solver ispatternsearch.

  9. 在里面Select problem datasection of the task, selectObjective function > Function handle和then choosefun.

  10. Select初始点(x0)> x0.

  11. 在任务的显示进度部分中,选择最佳值和网格大小图。

    Solver, objective function, initial point, and plots specified

  12. To run the solver, click the options buttonat the top right of the task window, and selectRun Section. The plots appear in a separate figure window and in the task output area.

    Function values decrease to -2, and the mesh size oscillates but converges to 9.53e-7.

The upper plot shows the objective function value of the best point at each iteration. Typically, the objective function values improve rapidly at the early iterations and then level off as they approach the optimal value.

The lower plot shows the mesh size at each iteration. The mesh size increases after each successful iteration and decreases after each unsuccessful iteration. For details, seeHow Pattern Search Polling Works.

优化了因为e the mesh size became smaller than the mesh size tolerance value, defined by theMeshTolerance选项。最小函数值约为-2。

To see the solution and objective function value, look at the top of the task.

优化returns solution and objectiveValue variables to the workspace

The优化task puts the variablessolutionobjectiveValuein the workspace. View these values by placing a new section below the task, and include this code.

disp(solution) disp(objectiveValue)

Run the section by pressingCtrl+Enter.

disp(solution)
-4.7124 -0.0000
disp(objectiveValue)
-2.0000

See Also

|

相关话题