We consider a problem with both equality and inequality constraints
In [1]:
using Polyopt
In [2]:
x, z = variables(["x", "z"]);
In [3]:
f = x + z;
In [4]:
g = x - z;
In [5]:
h = x^2 + z^2 - 1;
In [6]:
prob = momentprob(2, f, [g], [h]);
In [7]:
X, Z, t, y, solsta = solve_mosek(prob);
We inspect the solution,
In [8]:
[prob.basis y]
Out[8]:
In [9]:
t - Polyopt.evalpoly(f, y[[6,2]])
Out[9]:
In [10]:
Polyopt.evalpoly(g, y[[6,2]]) >= 0
Out[10]:
In [11]:
abs(Polyopt.evalpoly(h, y[[6,2]])) < 1e-5
Out[11]:
The returned solution consists objective value of the relaxation,
In [12]:
t
Out[12]:
of two semidefinite matrices $X_1$ and $X_2$, corresponding to $f(x,z)$ and $g(x,z)$,
In [13]:
X
Out[13]:
a symmetric indefinite matrix $Z_1$ corresponding to $h(x,z$),
In [14]:
Z
Out[14]:
and $y$ from which we extracted the coefficients for the optimal monomial solution,
In [15]:
y
Out[15]:
The dual interpretation expresses $f(x,z) - t = v_1^T X_1 v_1 + g(x,z) v_2^T X_2 v_2 + h(x,z) v_2^T Z_1 v_2$, in other words we express $f(x,z)-t$ as
where $s_0(x,z)$ and $s_1(x,z)$ are sums-of-squares, but $w(x,z)$ is not. Let us verify the expression,
In [16]:
v1 = monomials(2, [x,z])
Out[16]:
In [17]:
v2 = monomials(1, [x,z])
Out[17]:
In [18]:
f-t
Out[18]:
In [19]:
truncate( dot(v1, X[1]*v1) + g*dot(v2, X[2]*v2) + h*dot(v2, Z[1]*v2), 1e-8 )
Out[19]:
In [ ]: