I want to create an optimization script with fmincon, including an equation (f2), which is not solved by fmincon. This equation will be solved with a function (see bottom of the script in the function 'kostfunktion'), but it contains the parameters x(1) and x(2) from the optimization problem. The problem is, that f2 and therefore fval are always negative. How can I set these parameters to a minimum of 0 or at least let them be positive?
The involving case is this one:
- f1 = 10*x1 + 2*x2 - 30 f2 = - 2*x1 - 10*x2 + 30
Bounds: 1<=x1<=5 1<=x2<=5 0<=f1<=inf 0<=f2<=inf
The optimization goal is to get the minimum of: obj = f1 + f2
f1 will be solved by fmincon. f2 will be solved in the function 'kostfunktion'.
clc, clear, clear global;
x0 = [2; 2; 1];
A = ;
b = ;
Aeq = [-10 -2 1];
beq = [-30];
lb = [1; 1; 0];
ub = [5; 5; inf];
options = optimoptions('fmincon', 'Display', 'iter');
[x fval] = fmincon(@kostfunktion,x0,A,b,Aeq,beq,lb,ub,,options);
function obj = kostfunktion(x)
f2 = -2*x(1)-10*x(2)+30;
obj = x(3) + f2;
The optimal solution should be obj = 0 with x1 = 2.5 and x2 = 2.5, but in this script, the solution is obj = -24, because I can't set bounds for f2. How can I set the bounds for f2 or fval?
Thanks for your support.