Derivative of Function handle (To obtain the derivative of constraints in function fmincon)

1 回表示 (過去 30 日間)
sxj
sxj 2019 年 6 月 24 日
編集済み: sxj 2019 年 6 月 28 日
Hey, everyone, I'm using fmincon to solve the optimization problem under constraints. To increase the speed of calculation, I would like to provide the derivative matrix of the constraints. However, the constraint conditions are nonliner and complex, e.g as below.
where
the last one implies is also a function of . If I want to calculate the derivative of respect to , it will take a lot of efforts for me to calculate it by myself.
Does the MATLAB provide some tool to obtain the derivative of function handle, especially under using fmincon to solve the optimization problem ? Any suggestions to obtain the derivative of constraint conditions efficiently instead of calculating them by hand?

採用された回答

Matt J
Matt J 2019 年 6 月 24 日
編集済み: Matt J 2019 年 6 月 24 日
You can use the Symbolic Math Toolbox to obtain the expression for the derivative, and then use matlabFunction() to convert from symbolic form to function form.
  22 件のコメント
Matt J
Matt J 2019 年 6 月 28 日
編集済み: Matt J 2019 年 6 月 28 日
Change the first few lines in derivative_cons1,
Y = in1(1);
x1 = in1(2);
x2 = in1(3);
or make x_0 a row vector,
x_0 = [20,10,0.5];
sxj
sxj 2019 年 6 月 28 日
編集済み: sxj 2019 年 6 月 28 日
Thanks for your quick reply, Matt. I follow your suggestion and it works well. But I think it is inconvenient to change derivative_cons1 during running the whole code. So make x_0 a row vector will be better.
I also tried the following way
cons = matlabFunction([],[f1;f2;f3],[],jacobian([f1;f2;f3]).','File','derivative_cons1','Vars',{[Y;x1;x2]});
x_0 = [20;10;0.5];
opt = fmincon(@(x)objective(x), x_0,[], [], [],[],lb,ub, @(x)cons(x), options);
where I change the vector in the option 'Vars' from 1X3 to 3X1. In this way, it also works.
So far I have solved the simple version of my optimization problem and will turn to my original one. Thank you very much for all the discussions above, especially to Matt and Walter. I hope the discussions will also help others.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOptimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by