0

I have a system of matricial equations where I want to find 2 matrices of 7x7 (so I am working with (1x98) vectors).

I have an issue when I want to use GlobalSearch Matlab function. Here my code :

Eq1 = (P1.')*(a.')*a*P1 + (P1.')*(a.')*b*P2 + (P2.')*(b.')*a*P1 + (P2.')*(b.')*b*P2 - eye(7);
Eq2 = F1*a*P1 + F1*b*P2 + F2*a*P1 + F2*b*P2 - (a*P1 + b*P2)*D;
Eqs = reshape([Eq1,Eq2],2*7*7,[]);
Fun = matlabFunction(Eqs);

F = @(x) Fun(...
    x(  1   ),  x(  2   ),  x(  3   ),  x(  4   ),  x(  5   ),  x(  6   ),  x(  7   ),...
    x(  8   ),  x(  9   ),  x(  10  ),  x(  11  ),  x(  12  ),  x(  13  ),  x(  14  ),...
    x(  15  ),  x(  16  ),  x(  17  ),  x(  18  ),  x(  19  ),  x(  20  ),  x(  21  ),...
    x(  22  ),  x(  23  ),  x(  24  ),  x(  25  ),  x(  26  ),  x(  27  ),  x(  28  ),...
    x(  29  ),  x(  30  ),  x(  31  ),  x(  32  ),  x(  33  ),  x(  34  ),  x(  35  ),...
    x(  36  ),  x(  37  ),  x(  38  ),  x(  39  ),  x(  40  ),  x(  41  ),  x(  42  ),...
    x(  43  ),  x(  44  ),  x(  45  ),  x(  46  ),  x(  47  ),  x(  48  ),  x(  49  ),...
    x(  50  ),  x(  51  ),  x(  52  ),  x(  53  ),  x(  54  ),  x(  55  ),  x(  56  ),...
    x(  57  ),  x(  58  ),  x(  59  ),  x(  60  ),  x(  61  ),  x(  62  ),  x(  63  ),...
    x(  64  ),  x(  65  ),  x(  66  ),  x(  67  ),  x(  68  ),  x(  69  ),  x(  70  ),...
    x(  71  ),  x(  72  ),  x(  73  ),  x(  74  ),  x(  75  ),  x(  76  ),  x(  77  ),...
    x(  78  ),  x(  79  ),  x(  80  ),  x(  81  ),  x(  82  ),  x(  83  ),  x(  84  ),...
    x(  85  ),  x(  86  ),  x(  87  ),  x(  88  ),  x(  89  ),  x(  90  ),  x(  91  ),...
    x(  92  ),  x(  93  ),  x(  94  ),  x(  95  ),  x(  96  ),  x(  97  ),  x(  98  ));

x0 =  ones(2*7*7,1);
gs = GlobalSearch;
options = optimoptions('fmincon','Algorithm', 'interior-point',...
    'UseParallel',true, 'Display','off','MaxFunctionEvaluations',6000, 'TolCon', 1e-4, 'TolFun', 1e-4);
problem = createOptimProblem('fmincon', ...
'objective',F, ...
'x0',x0, ...
'lb',[-1*ones(98)], ...
'ub',[1*ones(98)], ...
'options',options)
[x,fval] = run(gs,problem)

But I get unfortunately the following error at execution :

problem =

  struct with fields:

    objective: [function_handle]
           x0: [98x1 double]
        Aineq: []
        bineq: []
          Aeq: []
          beq: []
           lb: [98x98 double]
           ub: [98x98 double]
      nonlcon: []
       solver: 'fmincon'
      options: [1x1 optim.options.Fmincon]

Warning: Length of lower bounds is > length(x); ignoring extra bounds.
> In checkbounds (line 27)
  In checkglobalsearchnlpinputs (line 36)
  In globalsearchnlp
  In GlobalSearch/run (line 340)
  In compute_solving_Matricial_Global (line 96)
Warning: Length of upper bounds is > length(x); ignoring extra bounds.
> In checkbounds (line 41)
  In checkglobalsearchnlpinputs (line 36)
  In globalsearchnlp
  In GlobalSearch/run (line 340)
  In compute_solving_Matricial_Global (line 96)
Error using fmincon (line 635)
Supplied objective function must return a scalar value.

Error in globalsearchnlp

Error in GlobalSearch/run (line 340)
                globalsearchnlp(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,options,localOptions);

Error in compute_solving_Matricial_Global (line 96)
[x,fval] = run(gs,problem)

Caused by:
    Failure in initial call to fmincon with user-supplied problem structure.

How can I fix this error message?

I think that I did a correct using of GlobalSearch but maybe this issue comes from incorrect lower or upper bounds, or even with the size of vectors I use.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Editor's note: this question contained a supplementary question that was put to the answer author after they successfully answered the first question. They were unable to help with that, and as outlined elsewhere, additional questions should be asked as a new question anyway. I have therefore rolled this back to the last good state, so the Q&A is complete for this page. – halfer Sep 28 '21 at 19:44

1 Answers1

0

No, it's not the the dimension problem. Although we can not reproduce the error due to incomplete code, the error message is clear:

Supplied objective function must return a scalar value.

Tyr call F with a static vector and check the size of its results. It should return a single value.

But there are also warnings about upper/lower bounds:

...
      x0: [98x1 double]
...
      lb: [98x98 double]
      ub: [98x98 double]
...

According to fmincon docs:

x0 — Initial point

Initial point, specified as a real vector or real array. Solvers use the number of elements in, and size of, x0 to determine the number and size of variables that fun accepts.

Now, you specified x0 as 2*7*7 by 1, while lb and ub are 98 by 98. They should be all of same size.

saastn
  • 5,717
  • 8
  • 47
  • 78
  • @saadtn `F` represents a system of non linear equations (Matricial equations actually) and I am looking for fill the vector `x` = `ones(1,98)`which is the solution. Unfortunately, I don't understand what you mean when you say " `Tyr call F with a static vector` " : Isn't my vector already "static" : if you could explain me how to proceed, this would be fine. –  Dec 12 '20 at 10:51
  • @youpilat13 Global optimizers take an objective function and try to find a point in search space that optimize that function. `fmincon` can optimize functions with `n` variable and one result. So, independent of the problem at hand, if you want to use `fmincon` you need an objective function of form `f: R^n => R`. In your code `F` is specified as the objective function, call `F(x0)`, if it does not return a scalar, it won't suit `fmincon`. – saastn Dec 12 '20 at 11:37
  • ok, indeed `F` is a symbolic expression but could you give me please a code snippet adapted in my case ? –  Dec 12 '20 at 11:52