undefined function or variable 'optimproblem'

3 ビュー (過去 30 日間)
Jidong Wang
Jidong Wang 2018 年 1 月 15 日
コメント済み: Mehdi Babaei 2019 年 9 月 2 日
I wanted to develop and solved an optimization problem with some exogenous variables. I tried to do it in a problem-based way, just as the Mathworks instruction says.
function sol=CS(Sa,Sc,en,e)
%%Define natural variables
mu=0.5;
ld=100;
alf=0.8;
%%Define core variables
prob = optimproblem('ObjectiveSense','maximize');
r= optimvar ('r', 'LowerBound',0, 'UpperBound', 1);
h=r*e;
H=-(1-alf)*ld/(mu*(mu*Sa-(1-alf)*ld))+ld/(mu*(mu*Sc-alf*ld));
l1=(1-alf)*alf+alf^2*h*mu;
l2=alf*h*mu*(mu*Sa-ld)-alf*mu^2*Sc*h+alf*ld+alf*mu*Sc+mu*Sa-ld;
l3=-h*mu^2*(mu*Sa-ld)*Sc-mu*Sc*ld;
ldc=piecewise([H<=0,ld],[H>0,piecewise([h>=0 & h<H,(-l2+sqrt(l2^2-4*l1*l3))/(2*l1)],[h>H,ld])]);
Ya=(1-alf)*ld*es+alf*(h+en)*(ld-ldc);
%%Optimization
prob.Objective=Ya;
sol=solve(prob);
end
But when run, it notified: undefined function or variable 'optimproblem'. Then I typed 'help optimproblem' in the command line, and same message occurred. My version is R2017a, and the Optimization Toolbox is installed. How to fix it?
Thanks!

採用された回答

Matt J
Matt J 2018 年 1 月 15 日
編集済み: Matt J 2018 年 1 月 15 日
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 16 日
Good point about the piecewise.
For optimization problems that involve piecewise, often it turns out to be necessary to break the problem up into subsets that are individually not piecewise, optimize over each subset, and then take the best of the solutions.
Jidong Wang
Jidong Wang 2018 年 1 月 17 日
Thanks for your additional comment. That's helpful!

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

その他の回答 (1 件)

Mehdi Babaei
Mehdi Babaei 2019 年 9 月 2 日
optimproblem is not defined in matlab 2017a version. you need to install 2018b version.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 2 日
R2017b was the version that introduced it.
Mehdi Babaei
Mehdi Babaei 2019 年 9 月 2 日
Yes, my mistake. 2017b is correct.

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

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by