oxfordcontrol / SOSTOOLS

A free MATLAB toolbox for formulating and solving sums of squares (SOS) optimization programs
51 stars 14 forks source link

upper and lower bounds check in findbound #11

Closed lucacarlone closed 1 year ago

lucacarlone commented 1 year ago

The following line (line 213 in findbound.m) throws an error in MATLAB R2020a on Mac:

ach = double(subs(p,num2cell(vars).',num2cell(xopt).'));

Minimal example:

pvar v1 v2 v3
v = [v1;v2;v3];
degree = 2;
normsq_v = sum(v.^2);
[gam2,vars,opt] = findbound( v1 + v2^2 + v3,[1 - normsq_v],[],degree);

Error:

Error using polynomial/subs (line 103)
Old must be a No-by-1 array of polynomial variables or a No-by-1 cell array of characters.

Error in findbound (line 213)
    ach = double(subs(p,num2cell(vars).',num2cell(xopt).'));

If I comment out lines 213 to 218 in findbound.m, the optimization runs and returns results without errors.

%   ach = double(subs(p,num2cell(vars).',num2cell(xopt).'));
%   
%   if min(abs(ach/GAM-1),abs(ach-GAM)) > 1e-4 ; 
%        xopt = [];
%        return;
%    end
lucacarlone commented 1 year ago

As far as I see, there seem to be two issues:

  1. num2cell(vars) is not parsing the input variables correctly (which should be easy to fix by using num2cell(vars,length(vars)).' in line 213 instead.
  2. "ispvar" inside "subs" fails to identify that the cell array "old" has polynomial entries.
djagt commented 1 year ago

Thank you for pointing out this issue, as well proposing a potential fix! That's always very helpful.

However, I seem unable to reproduce your error. In fact, the call

ach = double(subs(p,num2cell(vars).',num2cell(xopt).'));

does not appear in line 217 of my version of findbound. We have made some changes to findbound, but not since releasing v4.03 (see the lists of known bugs). Do you have the latest version of the codes installed?

lucacarlone commented 1 year ago

thanks for the prompt reply @djagt ! I think the code I'm referring to is in the master branch, while you are probably referring to the SOSTOOLS400 branch. Switching to the latter seems to solve the issue on my side as well. If that makes sense to you, we can mark the issue as solved.

djagt commented 1 year ago

Indeed, the SOSTOOLS400 branch contains the most recent codes. I realize its a bit confusing, as one would assume the master branch to be the main one. Maybe I should rename these branches....

Either way, I will close this issue. Let me know if you encounter any other problems.