sdpvar x t
n = 1
p = x^4-2*x+1;
[~,~,info] = solvemoment([],p);
% Lower bound
relaxdouble(p)
% Rank-1 moment matrix from which solution is extracted
% Simple case, rank-1
info.moment{end}
eig(info.moment{end})
% the n first monomials are linear
sdisplay(info.monomials)
assign(info.monomials(2:2+n-1),info.moment{end}(1,(2:2+n-1)))
double(p)
% SOS approach, exploits structure if available
% Unfortunately, I don't seem to return dual information, i.e., the moment
% matrix
[sol,m,B,residual,more] = solvesos(sos(p-t),-t);
% Hence, let YALMIP compile the SOS program, and go from there
[F,h] = compilesos(sos(p-t),-t);
solvesdp(F,h);
M = double(F(1));
% If the ordering of monomials is the same, these two coincide
info.moment{end}
M = M/M(1,1)
% A bit messy, since compilesos does not return ordering of monomials, so
% we have to reuse info from solvesos...
assign(m{1}(2:2+n-1),M(1,(2:2+n-1)))
double(p)