3

I have a MINLP objective function and I want to fix some variables value into constant as an example described below:

A = [1 1 1];
b = 30;
x1 = zeros(1,3);
y=1;
x = fmincon(@(x)objfun(x,y),x1,A,b);

function f = objfun(x,y)
x(y) = 1;
f = x(1)^2 + x(2)^2 + x(3)^2;
end

However, the result of variable x is all zeros. It seems that x(1) cannot be forced to be 1. How to fix this problem?

Dev-iL
  • 22,722
  • 7
  • 53
  • 89
bnbfreak
  • 343
  • 3
  • 12

1 Answers1

4

You should use a different syntax of fmincon:

fmincon(fun,x0,A,b,Aeq,beq,lb,ub)

Then, if you wish to only limit one of the values, you can use these bounds:

lb = [1 -Inf -Inf]; 
ub = [1 Inf Inf];

Since you will also need to specify the inputs Aeq and beq, don't forget you can use [] for any inputs you don't want/need to specify, as shown in this example in the documentation:

fun = @(x)1+x(1)./(1+x(2)) - 3*x(1).*x(2) + x(2).*(1+x(1));
lb = [0,0];
ub = [1,2];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0.5,1];
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
Dev-iL
  • 22,722
  • 7
  • 53
  • 89