Clear Filters
Clear Filters

fmincon, find integer values as optimal values

5 views (last 30 days)
f =@(fr)(50*fr(1)^2 + 100)/fr(1) + (175*fr(2)^2 + 150)/fr(2) + (160*fr(3)^2 + 250)/fr(3)
lb = [0,0,0];
ub = [5,5,5];
A = [];
b = [];
Aeq = [];
beq = [];
fr0 = [1,1,1];
fr = fmincon(f,fr0,A,b,Aeq,beq,lb,ub)
output:
f =
function_handle with value:
@(fr)(50*fr(1)^2+100)/fr(1)+(175*fr(2)^2+150)/fr(2)+(160*fr(3)^2+250)/fr(3)
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
fr =
1.4142 0.9258 1.2500
I want to find positive integer values rather than decimal values for my variables. is there any way to include this condition with fmincon? any help will be highly appreciated. thank you

Accepted Answer

Sean de Wolski
Sean de Wolski on 1 Feb 2018
Edited: Sean de Wolski on 1 Feb 2018
fmincon is not designed to deal with integer x values. You should try ga() which has an IntCon option or patternsearch() with a round() on the input values.
Of course for a small problem like this there are only 216 unique combinations of x so you could easily brute force it.
[rr,cc,pp] = ndgrid(0:5);
v = (50*rr.^2 + 100)./rr + (175*cc.^2 + 150)./cc + (160*pp.^2 + 250)./pp;
[val, idx] = min(v(:));
[rr(idx) cc(idx) pp(idx)]
  1 Comment
Mohamed Musni
Mohamed Musni on 1 Feb 2018
thank you. I found tutorial with ga() and abled to get answer with integer values. have a nice day

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!