- Your x0 should be ones(3*N,1), not ones(N,3)
- Your boundaries should be [-Inf(N,1); -Inf(N,1); zeros(N,1)], not [-Inf(N,1),-Inf(N,1),zeros(N,1)] (note the ";" instead of ",").
- Haven't looked into you objfun, but there you can change the x from (3*N)x1 back to Nx3 if it helps.
Matrix input and matrix variables in minimization of an objective function
3 views (last 30 days)
Show older comments
Hannaneh
on 26 Mar 2015
Commented: Titus Edelhofer
on 26 Mar 2015
I have three variables S,V,B .Each variable is a 16*1 Matrix. I'd like to minimize an objective function, which is a summation of variables in these matrices. There are also some linear constraints for this model. I get the error "Not enough input arguments" on this optimization model:
% [S,V,B,fval]=fmincon('objfun',x0,[],[],[],[],[-Inf(N,1),-Inf(N,1),zeros(N,1)],[Inf(N,1),Inf(N,1),ones(N,1)],'constraint');
I guess the way I define the input variables is not right.
I've attached the main code, the objective function and the constraints. I would be appreciated if you could take a look and help me.
0 Comments
Accepted Answer
Titus Edelhofer
on 26 Mar 2015
Hi Hannaneh,
you need to have one vector of variables, not a matrix. So
Titus
4 Comments
Titus Edelhofer
on 26 Mar 2015
Again, the error tells you what's wrong ;-).
fmincon minimizes the value of the objective function. Therefore, the objfun should return a value, not a vector. Your function takes the sum, so it should be a scalar in fact.
My suggestion: put a breakpoint into your objfun (klick in the editor on one of the small lines next to the line number). A red bullet should appear. Run the code. Go stepwise through the code and see, what sizes the variables have, and esp. why at the end the return variable f is not a scalar ...
Titus
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!