Fmincon gives Exact the same Answer as the initial guess

This is how I defined fmincon options
fminoptions = optimoptions('fmincon','Display','iter','Algorithm','interior-point');
problem.options = fminoptions;
problem.solver = 'fmincon';
%problem.nonlcon = @Constraints;
problem.objective = @obj;
problem.ub = [200,40];
problem.lb = [190,30];
[x,sln2.objective] = fmincon(problem);
x(1)
x(2)
This is the objective function:
ob = Ext.W22.*(Ext.TC1 - (round(x(1)))*(round(x(2)))).^2

 Accepted Answer

Matt J
Matt J on 2 Jun 2021
Edited: Matt J on 2 Jun 2021
Because of the round() operations, your objective function is locally flat (i.e., has zero gradient) almost everywhere. Therefore, almost every initial point you can choose is a local minimum.
Be mindful also that fmincon is a derivative based solver. It assumes you have a continuously differentiable objective function and nonlinear constraints. The discontinuous nautre of round() operations ruin that as well.

6 Comments

Thankyou very much MATT it really solved the problem. But can you give opinion on resolving the problem of continuos optimization parameter in fmincon. I want integers to be my optimized parameters instead of continuous numbers. My problem may also include non linear constraints at later stages that is why I am using fmincon. Can I handle these 2 issues in it or do there is some other good solver for it?
Since you only have a two variable problem you could do a combinatoric search. You only have 100 feasible values to test.
What do you mean by 100 feasible values ? I am planning to expand my problem later. At max how much design parameters it can handle ?
121 combinations, rather than 100.
x1 = 190:200
x1 = 1×11
190 191 192 193 194 195 196 197 198 199 200
x2 = 30:40
x2 = 1×11
30 31 32 33 34 35 36 37 38 39 40
[X1, X2] = meshgrid(x1, x2);
pairs = [X1(:), X2(:)];
pairs(1:12,:)
ans = 12×2
190 30 190 31 190 32 190 33 190 34 190 35 190 36 190 37 190 38 190 39
size(pairs)
ans = 1×2
121 2
Now you can
rows = size(pairs,1);
results = zeros(rows,1);
for K = 1 : rows
x = pairs(K,:);
ob = Ext.W22.*(Ext.TC1 - (round(x(1)))*(round(x(2)))).^2;
results(K) = ob;
end
[fval, bestidx] = min(results);
x = pairs(bestidx, :);
Your posted problem has x1 in the range [190,200] and x2 in the range [30,40], which contain 11^2 integer values. Five unknowns with similar bounds would contain 11^5 values, which is also not too bad. It's hard to give advice without seeing the real problem.
yes that is helpful. But If I need to expand the problem and later I need to include many other design parameters then it woyulb become bery tough to solve with it. But for the problem in hand its one of the best and easy solution.

Sign in to comment.

More Answers (1)

fmincon() is never suitable for discrete parameters.
If you have mixed integer work that has a scalar output then your options are:
  • ga -- supports anonymous functions; supports nonlinear constraints
  • abusing patternsearch() -- supports anonymous functions; supports nonlinear constraints
  • intlinprog() -- supports matrix objectives only; does not support nonlinear
  • surrogate optimization -- supports anonymous functions; supports nonlinear constraints; https://www.mathworks.com/help/gads/surrogateopt.html
In order to use integer constraints with ga(), you have to write your own functions to handle cross-over and mutation and initial population -- functions that just happen to obey the required integer constraints. The more obvious integer constraints for ga() are incompatible with providing nonlinear contraints.
Surrogate optimization provides obvious integer constraints, but does not provide obvious nonlinear constraints. However, instead of your objective function returning a numeric scalar, it can instead return a struct with a particular form, and surrogate optimization will follow the nonlinear constraints expressed in the structure.

2 Comments

Thankuou very much for such help. What is meant by obvious ininteger constraints ? Can you please help me to understand What you want say in the last 2 paragraphs more explicitly?
ga has a calling form which is
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)
However:
"When there are integer constraints, ga does not accept linear or nonlinear equality constraints, only inequality constraints."
so when the IntCon parameter is not empty, then it is okay for A and b and lb and ub to be non-empty, but Aeq, beq, and nonlcon would have to be empty.
ga() handles integer constraints internally by providing its own crossover and mutation and population construction functions that enforce the integer constraints. If you need both nonlinear constraints (nonlcon not empty) and integer constraints, then what you need to do is pass IntCon as empty, and supply your own crossover and mutation and popopulation construction functions that "just happen" to return values that follow the desired integer constraints.
surrogateopt() supports a syntax of
x = surrogateopt(objconstr,lb,ub,intcon,A,b,Aeq,beq)
which has a position for integer constraints. But notice that there is no position there for nonlinear constraints. surrogateopt() does not use a separate function that is in charge of testing for nonlinear inequalities. Instead,
objconstr returns one of the following:
  • Real scalar fval = objconstr(x).
  • Structure. If the structure contains the field Fval, then surrogateopt attempts to minimize objconstr(x).Fval. If the structure contains the field Ineq, then surrogateopt attempts to make all components of that field nonpositive: objconstr(x).Ineq <= 0 for all entries. objconstr(x) must include either the Fval or Ineq fields, or both. surrogateopt ignores other fields.
So you can implement nonlinear constraints by having the function return a struct that has an Ineq field.
surrogateopt does not support nonlinear equality constraints directly. You could, however, have the Ineq field return both a constraint value and its negative: surrogateopt would try to make both of the entries <= 0 and except for tolerance ranges, the only way for both of them to be <= 0 would be if the entry was 0.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!