This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

optimoptions

Create optimization options

Syntax

options = optimoptions(SolverName)
options = optimoptions(SolverName,Name,Value)
options = optimoptions(oldoptions,Name,Value)
options = optimoptions(SolverName,oldoptions)
options = optimoptions(prob)
options = optimoptions(prob,Name,Value)

Description

example

options = optimoptions(SolverName) returns a set of default options for the SolverName solver.

example

options = optimoptions(SolverName,Name,Value) returns options with the named parameters altered with the specified values.

example

options = optimoptions(oldoptions,Name,Value) returns a copy of oldoptions with the named parameters altered with the specified values.

example

options = optimoptions(SolverName,oldoptions) returns default options for the SolverName solver, and copies the applicable options in oldoptions to options.

example

options = optimoptions(prob) returns a set of default options for the prob optimization problem.

options = optimoptions(prob,Name,Value) returns options with the named parameters altered with the specified values.

Examples

collapse all

Create default options for the fmincon solver.

options = optimoptions('fmincon')
options = 
  fmincon options:

   Options used by current Algorithm ('interior-point'):
   (Other available algorithms: 'active-set', 'sqp', 'sqp-legacy', 'trust-region-reflective')

   Set properties:
     No options set.

   Default properties:
                    Algorithm: 'interior-point'
               CheckGradients: 0
          ConstraintTolerance: 1.0000e-06
                      Display: 'final'
     FiniteDifferenceStepSize: 'sqrt(eps)'
         FiniteDifferenceType: 'forward'
         HessianApproximation: 'bfgs'
                   HessianFcn: []
           HessianMultiplyFcn: []
                  HonorBounds: 1
       MaxFunctionEvaluations: 3000
                MaxIterations: 1000
               ObjectiveLimit: -1.0000e+20
          OptimalityTolerance: 1.0000e-06
                    OutputFcn: []
                      PlotFcn: []
                 ScaleProblem: 0
    SpecifyConstraintGradient: 0
     SpecifyObjectiveGradient: 0
                StepTolerance: 1.0000e-10
          SubproblemAlgorithm: 'factorization'
                     TypicalX: 'ones(numberOfVariables,1)'
                  UseParallel: 0

   Show options not used by current Algorithm ('interior-point')

Create nondefault options for the fmincon solver.

options = optimoptions(@fmincon,'Algorithm','sqp','MaxIterations',1500)
options = 
  fmincon options:

   Options used by current Algorithm ('sqp'):
   (Other available algorithms: 'active-set', 'interior-point', 'sqp-legacy', 'trust-region-reflective')

   Set properties:
                    Algorithm: 'sqp'
                MaxIterations: 1500

   Default properties:
               CheckGradients: 0
          ConstraintTolerance: 1.0000e-06
                      Display: 'final'
     FiniteDifferenceStepSize: 'sqrt(eps)'
         FiniteDifferenceType: 'forward'
       MaxFunctionEvaluations: '100*numberOfVariables'
               ObjectiveLimit: -1.0000e+20
          OptimalityTolerance: 1.0000e-06
                    OutputFcn: []
                      PlotFcn: []
                 ScaleProblem: 0
    SpecifyConstraintGradient: 0
     SpecifyObjectiveGradient: 0
                StepTolerance: 1.0000e-06
                     TypicalX: 'ones(numberOfVariables,1)'
                  UseParallel: 0

   Show options not used by current Algorithm ('sqp')

Update existing options with new values.

Create options for the lsqnonlin solver.

oldoptions = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt',...
    'MaxFunctionEvaluations',1500)
oldoptions = 
  lsqnonlin options:

   Options used by current Algorithm ('levenberg-marquardt'):
   (Other available algorithms: 'trust-region-reflective')

   Set properties:
                   Algorithm: 'levenberg-marquardt'
      MaxFunctionEvaluations: 1500

   Default properties:
              CheckGradients: 0
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
        FiniteDifferenceType: 'forward'
           FunctionTolerance: 1.0000e-06
               MaxIterations: 400
                   OutputFcn: []
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06
                    TypicalX: 'ones(numberOfVariables,1)'
                 UseParallel: 0

   Show options not used by current Algorithm ('levenberg-marquardt')

Increase MaxFunctionEvaluations to 2000.

options = optimoptions(oldoptions,'MaxFunctionEvaluations',2000)
options = 
  lsqnonlin options:

   Options used by current Algorithm ('levenberg-marquardt'):
   (Other available algorithms: 'trust-region-reflective')

   Set properties:
                   Algorithm: 'levenberg-marquardt'
      MaxFunctionEvaluations: 2000

   Default properties:
              CheckGradients: 0
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
        FiniteDifferenceType: 'forward'
           FunctionTolerance: 1.0000e-06
               MaxIterations: 400
                   OutputFcn: []
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06
                    TypicalX: 'ones(numberOfVariables,1)'
                 UseParallel: 0

   Show options not used by current Algorithm ('levenberg-marquardt')

Update existing options with new values by using dot notation.

Create options for the lsqnonlin solver.

options = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt',...
    'MaxFunctionEvaluations',1500)
options = 
  lsqnonlin options:

   Options used by current Algorithm ('levenberg-marquardt'):
   (Other available algorithms: 'trust-region-reflective')

   Set properties:
                   Algorithm: 'levenberg-marquardt'
      MaxFunctionEvaluations: 1500

   Default properties:
              CheckGradients: 0
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
        FiniteDifferenceType: 'forward'
           FunctionTolerance: 1.0000e-06
               MaxIterations: 400
                   OutputFcn: []
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06
                    TypicalX: 'ones(numberOfVariables,1)'
                 UseParallel: 0

   Show options not used by current Algorithm ('levenberg-marquardt')

Increase MaxFunctionEvaluations to 2000 by using dot notation.

options.MaxFunctionEvaluations = 2000
options = 
  lsqnonlin options:

   Options used by current Algorithm ('levenberg-marquardt'):
   (Other available algorithms: 'trust-region-reflective')

   Set properties:
                   Algorithm: 'levenberg-marquardt'
      MaxFunctionEvaluations: 2000

   Default properties:
              CheckGradients: 0
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
        FiniteDifferenceType: 'forward'
           FunctionTolerance: 1.0000e-06
               MaxIterations: 400
                   OutputFcn: []
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06
                    TypicalX: 'ones(numberOfVariables,1)'
                 UseParallel: 0

   Show options not used by current Algorithm ('levenberg-marquardt')

Transfer nondefault options for the fmincon solver to options for the fminunc solver.

Create nondefault options for the fmincon solver.

oldoptions = optimoptions(@fmincon,'Algorithm','sqp','MaxIterations',1500)
oldoptions = 
  fmincon options:

   Options used by current Algorithm ('sqp'):
   (Other available algorithms: 'active-set', 'interior-point', 'sqp-legacy', 'trust-region-reflective')

   Set properties:
                    Algorithm: 'sqp'
                MaxIterations: 1500

   Default properties:
               CheckGradients: 0
          ConstraintTolerance: 1.0000e-06
                      Display: 'final'
     FiniteDifferenceStepSize: 'sqrt(eps)'
         FiniteDifferenceType: 'forward'
       MaxFunctionEvaluations: '100*numberOfVariables'
               ObjectiveLimit: -1.0000e+20
          OptimalityTolerance: 1.0000e-06
                    OutputFcn: []
                      PlotFcn: []
                 ScaleProblem: 0
    SpecifyConstraintGradient: 0
     SpecifyObjectiveGradient: 0
                StepTolerance: 1.0000e-06
                     TypicalX: 'ones(numberOfVariables,1)'
                  UseParallel: 0

   Show options not used by current Algorithm ('sqp')

Transfer the applicable options to the fminunc solver.

options = optimoptions(@fminunc,oldoptions)
options = 
  fminunc options:

   Options used by current Algorithm ('quasi-newton'):
   (Other available algorithms: 'trust-region')

   Set properties:
              CheckGradients: 0
        FiniteDifferenceType: 'forward'
               MaxIterations: 1500
         OptimalityTolerance: 1.0000e-06
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06

   Default properties:
                   Algorithm: 'quasi-newton'
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
      MaxFunctionEvaluations: '100*numberOfVariables'
              ObjectiveLimit: -1.0000e+20
                   OutputFcn: []
                    TypicalX: 'ones(numberOfVariables,1)'

   Show options not used by current Algorithm ('quasi-newton')

Create an optimization problem and find the default solver and options.

rng default
x = optimvar('x',3,'LowerBound',0);
expr = x'*(eye(3) + randn(3))*x - randn(1,3)*x;
prob = optimproblem('Objective',expr);
options = optimoptions(prob)
options = 
  quadprog options:

   Options used by current Algorithm ('interior-point-convex'):
   (Other available algorithms: 'trust-region-reflective')

   Set properties:
     No options set.

   Default properties:
              Algorithm: 'interior-point-convex'
    ConstraintTolerance: 1.0000e-08
                Display: 'final'
           LinearSolver: 'auto'
          MaxIterations: 200
    OptimalityTolerance: 1.0000e-08
          StepTolerance: 1.0000e-12

   Show options not used by current Algorithm ('interior-point-convex')

The default solver is quadprog.

Set the options to use iterative display. Find the solution.

options.Display = 'iter';
sol = solve(prob,'Options',options);
Your Hessian is not symmetric. Resetting H=(H+H')/2.

 Iter            Fval  Primal Infeas    Dual Infeas  Complementarity  
    0    2.018911e+00   0.000000e+00   2.757660e+00     6.535839e-01  
    1   -2.170204e+00   0.000000e+00   8.881784e-16     2.586177e-01  
    2   -3.405808e+00   0.000000e+00   8.881784e-16     2.244054e-03  
    3   -3.438788e+00   0.000000e+00   3.356690e-16     7.261144e-09  

Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
sol.x
ans = 3×1

    1.6035
    0.0000
    0.8029

Input Arguments

collapse all

Solver name, specified as a character vector, string, or function handle.

Example: 'fmincon'

Example: @fmincon

Data Types: char | function_handle | string

Options, specified as an options object. The optimoptions function creates options objects.

Example: oldoptions = optimoptions(@fminunc)

Optimization problem, specified as an OptimizationProblem object. Create prob using the Problem-Based Workflow.

The syntaxes using prob enable you to see what the default solver is for your problem and to modify the algorithm or other options.

Example: prob = optimproblem('Objective',myobj), where myobjis an optimization expression

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: optimoptions(@fmincon,'Display','iter','FunctionTolerance',1e-10) sets fmincon options to have iterative display, and to have a FunctionTolerance of 1e-10.

For relevant name-value pairs, consult the options table for your solver:

Output Arguments

collapse all

Options object, returned as the options for the SolverName solver.

Alternative Functionality

App

You can set and modify options using the Optimization app (optimtool). See Importing and Exporting Your Work.

Note

The Optimization app warns that it will be removed in a future release.

Introduced in R2013a