Why does my objective function return complex?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2022-2-28
编辑:Matt J
2022-2-28
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!