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!
  1 件のコメント
Ben11
Ben11 2014 年 7 月 11 日
Don't forget to accept the answer :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver 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