show
显示有关优化对象的信息
说明
使用 show
显示有关优化对象的信息。
提示
有关完整的工作流,请参阅基于问题的优化工作流或基于问题的方程求解工作流。
示例
检查问题构造的各个阶段,以优化限制在单位圆盘上的罗森布罗克函数(请参阅基于问题求解有约束非线性问题:)。
创建一个二维优化变量 x
。显示该变量。
x = optimvar('x',2);
show(x)
[ x(1) ] [ x(2) ]
为目标函数创建一个表达式。显示该表达式。
obj = log(1 + 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2); show(obj)
log(((1 + (100 .* (x(2) - x(1).^2).^2)) + (1 - x(1)).^2))
为约束创建一个表达式。显示该约束。
cons = x(1)^2 + x(2)^2 <= 1; show(cons)
(x(1).^2 + x(2).^2) <= 1
创建一个以 obj
为目标函数、以 cons
为约束的优化问题。显示该问题。
prob = optimproblem("Objective",obj,"Constraints",cons); show(prob)
OptimizationProblem : Solve for: x minimize : log(((1 + (100 .* (x(2) - x(1).^2).^2)) + (1 - x(1)).^2)) subject to : (x(1).^2 + x(2).^2) <= 1
最后,创建一个初始点 [0 0]
,并从该初始点开始求解问题。
x0.x = [0 0]; [sol,fval,exitflag] = solve(prob,x0)
Solving problem using fmincon. Local 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. <stopping criteria details>
sol = struct with fields:
x: [2×1 double]
fval = 0.0447
exitflag = OptimalSolution
检查解点。
sol.x
ans = 2×1
0.7864
0.6177
输入参数
优化对象,指定为以下对象之一:
OptimizationProblem
对象 -show(obj)
显示解的变量、目标函数、约束和变量边界。EquationProblem
对象 -show(obj)
显示解的变量、解的方程和变量边界。OptimizationExpression
对象 -show(obj)
显示优化表达式。OptimizationVariable
对象 -show(obj)
显示优化变量。此显示不指示变量类型或边界;它只显示变量维度和索引名称(如果有)。OptimizationConstraint
对象 -show(obj)
显示约束表达式。OptimizationEquality
对象 -show(obj)
显示等式表达式。OptimizationInequality
对象 -show(obj)
显示不等式表达式。
版本历史记录
在 R2019b 中推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)