# 非线性等式和不等式约束

`[c,ceq] = nonlinconstr(x)`

### 非线性约束

`${x}_{1}^{2}+{x}_{2}=1$`

${x}_{1}{x}_{2}\ge -10$

`$\begin{array}{c}{x}_{1}^{2}+{x}_{2}-1=0\\ -{x}_{1}{x}_{2}-10\le 0.\end{array}$`

### 目标函数

`$\underset{x}{\mathrm{min}}f\left(x\right)={e}^{{x}_{1}}\left(4{x}_{1}^{2}+2{x}_{2}^{2}+4{x}_{1}{x}_{2}+2{x}_{2}+1\right)$`

### 求解问题

`x0 = [-1,-1];`

```A = []; b = []; Aeq = []; beq = []; lb = []; ub = [];```

`[x,fval] = fmincon(@objfun,x0,A,b,Aeq,beq,lb,ub,@confuneq)`
```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. ```
```x = 1×2 -0.7529 0.4332 ```
```fval = 1.5093 ```

`[c,ceq] = confuneq(x)`
```c = -9.6739 ```
```ceq = 2.0668e-12 ```

### 辅助函数

```function [c,ceq] = confuneq(x) % Nonlinear inequality constraints c = -x(1)*x(2) - 10; % Nonlinear equality constraints ceq = x(1)^2 + x(2) - 1; end```

```function f = objfun(x) f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1); end```