We examime whether $f(x,z) = 2 x^4 + 2 x^3 z - x^2 z^2 + 5 z^4$ can be written as a sum of squares.
In [1]:
using Polyopt
In [2]:
x, z = variables(["x", "z"]);
In [3]:
f = 2*x^4 + 2*x^3*z - x^2*z^2 + 5*z^4;
The degree of $f$ is 4, so we need a second order relaxation,
In [4]:
prob = momentprob(2, f);
We solve the problem,
In [5]:
X, Z, t, y, solsta = solve_mosek(prob);
Since $t$ is zero, we have a sum-of-squares certificate
In [6]:
t
Out[6]:
In [7]:
X[1]
Out[7]:
To verify the sum-of-squares certificate, we compute a monomial vector
In [8]:
v = monomials(2, [x, z])
Out[8]:
In [9]:
u = chol(X[1])*v
Out[9]:
or discarding monomial terms with small coeffients,
In [10]:
u = [truncate(ui, 1e-8) for ui=u ]
Out[10]:
and the sum-of-squares term can be evaluated to
In [11]:
truncate(f - dot(u,u), 1e-8)
Out[11]: