How do I solve the error "Error using barrier Finite difference derivatives at initial point contain Inf, NaN, or complex values. Fmincon cannot continue."

I am using R2020a and I ran into the following error when using fmincon function:
"Error using barrier Finite difference derivatives at initial point contain Inf, NaN, or complex values. Fmincon cannot continue.
Error in fmincon (line 834) [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ..."
I am very confused because earlier the function ran well. The only change I make is I try to use the parallel computing to speed up the optimization.
"options = optimoptions('fmincon','UseParallel',true)"
Before I added the UseParallel function, the fmincon ran well and there was no this error. In my understanding, the finite difference derivatives at initial point shouldn't be effected by using parallel or not?
I do not really know how to solve this problem. I tried to use diff function to find an initial point where the derivative is a finite real number. But diff(fun(x)) always returns [ ], which I confuses me more.

4 Comments

Do you use global variables in funfcn ? This should be avoided if using the parallel processing functionality.
Thank you for your reply! I do use global variables in my optimization. Is there any way to use global variables and parallel processing functionality at the same time?
Is there any way to use global variables and parallel processing functionality at the same time?
No. The closest you could get would be if you had a limited number of places where you change the variable, and you put in logic at each of the places to send the new value of the variable back to the controller, which would then send the value to each of the workers.

Sign in to comment.

Answers (0)

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Asked:

on 23 May 2021

Commented:

on 24 May 2021

Community Treasure Hunt

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

Start Hunting!