# solvers

## 语法

``autosolver = solvers(prob)``
``[autosolver,validsolvers] = solvers(prob)``

## 说明

``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 ```

`[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` 的默认求解器，以字符串形式返回。当您调用这些函数而不传递 `Solver` 名称-值参量时，`solve``prob2struct` 将使用默认求解器。

`prob` 的有效求解器，以字符串向量形式返回。当您在对 `solve``prob2struct` 的调用中指定 `Solver` 名称-值参量时，您可以对 `prob` 使用任何有效的求解器。