issorted alternative for optimization toolbox

2 ビュー (過去 30 日間)
Kendall Knight
Kendall Knight 2019 年 2 月 20 日
編集済み: Matt J 2019 年 2 月 20 日
I have an optimvar A that needs to be constrained to be in descending order. The code
sorted = issorted(A,'descend') == 1;
prob.Constraints.sorted = sorted;
returns "Error using issorted. Undefined function 'issorted' for input arguments of type 'optim.problemdef.OptimizationVariable'."
Is there an alternative to 'issorted' to implement this constraint?
Thanks

採用された回答

Matt J
Matt J 2019 年 2 月 20 日
編集済み: Matt J 2019 年 2 月 20 日
You can do,
prob.Constraints.sorted = ( A(2:end) <= A(1:end-1) );

その他の回答 (1 件)

John D'Errico
John D'Errico 2019 年 2 月 20 日
Apparently not. However, you don't need it either. What stops you from just using a cumulative sum? Then constrain all elements of the vector but the first to be negative? The net result is you will have a decreasing sequence.
  1 件のコメント
Kendall Knight
Kendall Knight 2019 年 2 月 20 日
編集済み: Kendall Knight 2019 年 2 月 20 日
You're right. I did not think of that solution. The issue is the variable array is then mulitplied by a postive constant array and the total sum of the element wise multiplication of those two arrays is the minimiation objective. Because of this objective, constraining all but the first entry to be negative leads to the first entry taking on an unrealistic positive value due to the physical nature of the problem.

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

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by