solvers
Determine default and valid solvers for problem
Description
returns the default solver for autosolver
= solvers(prob
)prob
.
[
also returns a list of the valid solvers for autosolver
,validsolvers
] = solvers(prob
)prob
.
Examples
Find Default and Valid Solvers
Create an optimization problem with Rosenbrock's function as the objective (see Solve a Constrained Nonlinear Problem, Problem-Based).
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);
Find the default and valid solvers for the problem.
[autosolver,validsolvers] = solvers(prob)
autosolver = "lsqnonlin"
validsolvers = 1x10 string
Columns 1 through 5
"lsqnonlin" "lsqcurvefit" "fmincon" "ga" "patternsearch"
Columns 6 through 9
"surrogateopt" "particleswarm" "simulannealbnd" "gamultiobj"
Column 10
"paretosearch"
Solve the problem using the default solver.
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
Solve the problem using fmincon
instead of the default 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
Input Arguments
prob
— Optimization problem or equation problem
OptimizationProblem
object | EquationProblem
object
Optimization problem or equation problem, specified as an OptimizationProblem
object or an EquationProblem
object. Create an optimization problem by using optimproblem
; create an equation problem by using eqnproblem
.
Warning
The problem-based approach does not support complex values in an objective function, nonlinear equalities, or nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result might be incorrect.
Example: prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 =
cons1;
Example: prob = eqnproblem; prob.Equations = eqs;
Output Arguments
autosolver
— Default solver for prob
string
Default solver for prob
, returned as a string. The default
solver is used by solve
or
prob2struct
when you call these functions without passing the Solver
name-value
argument.
validsolvers
— Valid solvers for prob
string vector
Valid solvers for prob
, returned as a string vector. You can
use any of the valid solvers for prob
when you specify the
Solver
name-value argument in the call to solve
or
prob2struct
.
The list of valid solvers depends on your toolbox licenses. For example, if you have
a Global Optimization Toolbox license, the list of valid solvers includes ga
, the
genetic algorithm solver.
Version History
Introduced in R2022b
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 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)