Constrained Optimization

Let $x\in\mathbf{R}^n$, $f(x)$, $g_1(x),\ldots, g_{\text{ne}}(x)$, and $h_1(x),\ldots, h_\text{ni}(x)$ are differentiable functions, this application solves the constrained optimization problems: \[ \begin{aligned} \min_{x} \quad & f(x)\\ \textrm{s.t.} \quad & \boldsymbol{g}(x) = 0\\ & \boldsymbol{h}(x) \geqslant 0 \\ & l\leqslant x \leqslant u \end{aligned} \] where $\boldsymbol{g}(x)=[g_1(x),\ldots, g_{\text{ne}}(x)]^T$ are equality constraints, $\boldsymbol{h}(x)=[h_1(x),\ldots, h_{\text{ni}}(x)]^T$ are inequality constraints, and $l_i\leqslant x_i\leqslant u_i$ for $i=1,\ldots,n$.

As an example of this kind of problems, we want to find $x^\star$ that minimizes $f(x)=(x_1-2)^2 + (x_2-2)^2 -2(x_1+x_2)$ with the conditions that $x$ must satisfy the equality constraint $x_1^2+x_2-2=0$ and inequality constraint $0\leqslant x_1^2-x_2\leqslant 1$ and $x_1,x_2$ are in the interval $[-1,2]$.

Written in the form required by the calculator, the constrained optimization becomes \[ \begin{aligned} \min_{x} \quad & f(x)=(x_1-2)^2 + (x_2-2)^2 -2(x_1+x_2) \\ \textrm{s.t.} \quad & g_1(x)=x_1^2+x_2-2=0\\ & h_1(x)=x_1^2-x_2 \geqslant 0 \\ & h_2(x)=1-x_1^2+x_2 \geqslant 0 \\ & -1\leqslant x_1 \leqslant 2 \\ & -1\leqslant x_2 \leqslant 2 \end{aligned} \] Note that the inequality constraints are in the form $h_i(x)\geqslant 0$, not $h_i(x)\leqslant 0$ or others, so $0\leqslant x_1^2-x_2\leqslant 1$ is splitted into two constraints $x_1^2-x_2\geqslant 0$ and $1-x_1^2+x_2 \geqslant 0$.

Input Data

  1. The input data for $f(x)$ has the same format as in Gradient Calculator
  2. The input data for equality constraints $\boldsymbol{g}(x)$ and inequality constraints $\boldsymbol{h}(x)$ have the same format as used in Jacobian Calculator where the signs $=0$ and $\geqslant 0$ are not required for $\boldsymbol{g}(x)$ and $\boldsymbol{h}(x)$, respectively. As this calculator is for constrained optimization problems, it requires at least one constraint, equality constraint or inequality constraint.
  3. The input data for $l$ and $u$ are entered in $n$ rows, each with 2 columns for $l$ and $u$, respectively. If the data is not entered, the calculator set them to $-10\leqslant x_1,\ldots,x_n\leqslant 10$.
  4. If the initial values $x_0$ are entered, they are separated by at least one space. If they are entered by a user, the calculator set them to $x_i=\text{random}(l_i,u_i)$ for $i=1,\ldots,n$.

Constrained Optimization Solver