1

I'm having a strange error when using fmincon. The details about the objective function and the nonlinear constraint functions are many, so I'm going to try to ask this question without describing those if possible.

The minimization requires a single input. For some but not all inputs, I get the following error:

Subscript indices must either be real positive integers or logicals.

Error in qpsub>eqnsolv (line 888)
    ACTSET = A(ACTIND,:);

Error in qpsub (line 157)
[Q,R,A,B,X,Z,how,ACTSET,ACTIND,ACTCNT,aix,eqix,neqcstr,ncstr, ...

Error in nlconst (line 619)
    [SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...

Error in fmincon (line 794)
[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...

Error in PauliApproximate2.unitalChannelApproximate (line 170)
        [pc, distance] = fmincon(@objective,x0, A, b, Aeq, beq,lb,ub, @constraint,
        options);

When I check to see the value of ACTIND, the error is thrown when it equals [0], hence the indexing error. Similar to the hack that the OP of this thread used, before the line (in qpsub)

ACTSET = A(ACTIND,:);

I put the if statement:

    if max(ACTIND) < 1
        ACTIND = [1];
    end

From preliminary testing this seems to "Fix" the problem. It is giving sensible results for inputs that used to throw the error (in that it is returning a good minimum value and the constraints are satisfied to within tolerance), and is returning the same results it always did for inputs that didn't have the error (obviously, as the if statement won't be invoked). So my question is, for people that know the inner workings of these functions, how bad is this? Am I sidestepping a horrible issue that results in ACTIND being [0] that I shouldn't be?

4

0 回答 0