showproblem
(不推荐)显示优化问题
说明
示例
显示优化问题
创建一个优化问题,包括目标函数和约束,并显示问题。
创建 混合整数线性规划基础:基于问题 中的问题。
steelprob = optimproblem; ingots = optimvar('ingots',4,1,'Type','integer','LowerBound',0,'UpperBound',1); alloys = optimvar('alloys',4,1,'LowerBound',0); weightIngots = [5,3,4,6]; costIngots = weightIngots.*[350,330,310,280]; costAlloys = [500,450,400,100]; cost = costIngots*ingots + costAlloys*alloys; steelprob.Objective = cost; totalweight = weightIngots*ingots + sum(alloys); carbonIngots = [5,4,5,3]/100; carbonAlloys = [8,7,6,3]/100; totalCarbon = (weightIngots.*carbonIngots)*ingots + carbonAlloys*alloys; molybIngots = [3,3,4,4,]/100; molybAlloys = [6,7,8,9]/100; totalMolyb = (weightIngots.*molybIngots)*ingots + molybAlloys*alloys; steelprob.Constraints.conswt = totalweight == 25; steelprob.Constraints.conscarb = totalCarbon == 1.25; steelprob.Constraints.consmolyb = totalMolyb == 1.25;
显示该问题。
showproblem(steelprob)
OptimizationProblem : Solve for: alloys, ingots where: ingots integer minimize : 1750*ingots(1) + 990*ingots(2) + 1240*ingots(3) + 1680*ingots(4) + 500*alloys(1) + 450*alloys(2) + 400*alloys(3) + 100*alloys(4) subject to conswt: 5*ingots(1) + 3*ingots(2) + 4*ingots(3) + 6*ingots(4) + alloys(1) + alloys(2) + alloys(3) + alloys(4) == 25 subject to conscarb: 0.25*ingots(1) + 0.12*ingots(2) + 0.2*ingots(3) + 0.18*ingots(4) + 0.08*alloys(1) + 0.07*alloys(2) + 0.06*alloys(3) + 0.03*alloys(4) == 1.25 subject to consmolyb: 0.15*ingots(1) + 0.09*ingots(2) + 0.16*ingots(3) + 0.24*ingots(4) + 0.06*alloys(1) + 0.07*alloys(2) + 0.08*alloys(3) + 0.09*alloys(4) == 1.25 variable bounds: 0 <= alloys(1) 0 <= alloys(2) 0 <= alloys(3) 0 <= alloys(4) 0 <= ingots(1) <= 1 0 <= ingots(2) <= 1 0 <= ingots(3) <= 1 0 <= ingots(4) <= 1
输入参数
prob
— 优化问题或方程问题
OptimizationProblem
对象 | EquationProblem
对象
优化问题或方程问题,指定为 OptimizationProblem
对象或 EquationProblem
对象。使用 optimproblem
创建优化问题;使用 eqnproblem
创建方程问题。
警告
基于问题的方法不支持目标函数、非线性等式或非线性不等式中使用复数值。如果某函数计算具有复数值,即使是作为中间值,最终结果也可能不正确。
示例: prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 = cons1;
示例: prob = eqnproblem; prob.Equations = eqs;
提示
showproblem
等效于调用以下所有各项:showexpr
(prob.Objective
)对
prob.Constraints
中的每个约束调用showconstr
对
prob
中的所有变量调用showbounds
对于有许多边界或约束的问题,使用
writeproblem
生成包含目标、约束和边界信息的文本文件。
版本历史记录
在 R2017b 中推出MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)