How does fmincon relate array parameters to constraints?

5 次查看(过去 30 天)
Hi-
I'm trying to use fmincon to minimize a function that takes an array input. I need to enforce a constraint on the values of the array such that if the array looks like:
[ a1 a2 a3 a4 a5; b1 b2 b3 b4 b5; c1 c2 c3 c4 c5]
then
c*a1 + a2 + d*a3 < ub1
c*a2 + a3 + d*a4 < ub1
and so on, and similarly,
c*b1 + b2 + d*b3 < ub2
c*b2 + b3 + d*b4 < ub2
My problem is that although it is clear that internally fmincon flattens the array, I can't figure out the order in which the flattening occurs, and hence I don't know how to shape the constraint matrix A. So, internally, does fmincon flatten my array as
[a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5]
or
[a1 b1 c1 a2 b2 c2 a3 b3 c3 a4 b4 c4 a5 b5 c5]?
I know I could flatten the array before passing it to fmincon but that would require an enormous amount of rewriting of the objective function, which is seriously nontrivial.

回答(2 个)

Matt J
Matt J 2014-7-11
编辑:Matt J 2014-7-11
So, internally, does fmincon flatten my array as...or...
It flattens the array as
[a1 b1 c1 a2 b2 c2 a3 b3 c3 a4 b4 c4 a5 b5 c5].'; %<--note transpose
See also Linear Indexing.
I know I could flatten the array before passing it to fmincon but that would require an enormous amount of rewriting of the objective function, which is seriously nontrivial.
It would be highly trivial. You could just insert the following line at the beginning of the objective function and leave the rest as is.
unknowns=reshape(unknowns,3,5);
But... there is no need to pre-flatten.

Glen
Glen 2014-7-11
That answers my question. Thanks!

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by