% sos_decomposition3.m

% 2011/01/25   H. Ichihara

clear all;

% polynomial
sdpvar x1 x2;
p = 2*x1^4+3*x1^2*x2^2+2*x1*x2^3+4*x2^4;

% monomial vector and symmetric matrix
z = [x1^2 x1*x2 x2^2]';
S = sdpvar(length(z));

% solve LP
Fs0 = set(coefficients(p-z'*S*z,[x1,x2])==0);
sol0 = solvesdp(Fs0)
Sv = double(S);

% PSD matrix
U = sdpvar(length(z));
Fs = set(Sv+U>=0)+set(coefficients(z'*U*z,[x1,x2])==0);

% solve SDP
sol = solvesdp(Fs)

% check set
if sol.problem ~= 1
 pres = checkset(Fs(1))
end

% EOF
