Mauro,
From inspecting the code that you posted I was not able to
see anything obviously wrong that could cause the error.
It would be useful to be able to run your code to reproduce
the problem. If it's possible, I suggest that you send your
code to tech support.
If this is not possible, can you post the values of all the
inputs to qpsub() during the call where the error occurs?
Marcelo
mauro Gaggero wrote:
> Hi, while using fmincon function of the Optimization Toolbox in Matlab r2008b I got the following error:
> 
> ??? Subscript indices must either be real positive integers or logicals.
> Error in ==> qpsub>eqnsolv at 916
> ACTSET = A(ACTIND,:);
> Error in ==> qpsub at 155
> [Q,R,A,B,X,Z,how,ACTSET,ACTIND,ACTCNT,aix,eqix,neqcstr,ncstr, ...
> Error in ==> nlconst at 668
> [SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
> Error in ==> fmincon at 728
> [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
> Error in ==> optimizerFmincon at 48
> [uopt(:,i), J(i), exitfl(i)] = fmincon(@(u) costFunction(u, x, d, A, B, C, D, Ncontrols, Nsell, xaxis, cost,
> t, T), u0, [], [], [], [], UminUmin, Umax, @(u) constraints(u, x, d, Umin, freq,
> Error in ==> simulationSC at 25
> [controls, Jopt, exitflag] = optimizerFmincon(x, d, A, B, C, D, k, T, Umin, Unominal, Umax, freq, Ncontrols,
> Nsell, xaxis, cost, optimizationTrials);
> Error in ==> mainSC at 56
> [x, u] = simulationSC(d, x0, xmax, Umin, Unominal, Umax, freq, A, B, C, D, Ncontrols, Nsell, xaxis, cost, T, Tfin,
> optimizationTrials);
> 
>
> The variable ACTIND in qpsub.m takes on negative values and thus the instruction ACTSET = A(ACTIND,:); fails. By adding ACTIND = max(ACTIND, 1); the error disapperars.
>
> I got this error while solving many optimization problems with inequality and equality constraints one after the other. The error appears in different points when I lauch again the simulation. How can I solve my problem? Did I make something wrong or Matlab has a bug?
>
> Thanks a lot.
> Mauro
>
> I post the call of fmincon:
> [uopt(:,i), J(i), exitfl(i)] = fmincon(@(u) costFunction(u, x, d, A, B, C, D, Ncontrols, Nsell, xaxis, cost, t, T), u0, [], [], [], [], UminUmin, Umax, @(u) constraints(u, x, d, Umin, freq, A, B, D, Ncontrols, Nsell, t, T), options);
>
> the cost function:
> function retval = costFunction(u, x, d, A, B, C, D, Ncontrols, Nsell, xaxis, cost, currentInstant, T)
>
> retval = 0;
> one = ones(1, Ncontrols);
> for k=currentInstant:currentInstant+T1
> retval = retval + C*x(:,k) + one*getTransferCost(u(1+(kcurrentInstant)*Ncontrols:(kcurrentInstant+1)*Ncontrols), Ncontrols, xaxis, cost);
> x(:,k+1) = A*x(:,k) + B*u(1+(kcurrentInstant)*Ncontrols:(kcurrentInstant+1)*Ncontrols) + D*d(:,k);
> end
>
> the constraints function:
> function [c, ceq] = constraints(u, x, d, Umin, freq, A, B, D, Ncontrols, Nsell, currentInstant, T)
>
> ceq = zeros((NcontrolsNsell)*T, 1);
> dimX = size(x, 1);
> c1 = zeros(dimX*T, 1);
> c2 = zeros((NcontrolsNsell)*T, 1);
> c = zeros(dimX*T+(NcontrolsNsell)*T, 1);
> for k=currentInstant:currentInstant+T1
> for i=1:NcontrolsNsell
> if(mod(k, freq(i))~=0)
> ceq((kcurrentInstant)*(NcontrolsNsell)+i) = u(Nsell*(kcurrentInstant)+(kcurrentInstant)*(NcontrolsNsell)+i);
> else
> c2((kcurrentInstant)*(NcontrolsNsell)+i) = Umin(i)  u(Nsell*(kcurrentInstant)+(kcurrentInstant)*(NcontrolsNsell)+i);
> end
> end
> x(:,k+1) = A*x(:,k) + B*u(1+(kcurrentInstant)*Ncontrols:(kcurrentInstant+1)*Ncontrols) + D*d(:,k);
> c1(1+(kcurrentInstant)*dimX:(kcurrentInstant+1)*dimX,1) = x(:,k+1);
> end
> c = [c1;c2];
>
