フィルターのクリア

how to do conditional statements using optimisation variables?

9 ビュー (過去 30 日間)
NN
NN 2021 年 5 月 4 日
コメント済み: Julian 2023 年 7 月 21 日
hi all, how can i perform logical comparison using optimisation variable ?
I have tried this below code for optimisation using optimisation variable PbattV , but getting error :
Cost = Costa.*(PbattV<=200) +Costb.*(PbattV>=200);
P1= dt*Cost'*PbattV;
P2=dt*Cost'*PbattV;
P=P1-P2;
prob.ObjectiveSense = 'minimize';
prob.Objective = P;
An error occurred while running the simulation and the simulation was terminated Caused by: times Please help if you have any suggestion
basically i need to check if Pbatt is positive or negative and accordingly i have to chose Cost and use it for objective function;
  1 件のコメント
Julian
Julian 2023 年 7 月 21 日
Hi NN, I wanted to ask If you have found a working solution for your problem?
Have you found a way to rewrite your Problem?

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 4 日
Cost = Costa.*(PbattV<=200) +Costb.*(PbattV>=200);
Optimization variables cannot be converted to logical values. The only time you can compare an optimization variable to a value is in constructing a constraint.
Give up on trying to code it in terms of comparison operators: you will not succeed.
If there is a solution, then it will involve using mathematical tricks such as sqrt(x^2)/x to get the sign(x)
  17 件のコメント
NN
NN 2021 年 8 月 19 日
Ok.Still when it doesnt support another function with conditional statements, or even constraints, i cant perform that operation.
I am thinking some other approach without considering sign change
Walter Roberson
Walter Roberson 2021 年 8 月 21 日
When you have discontinuous derivatives, the alternative supported by MATLAB are:

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOptimize Model Response についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by