Set Options

Set Options Using optimoptions

You can specify any available patternsearch options by passing options as an input argument to patternsearch using the syntax

[x,fval] = patternsearch(@fitnessfun,nvars, ... 

Pass in empty brackets [] for any constraints that do not appear in the problem.

You create options using the function optimoptions.

options = optimoptions(@patternsearch)
options = 

  patternsearch options:

   Set properties:
     No options set.

   Default properties:
            AccelerateMesh: 0
       ConstraintTolerance: 1.0000e-06
                   Display: 'final'
         FunctionTolerance: 1.0000e-06
           InitialMeshSize: 1
    MaxFunctionEvaluations: '2000*numberOfVariables'
             MaxIterations: '100*numberOfVariables'
                   MaxTime: Inf
     MeshContractionFactor: 0.5000
       MeshExpansionFactor: 2
             MeshTolerance: 1.0000e-06
                 OutputFcn: []
                   PlotFcn: []
                PollMethod: 'GPSPositiveBasis2N'
        PollOrderAlgorithm: 'consecutive'
                 ScaleMesh: 1
                 SearchFcn: []
             StepTolerance: 1.0000e-06
           UseCompletePoll: 0
         UseCompleteSearch: 0
               UseParallel: 0
             UseVectorized: 0

The patternsearch function uses these default values if you do not pass in options as an input argument.

The value of each option is stored in a field of options, such as options.MeshExpansionFactor. You can display any of these values by entering options followed by the name of the field. For example, to display the mesh expansion factor for the pattern search, enter

ans =

To create options with a field value that is different from the default, use optimoptions. For example, to change the mesh expansion factor to 3 instead of its default value 2, enter

options = optimoptions('patternsearch','MeshExpansionFactor',3);

This creates options with all values set to defaults except for MeshExpansionFactor, which is set to 3.

If you now call patternsearch with the argument options, the pattern search uses a mesh expansion factor of 3.

If you subsequently decide to change another field in options, such as setting PlotFcn to @psplotmeshsize, which plots the mesh size at each iteration, call optimoptions with the syntax

options = optimoptions(options,'PlotFcn',@psplotmeshsize)

This preserves the current values of all fields of options except for PlotFcn, which is changed to @plotmeshsize. Note that if you omit the options input argument, optimoptions resets MeshExpansionFactor to its default value, which is 2.

You can also set both MeshExpansionFactor and PlotFcn with the single command

options = optimoptions('patternsearch','MeshExpansionFactor',3,'PlotFcn',@psplotmeshsize)

Create Options and Problems Using the Optimization App

As an alternative to creating options using optimoptions, you can set the values of options in the Optimization app and then export the options to the MATLAB® workspace, as described in Importing and Exporting Your Work (Optimization Toolbox). If you export the default options in the Optimization app, the resulting options has the same settings as the default options returned by the command

options = optimoptions('patternsearch')

except for the default value of 'Display', which is 'final' when created by optimoptions, but 'none' when created in the Optimization app.

You can also export an entire problem from the Optimization app and run it from the command line. Enter

where problem is the name of the exported problem.

See Also


Related Topics