Error running fmincon

Dear Octave users:

I’m calling fmincon with options set as:

options = optimset('Algorithm','active-set','Display','off', 'TolFun', 0.1);

with the following constraints:

Aeq, beq, lb, ub, x0.

Inputs are like this:


As you see, inputs are column series of real values, and it works perfectly when I don’t have any NaN field. However, with a single NaN field in any of the columns, I get the following errors:

error: qp: failed to compute eigenvalues of H
error: called from
    qp at line 422 column 29
    sqp at line 425 column 31
    __octave_sqp_wrapper__ at line 76 column 60
    fmincon at line 451 column 24 

qp at line 422 column 29 reads:

 if (info == 0)
    ## The initial (or computed) guess is feasible.  Call the solver.
    [x, lambda, info, iter] = __qp__ (x0, H, q, A, b, Ain, bin, maxit, rtol); %(LINE 422)
    iter = 0;
    x = x0;
    lambda = [];

sqp at line 425 column 31 reads:

## Compute search direction p by solving QP.
g = -ce;
d = -ci;

old_lambda = lambda;
[p, obj_qp, INFO, lambda] = qp (x, B, c, F, g, [], [], d, C,
                                Inf (size (d)), struct ("TolX", tol)); % LINE 425

info =;

octave_sqp_wrapper at line 76 column 60 reads:

## call sqp
[p_res, objf, info, outp.niter, outp.nobjf, outp.lambda] = ...
      sqp (pin, passed_f, {equc, dequc}, {inequc, dinequc}, -Inf, Inf,
           niter, tolerance);

My code works perfectly using Matlab’s fmincon.

Any help would be appreciated.
Thank you.

My system

  • Ubuntu 14.04 LTS
  • Octave version: 6.3.0 (2021-07-11)
  • Installation method: snap installation.

Please show us relevant portions of your code also. Particularly the variable which has the single NaN in it, and where that variable is used in connection with fmincon.

As a general comment, having NaN values is going to be a problem. If you are using NaN to substitute for data that you don’t have (for example, a sensor was faulty or someone simply forgot to record a data point at a particular time) then you would be better off choosing a value that is numerical but outside of any normal bounds.

The problem is that when NaN is used in any mathematical operation the result is also NaN so even one instance can slowly poison all future calculations.

NaN + 1 -> NaN
NaN - 1 -> NaN
NaN * 2 -> NaN
NaN / 2 -> NaN

In this case, trying to compute the eigenvalues of a matrix requires lots of multiplication and summation operations which inevitably get corrupted.

Thank you.

Thank you, rik. I am using nanmean (and others to ignore or treat NaN) function, and all works fine in Matlab.
I will check all your suggestions, though! Thanks!