How does fmincon relate array parameters to constraints?

조회 수: 5 (최근 30일)
Glen
Glen 2014년 7월 10일
댓글: Ben11 2014년 7월 11일
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