Hi Johan,
But in this case, everything looks fine. I know it's same issue lhs has a large numerical spanning. But the solver reported NEAR_OPTIMAL, res looks fine and in p=z^TQz coefficients can be cleaned by 1e-6. In fact I do believe the first sos constraint is strict (the first is the most important). Yet at x = (1000,1) for example, on both sides of first sos constraints the value are at order 1e32, and the different is at order 10^29. Should I trust the result?
clear;
x = sdpvar(2,1);
T = [1,0;0,100];
y = T*x;
recRuls = [1 0;-1 0;0 1;0 -1];
alpha = 0;
ktc = 1/6;
kdm = 1/(3.6*(1+alpha*100));
kta = 1/60;
kdx = 1e-4;
fedmon = 1 + alpha*y(2);
recRate = [ktc;kdm*y(1)*fedmon;kta*y(1)*fedmon;kdx*y(2)*fedmon];
mono = monolist(x,3);
monoq = replace(mono,x,x.^2);
P = sdpvar(length(mono));
C = [P>=0];
V = mono'*P*mono;
qV=0;
for r = 1:size(recRuls,1)
ds = y + recRuls(r,:)';
ds = T\ds;
qV = qV + recRate(r)*(replace(V,x,ds) - V);
end
[coq,moq] = coefficients(qV,x);
moqq = replace(moq,x,x.^2);
qqV = coq'*moqq;
fedmonq = replace(fedmon,x,x.^2);
b = sdpvar(1);
lhs = b-qqV;
C = C + sos(lhs);
B = [0,0;100,1000];
B = B/T;
a = B(1,:)';
c = B(2,:)';
N = [0,10;10,200];
N = N/T;
d = N(1,:)';
e = N(2,:)';
g = x.^2-e;
g = [g;d(2)-x(2)^2];
for i=1:length(g)
l = sdpvar(1);
C = C + [l>=0] + sos(-(qqV+1)-l*g(i,:)');
end
ops = sdpsettings('solver','mosek');
[sol,v,Q,res] = solvesos(C,b,ops);
for k = 1:length(Q)
rhs{k} = v{k}'*Q{k}*v{k};
end
eP = value(P);
eb = value(b);
V = mono'*eP*mono;
qV=0;
for r = 1:size(recRuls,1)
ds = y + recRuls(r,:)';
ds = T\ds;
qV = qV + recRate(r)*(replace(V,x,ds) - V);
end
[coq,moq] = coefficients(qV,x);
moqq = replace(moq,x,x.^2);
vqV = coq'*moqq;
lhst = b-vqV;