本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

optimoptions

创建优化选项

说明

示例

options = optimoptions(SolverName) 返回 SolverName 求解器的一组默认选项。

示例

options = optimoptions(SolverName,Name,Value) 返回使用指定值更改了指定参数的选项。

示例

options = optimoptions(oldoptions,Name,Value) 返回 oldoptions 的副本,并使用指定值更改了指定参数。

示例

options = optimoptions(SolverName,oldoptions) 返回 SolverName 求解器的默认选项,并将 oldoptions 中的适用选项复制到 options 中。

示例

options = optimoptions(prob) 针对 prob 优化问题或方程问题返回一组默认选项。

options = optimoptions(prob,Name,Value) 返回使用指定值更改了指定参数的选项。

示例

全部折叠

fmincon 求解器创建默认选项。

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')

fmincon 求解器创建非默认选项。

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')

用新值更新现有选项。

lsqnonlin 求解器创建选项。

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')

MaxFunctionEvaluations 增加到 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')

使用圆点表示法用新值更新现有选项。

lsqnonlin 求解器创建选项。

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')

使用圆点表示法将 MaxFunctionEvaluations 增加到 2000。

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')

fmincon 求解器的非默认选项转移到 fminunc 求解器的选项。

fmincon 求解器创建非默认选项。

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')

将适用选项迁移到 fminunc 求解器。

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)'
                 UseParallel: 0

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

创建优化问题并找到默认的求解器和选项。

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: 'active-set', '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')

默认求解器是 quadprog

设置选项以使用迭代输出。查找解。

options.Display = 'iter';
sol = solve(prob,'Options',options);
Solving problem using quadprog.
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 value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
sol.x
ans = 3×1

    1.6035
    0.0000
    0.8029

输入参数

全部折叠

求解器名称,指定为字符向量、字符串或函数句柄。

示例: 'fmincon'

示例: @fmincon

数据类型: char | function_handle | string

选项,指定为选项对象。optimoptions 函数创建选项对象。

示例: oldoptions = optimoptions(@fminunc)

问题对象,指定为 OptimizationProblem 对象或 EquationProblem 对象。使用Problem-Based Optimization WorkflowProblem-Based Workflow for Solving Equations创建 prob

通过指定 prob,您可以查看适用于您的问题的默认求解器,还可以修改算法或其他选项。

示例: prob = optimproblem('Objective',myobj),其中 myobj 是优化表达式

名称-值对组参数

指定可选的、以逗号分隔的 Name,Value 对组参数。Name 为参数名称,Value 为对应的值。Name 必须放在引号中。您可采用任意顺序指定多个名称-值对组参数,如 Name1,Value1,...,NameN,ValueN 所示。

示例: optimoptions(@fmincon,'Display','iter','FunctionTolerance',1e-10)fmincon 选项设置为启用迭代输出,并具有 1e-10FunctionTolerance

如需了解相关的名称-值对组,请参考您的求解器的选项表:

  • fgoalattain options

  • fmincon options

  • fminimax options

  • fminunc options

  • fseminf options

  • fsolve options

  • ga options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • gamultiobj options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • intlinprog options

  • linprog options

  • lsqcurvefit options

  • lsqlin options

  • lsqnonlin options

  • paretosearch options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • particleswarm options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • patternsearch options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • quadprog options

  • simulannealbnd options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

  • surrogateopt options (Global Optimization Toolbox)(在 Global Optimization Toolbox 中)

输出参数

全部折叠

选项对象,以 SolverName 求解器的选项形式返回。

替代功能

App

您可以使用 Optimization 工具 (optimtool) 设置和修改选项。请参阅导入和导出您的工作

注意

Optimization 工具会显示警告,说明它将在以后的版本中被删除。

在 R2013a 中推出