% 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 = [coefficients(p-z'*S*z,[x1,x2])==0];          % ---> set に代わる新しい記述形式 []
sol0 = solvesdp(Fs0)
Sv = double(S);

% PSD matrix
U = sdpvar(length(z));
Fs = [Sv+U>=0, coefficients(z'*U*z,[x1,x2])==0];    % ---> set に代わる新しい記述形式 []

% solve SDP
sol = solvesdp(Fs)

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

% EOF
