Main Content

Set Options

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

[x,fval] = patternsearch(@fitnessfun,nvars, ... 
            A,b,Aeq,beq,lb,ub,nonlcon,options)

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

Create options using the optimoptions function.

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

options.MeshExpansionFactor
ans =
    2

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)

See Also

|

Related Topics