I am using fmincon to find some optimum mix using a large set of data and have come to a couple of doubts.
First the relevant section of my code:
x0 = [a_ms a_lc a_lr]; %initial state epsi = 1 ; % Epsilon factor options =optimoptions('fmincon','Algorithm','active-set') ; A = [e_ms e_lc e_lr] ; % equation left side b = epsi*csm ; % equation right side [x_res,fval] = fmincon(@objfun,x0,A,b,,,,,,options); valopt = x_res(1)*e_ms + x_res(2)*e_lc + x_res(3)*e_lr ;
I want to find the decision variables a_ms, a_lc and a_lr that minimize an objective function objfun . A is a 24000x3 matrix with data of production from three different sources and b is a 240000x1 vector with consumption data. As it is my first time using fmincon, is the approach in the code the correct one to optimize the problem for all the data?
After running the above lines, if I change one parameter in my objective function sometimes I get one of the three optimal values of the result ( x_res(2) ) as a negative, so I was thinking to include a restriction so that none of the decision variables can be less than zero. How can I do this?, shoud I add three more rows at the bottom of A and b in order to reflect this or is there another way?
Thanks beforehand for your help.
This is not even remotely a large problem. That you have a moderately large (but not really) array of size 24000x3 is not relevant. What matters are the number of variables. You have THREE variables, which makes this essentially a trivially small problem.
We are not told what objfun does. Is objfun a linear relationship in the parameters? I'm wondering if it is so. If so, then fmincon is not even the right tool to solve this. You might want to use a tool like lsqlin or even linprog.
fmincon, lsqlin, and linprog all allow both linear inequality constraints, as well as bound constraints. Note all of those  bracket parameters where you passed in nothing to fmincon? consider what the variable called lb would do. lb stands for lower bounds of course. So if it makes no sense for a variable to be negative in your process, then a lower bound of zero will be appropriate.
Sometimes, tools like fmincon can allow a variable to exceed the bound constraints by a tiny amount. If even this is intolerable, then you can always consider working in a log domain. Thus fmincon will optimize the log of the variable. In the function, you would work with exp(x), which is always positive of course. This allows you to approach arbitrarily close to zero, yet not fall below that bound.