# EquationProblem

## 创建对象

```prob = eqnproblem; x = optimvar('x'); eqn = x^5 - x^4 + 3*x == 1/2; prob.Equations.eqn = eqn;```

## 对象函数

 `optimoptions` 创建优化选项 `prob2struct` 将优化问题或方程问题转换为求解器形式 `show` 显示有关优化对象的信息 `solve` 求解优化问题或方程问题 `solvers` Determine default and valid solvers for optimization problem or equation problem `varindex` 将问题变量映射到基于求解器的变量索引 `write` 保存优化对象描述

## 示例

`$\begin{array}{l}\mathrm{exp}\left(-\mathrm{exp}\left(-\left({x}_{1}+{x}_{2}\right)\right)\right)={x}_{2}\left(1+{x}_{1}^{2}\right)\\ {x}_{1}\mathrm{cos}\left({x}_{2}\right)+{x}_{2}\mathrm{sin}\left({x}_{1}\right)=\frac{1}{2}\end{array}$`

`x = optimvar('x',2);`

`eq1 = exp(-exp(-(x(1) + x(2)))) == x(2)*(1 + x(1)^2);`

`eq2 = x(1)*cos(x(2)) + x(2)*sin(x(1)) == 1/2;`

```prob = eqnproblem; prob.Equations.eq1 = eq1; prob.Equations.eq2 = eq2;```

`show(prob)`
``` EquationProblem : Solve for: x eq1: exp((-exp((-(x(1) + x(2)))))) == (x(2) .* (1 + x(1).^2)) eq2: ((x(1) .* cos(x(2))) + (x(2) .* sin(x(1)))) == 0.5 ```

`[0,0]` 点开始求解问题。对于基于问题的方法，将初始点指定为结构体，并将变量名称作为结构体的字段。对于此问题，只有一个变量，即 `x`

```x0.x = [0 0]; [sol,fval,exitflag] = solve(prob,x0)```
```Solving problem using fsolve. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. ```
```sol = struct with fields: x: [2x1 double] ```
```fval = struct with fields: eq1: -2.4070e-07 eq2: -3.8255e-08 ```
```exitflag = EquationSolved ```

`disp(sol.x)`
``` 0.3532 0.6061 ```

```ls1 = fcn2optimexpr(@(x)exp(-exp(-(x(1)+x(2)))),x); eq1 = ls1 == x(2)*(1 + x(1)^2); ls2 = fcn2optimexpr(@(x)x(1)*cos(x(2))+x(2)*sin(x(1)),x); eq2 = ls2 == 1/2;```