Error using GA in MATLAB for nonlinear constrained optimization

3 ビュー (過去 30 日間)
Mohammad
Mohammad 2018 年 3 月 22 日
コメント済み: Walter Roberson 2018 年 3 月 24 日
I am using GA in MATLAB to minimize a convex function. I am getting the following error,
Error using constrValidate (line 59)
Constraint function must return real value.
But when in the cost.m the system called "sys" is created (which is a global variable), then the constr function computes its H_\infty norm which is a real value. Still I don't understand why I am getting this error.
My codes are attached.
Any help is really appreciated.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 24 日
constr.m is receiving an empty sys which leads to hinfnorm warning and returning infinity.
sys is empty because it is a global variable that has not been initialized.
sys has not been initialized at that point because the cost function has not yet been called.
It is permitted for ga to invoke the constraint function before the cost function, as ga wants to be sure that the proposed points are valid before bothering to calculate their cost.
Your cost function needs to calculate sys as well.
If you have a more recent version, you could consider moving the calculation of sys into a function with k as input, and memoizing the function, https://www.mathworks.com/help/matlab/ref/memoize.html
  2 件のコメント
Mohammad
Mohammad 2018 年 3 月 24 日
Thanks. I have modified constr.m and cost.m as attached (also I removed globality for sys) but this time I am getting the following error, Gramians cannot be computed for models with unstable dynamics.
Walter Roberson
Walter Roberson 2018 年 3 月 24 日
A+Kbar (which is A+diag(k) where k is the random input) has positive eigenvalues, which makes it an unstable dynamic matrix -- if left to run long enough, some parts of the system would go infinite.
You need to take into account that ga can call the nonlinear constraint function in any order compared to the cost function. The cost function is not being called exclusively with values that pass the nonlinear constraints first -- and sometimes the cost function is run even if the nonlinear constraint function has rejected the value (it happens for the very first call at least.)

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

その他の回答 (1 件)

Sebastian Castro
Sebastian Castro 2018 年 3 月 23 日
Pretty sure it's because hinfnorm can return an Inf value if the input system is unstable...
So you're going to have to handle that case and, as the error message said, return a real (or finite) number. Easiest thing is probably to limit the value of your constraint function to some really large value, keeping in mind that the optimizer just needs to keep this value <= 0.
- Sebastian
  3 件のコメント
Sebastian Castro
Sebastian Castro 2018 年 3 月 24 日
Hmm... then maybe some of those input variables (c or gamma2) are returning complex numbers.
Have you tried putting a breakpoint in your function and seeing what comes out?
- Sebastian
Mohammad
Mohammad 2018 年 3 月 24 日
well, in the modified constr.m file, c is a real value either 1e10 or -1e10. gamma2 is 10000000 which is real too.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by