How can I using fmincon on both vector variables and matrix variables

19 ビュー (過去 30 日間)
Jingyu Liu
Jingyu Liu 2022 年 2 月 16 日
コメント済み: Walter Roberson 2023 年 9 月 15 日
I have a optimization problem with two variables: x is a vector and U is a matrix. I want to solving it by fmincon. My question is, how I can write the fmincon. More exactly, how to write the objective function and constraints? Or I have to transform U into a vector variable.
Any suggestion is appreciated. Thanks!
  8 件のコメント
Joshua Scott
Joshua Scott 2023 年 9 月 15 日
@Walter Roberson, What if you have both scalars and a matrix that need to be optimized?
Would I: Vectorize the matrix, reshape within the function getting called by fmincon, and reshape after fmincon?
Or am I missing a step?
Thank you for the guidance!
Walter Roberson
Walter Roberson 2023 年 9 月 15 日
function [c, ceq] = nonlcon(X) %example
x = X(1);
U = reshape(X(2:end), 5, 20); %U is 5 x 20
%now use x and U to compute c and ceq
end
And yes, after the optimization when you have the packed vector, you would to the same extraction to get the final values.

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

採用された回答

Alan Weiss
Alan Weiss 2022 年 2 月 16 日
You might enjoy the problem-based approach, which does not require you to put all variables into one.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Jingyu Liu
Jingyu Liu 2022 年 2 月 17 日
Thanks for your answer, it really helps me a lot!

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

その他の回答 (0 件)

カテゴリ

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