How does fmincon relate array parameters to constraints?
2 次查看(过去 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.
0 个评论
回答(2 个)
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!