Fmincon works for MATLAB version 2020a but not for version 2021b

5 ビュー (過去 30 日間)
Huseyin Eken
Huseyin Eken 2021 年 11 月 17 日
回答済み: Kumar Pallav 2021 年 11 月 28 日
Hello!
I have a convex function (i.e., energy) that I would like to minimize on a single variable named x. My code looks like this:
x = optimvar('x', 'LowerBound', 0); %Definition of the variable with constraints
prob = optimproblem; %Definition of the problem
prob.Objective = energyfun; %Set the objective to minimize energy
x0.x = 10; % Initial point of the optimization variable
sol = solve(prob, x0);
I am getting the following error: Gradient at initial point contains Inf, NaN, or a complex values. Fmincon cannot continue.
But the most interesting part is that I have tried my code on different computers with MATLAB versions 2021b and 2020a. Basically, it works on the 2020a version but not on 2021b.
I have checked the optimoptions of the fmincon solver in both versions and they are exactly the same. Am I missing something or did something changed between these two versions?
Thank you all in advance!
  4 件のコメント
Matt J
Matt J 2021 年 11 月 17 日
編集済み: Matt J 2021 年 11 月 17 日
It is strange to be using fmincon for a simple 1D minimization. You could use fminbnd, instead. Then you wouldn't need to worry about gradients, because fminbnd doesn't use them..
Huseyin Eken
Huseyin Eken 2021 年 11 月 17 日
Thanks for the input, i will try also with fminbnd as you suggested. Actually, I can solve the problem with other solvers like the genetic algorithm. What I found strange was that fmincon works for a version of MATLAB and not for the other.
As a side note, I would like to add more parameters to the optimization problem later on. This is just the starting point that I found in literature.

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

回答 (1 件)

Kumar Pallav
Kumar Pallav 2021 年 11 月 28 日
Hi,
Please refer to a similar issue here.
You could set breakpoints for debugging at the command line:
dbstop if naninf
and run your program. If it stops in the debugger then you encountered a nan or inf and you will be able to explore the values in the debugger to see what is happening.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by