fmincon crashs if called to many times

My problem seems to be, that fmincon will crash if it is called to many times. I am using matlab 2007b. More details are below.
I have a cost function F(x,N) where x is a vector containing the optimization variables, and N is a vector containing various parameters. For each of the possible values of N, I would like to optimize F, so the code look something like
for N = values of N
cost = @(x) F(x,N)
x0 = random guess for x
x_opt(:,N) = fmincon(cost,x0, constraints, options)
end
Everything works fine up until a particular values of N, which I'll call N_bad. At this point the following error is generated:
Error in ==> pinv at 29 [U,S,V] = svd(A,0);
Error in ==> qpsub at 494 projSD = pinv(projH)*(-Zgf);
Error in ==> nlconst at 711 [SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
Error in ==> fmincon at 562 [X,FVAL,lambda,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Which causes the entire program to crash.
Furthermore, it doesn't seem to be the specific value of N_bad which causes the error, because if I run the previous code without the loop and set N=N_bad, everything works fine. Additionally, If I loop over a smaller number of N's, including N_bad, everything still works.
So the problem seems to be, that fmincon will crash if it is called to many times.
Has anyone else seen this? If so, how can it be fixed?

1 Comment

Did you try "dbstop if error" and examine the value of A? The debugger is usually very helpful for such problems.

Sign in to comment.

Answers (0)

Asked:

on 4 Apr 2011

Community Treasure Hunt

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

Start Hunting!