Why does my objective function return complex?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Snoopy
am 28 Feb. 2022
Kommentiert: Walter Roberson
am 2 Mär. 2022
I have a likelihood function that I need to minimize. I use fmincon to search for the minimum. Iterations of fmincon sometimes show "Objective function returned complex; trying a new point…" But in my code I do not take square root of any variable. Why am I then getting this error? A second question is whether there is a counterpart of
dbstop if naninf
for "complex" like the
dbstop if complex
command? Or would
dbstop if error
do?
2 Kommentare
Akzeptierte Antwort
Matt J
am 28 Feb. 2022
Bearbeitet: Matt J
am 28 Feb. 2022
There is no "dbstop if complex", but you can set a conditional breakpoints in your objective function to detect when theany particular value is complex.Or, insert a keyboard() command.
function fval=myobjective(x)
fval=....
if ~isreal(fval)
keyboard
end
end
4 Kommentare
Walter Roberson
am 2 Mär. 2022
suggest you add a conditional breakpoint to trigger if any(imag(VALUE))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!