solvers
说明
返回 autosolver
= solvers(prob
)prob
的默认求解器,其中 prob
是 OptimizationProblem
对象或 EquationProblem
对象。要求解 prob
,请调用 solve
,后者将调用默认求解器。
[
还返回 autosolver
,validsolvers
] = solvers(prob
)prob
的有效求解器列表。
示例
查找默认和有效求解器
以罗森布罗克函数为目标创建一个优化问题(请参阅基于问题求解有约束非线性问题:)。
x = optimvar("x",LowerBound=-3,UpperBound=3); y = optimvar("y",LowerBound = 0,UpperBound=9); obj = 100*(y - x^2)^2 + (1 - x)^2; prob = optimproblem(Objective=obj);
查找问题的默认和有效求解器。
[autosolver,validsolvers] = solvers(prob)
autosolver = "lsqnonlin"
validsolvers = 1x10 string
"lsqnonlin" "lsqcurvefit" "fmincon" "ga" "patternsearch" "surrogateopt" "particleswarm" "simulannealbnd" "gamultiobj" "paretosearch"
使用默认求解器求解该问题。
x0.x = -2.1; x0.y = 2.2; [sol,fval] = solve(prob,x0)
Solving problem using lsqnonlin. Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
sol = struct with fields:
x: 1.0000
y: 1.0000
fval = 4.9503e-16
使用 fmincon
(而不是默认的 lsqnonlin
)求解问题。
[sol,fval] = solve(prob,x0,Solver="fmincon")
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.
sol = struct with fields:
x: 1.0000
y: 1.0000
fval = 1.9355e-13
输入参数
prob
— 优化问题或方程问题
OptimizationProblem
对象 | EquationProblem
对象
优化问题或方程问题,指定为 OptimizationProblem
对象或 EquationProblem
对象。使用 optimproblem
创建优化问题;使用 eqnproblem
创建方程问题。
警告
基于问题的方法不支持在目标函数、非线性等式和非线性不等式中使用复数值。如果某函数计算具有复数值,即使是作为中间值,最终结果也可能不正确。
示例: prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 = cons1;
示例: prob = eqnproblem; prob.Equations = eqs;
输出参量
autosolver
— prob
的默认求解器
字符串
prob
的默认求解器,以字符串形式返回。当您调用这些函数而不传递 Solver
名称-值参量时,solve
或 prob2struct
将使用默认求解器。
validsolvers
— prob
的有效求解器
字符串向量
prob
的有效求解器,以字符串向量形式返回。当您在对 solve
或 prob2struct
的调用中指定 Solver
名称-值参量时,您可以对 prob
使用任何有效的求解器。
有效求解器的列表取决于您的工具箱许可证。例如,如果您有 Global Optimization Toolbox 许可证,则有效求解器列表中包括遗传算法求解器 ga
。
版本历史记录
在 R2022b 中推出
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)