Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fmincon stuck in nlconst

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 3 Feb, 2009 16:11:05

Message: 1 of 16

Hi

I am running Matlab 2008(a) with the Optimization toolbox (ver. 4),
and I have a problem when running a minimization using fmincon. I have
only upper and lower bound constraints, yet at some times, my
optimization freezes like this:

18 (iteration) 263 (function count) -2.11305e+010 (Cost)
0 (max. constraint) 1(line search step length) -2.89e+010
(direction derivative) 9.35e+011 (first order optimality procedure).

When I use ctrl+C, it always terminates at nlconst with the following
error:
??? Operation terminated by user during ==> nlconst at 664 (line
number varies, but is always within the particular section of the code
given below)

The section containing Line 664 in nlconst is for this:
         % Make sure Hessian is positive definite in update.

(I also tried introducing a dummy non linear constraint function, but
it made no difference).

Any ideas on how I can work around this? Obviously, a change in my
initial conditions would help, but unfortunately, it is for batch
processing, and I'd like as little intervention as possible.

Thanks
Srikanth

Subject: fmincon stuck in nlconst

From: Matt

Date: 3 Feb, 2009 16:43:03

Message: 2 of 16

Srikanth <skt@xdtech.com> wrote in message <37980807-f75a-4128-845c-19baf0a2d692@z28g2000prd.googlegroups.com>...
>
> The section containing Line 664 in nlconst is for this:
> % Make sure Hessian is positive definite in update.

Any idea why your Hessian would not be positive definite? Maybe a look at your objective function would provide a clue to how to avoid this region.

Subject: fmincon stuck in nlconst

From: Marcus M. Edvall

Date: 3 Feb, 2009 23:43:40

Message: 3 of 16

Your problem looks poorly scaled, but give it a shot with TOMLAB /
SNOPT /KNITRO /CONOPT.

The best would be if you defined the problem with tomSym so that
analytical derivatives are available.

Best wishes, Marcus
http://tomsym.com/
http://tomdyn.com/

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 4 Feb, 2009 00:06:12

Message: 4 of 16


> Any idea why your Hessian would not be positive definite? Maybe a look at your objective function would provide a clue to how to avoid this region.

Unfortunately, I don't see how this could be - the objective is
quadratic and positive definite in all its components. (Specifically,
Objective=x'Ax, where A is diagonal with all entries > 0).
Any other ideas?

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 4 Feb, 2009 00:13:03

Message: 5 of 16

Actually, I think I figured out the problem - a complex value is being
returned, that makes the cost negative. I should have caught this
earlier...
Thanks.
Srikanth

Subject: fmincon stuck in nlconst

From: visalakshi

Date: 5 Feb, 2009 06:00:05

Message: 6 of 16

iam using fmincon for power system optimization.

My objective is max of social welfare.

After running the program it is displayed as follows

"there is no feasible solution. search direction is less than 2*option"

How to eliminate this?

Subject: fmincon stuck in nlconst

From: Matt

Date: 5 Feb, 2009 08:05:07

Message: 7 of 16

Srikanth <skt@xdtech.com> wrote in message <e118df8b-a411-4be8-ac19-a7ffacbb2ef3@l33g2000pri.googlegroups.com>...
>
> > Any idea why your Hessian would not be positive definite? Maybe a look at your objective function would provide a clue to how to avoid this region.
>
> Unfortunately, I don't see how this could be - the objective is
> quadratic and positive definite in all its components. (Specifically,
> Objective=x'Ax, where A is diagonal with all entries > 0).
> Any other ideas?

If so, it is not at all clear why you are using fmincon(). If, as you say, A is diagonal, positive definite and you only have upper and lower boundary constraints on each x(i), then the problem has a simple closed form solution

min( min(ub'*A*ub, lb'*A*lb), 0 );

where ub and lb are the vectors of upper and lower bound constraints, respectively.

Subject: fmincon stuck in nlconst

From: Matt

Date: 5 Feb, 2009 09:01:01

Message: 8 of 16

"Matt " <xys@whatever.com> wrote in message <gme6jj$l01$1@fred.mathworks.com>...
> Srikanth <skt@xdtech.com> wrote in message <e118df8b-a411-4be8-ac19-a7ffacbb2ef3@l33g2000pri.googlegroups.com>...
> >
> > > Any idea why your Hessian would not be positive definite? Maybe a look at your objective function would provide a clue to how to avoid this region.
> >
> > Unfortunately, I don't see how this could be - the objective is
> > quadratic and positive definite in all its components. (Specifically,
> > Objective=x'Ax, where A is diagonal with all entries > 0).
> > Any other ideas?
>
> If so, it is not at all clear why you are using fmincon(). If, as you say, A is diagonal, positive definite and you only have upper and lower boundary constraints on each x(i), then the problem has a simple closed form solution
>
> min( min(ub'*A*ub, lb'*A*lb), 0 );
>
> where ub and lb are the vectors of upper and lower bound constraints, respectively.


Sorry, the above should be

a=diag(A);
z=min( min(a.*ub.^2, a.*lb.^2), 0 );
iu= (z==a.*ub.^2);
lu= (z==a.*lb.^2);
xmin=zero(size(a));
xmin(iu)=z(iu);
xmin(lu)=z(lu);

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 5 Feb, 2009 13:35:00

Message: 9 of 16


>
> If so, it is not at all clear why you are using fmincon(). If, as you say=
, =A0A is diagonal, positive definite and you only have upper and lower bou=
ndary constraints on each x(i), then the problem has a simple closed form s=
olution
>
> min( min(ub'*A*ub, lb'*A*lb), 0 );
>
> where ub and lb are the vectors of upper and lower bound constraints, res=
pectively.
Sorry, I didn't explain that right. A is diagonal positive, but
actually my cost is y'Ay, where y =3D f(x) - where x falls in the bounds
of x_Low and x_Up, f is non-linear.
Otherwise, as you mentioned, just minimizing x'Ax would be convex.
Thanks

Subject: fmincon stuck in nlconst

From: Matt

Date: 5 Feb, 2009 15:21:01

Message: 10 of 16

Srikanth <skt@xdtech.com> wrote in message <ceb2d827-c3ff-4087-9af8-3b2982e9d932@g3g2000pre.googlegroups.com>...
>
> >
> > If so, it is not at all clear why you are using fmincon(). If, as you say=
> , =A0A is diagonal, positive definite and you only have upper and lower bou=
> ndary constraints on each x(i), then the problem has a simple closed form s=
> olution
> >
> > min( min(ub'*A*ub, lb'*A*lb), 0 );
> >
> > where ub and lb are the vectors of upper and lower bound constraints, res=
> pectively.
> Sorry, I didn't explain that right. A is diagonal positive, but
> actually my cost is y'Ay, where y =3D f(x) - where x falls in the bounds
> of x_Low and x_Up, f is non-linear.
> Otherwise, as you mentioned, just minimizing x'Ax would be convex.

In that case, it's not clear why you think the function has to be positive definite everywhere. This will depend on the form of f(x).

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 5 Feb, 2009 23:42:30

Message: 11 of 16


> In that case, it's not clear why you think the function has to be positive definite everywhere. This will depend on the form of f(x).

Because f(x) is a real valued. I need to use fmincon to minimize f
(x)'Af(x), which will be positive definite (I think). If I just had
y'Ay and bounds on y, then I could (as you pointed out earlier) just
use a trivial analytic expression. I think that the expression y'*A*y
would be positive definite (given A is positive definite), and since I
don't have any idea of the values y could take (or the values of x
that give the y=f(x) that minimizes y'*A*y - and what I really need is
the x that does it), I am using fmincon.
Thanks

Subject: fmincon stuck in nlconst

From: Matt

Date: 6 Feb, 2009 15:10:03

Message: 12 of 16

Srikanth <skt@xdtech.com> wrote in message <41d12988-6274-4cc6-b18d-ec7daccc89f3@w1g2000prm.googlegroups.com>...
>
> > In that case, it's not clear why you think the function has to be positive definite everywhere. This will depend on the form of f(x).
>
> Because f(x) is a real valued. I need to use fmincon to minimize f
> (x)'Af(x), which will be positive definite (I think).

I don't think f(x) being real valued ensures positive definiteness, and neither apparently does fmincon().

Might be helpfule to have a look at f(x).

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 6 Feb, 2009 16:03:37

Message: 13 of 16


>
> I don't think f(x) being real valued ensures positive definiteness, and neither apparently does fmincon().

Not in itself, but the second derivatives have a structure (inherent
from my problem) so that they are in line with the original function
vector. So the hessian of the function should work out positive
definite. As you mentioned, it is problem specific.
Thanks
Srikanth

Subject: fmincon stuck in nlconst

From: Tohid

Date: 5 Mar, 2009 20:39:01

Message: 14 of 16

I looked trough your treads. I have the same difficulty. My objective function in some iterations gives the complex value and this make the iteration to be freezed in fmincon. I do not know how to solve the situation. I know that the problem is in having the complex value (which I should not have as the value of objective function...I dont know why I have actually)...
Can you tell me how to solve it? when you found that the problem is becasue of complex value, what did you do?
I apprictae.
Tohid

Srikanth <skt@xdtech.com> wrote in message <74c61669-faf5-4635-9742-b45a952aa89e@p23g2000prp.googlegroups.com>...
> Actually, I think I figured out the problem - a complex value is being
> returned, that makes the cost negative. I should have caught this
> earlier...
> Thanks.
> Srikanth

Subject: fmincon stuck in nlconst

From: Srikanth

Date: 11 Mar, 2009 17:58:32

Message: 15 of 16

On Mar 5, 1:39=A0pm, "Tohid " <erfanito...@gmail.com> wrote:
> I looked trough your treads. I have the same difficulty. My objective fun=
ction in some iterations gives the complex value and this make the iteratio=
n to be freezed in fmincon. I do not know how to solve the situation. I kno=
w that the problem is in having the complex value (which I should not have =
as the value of objective function...I dont know why I have actually)...
> Can you tell me how to solve it? when you found that the problem is becas=
ue of complex value, what did you do?
> I apprictae.
> Tohid

Hi
The problem still persisted in nlconst.m - there is a line (near line
664, as I mentioned earlier) where it was stuck in a loop that tries
to make the hessian positive definite. So I just added a counter in
the loop that quits with an error if it does not exit after a
particular number of iterations.
You might also want to consider a try-catch at the place where you
call fmincon, so that when this error occurs, you don't terminate
execution (for example, if you do batch minimizations, where you want
to continue with the next sample even if one minimization fails).
hth

Subject: fmincon stuck in nlconst

From: C F

Date: 17 Aug, 2009 20:30:04

Message: 16 of 16

Srikanth <skt@xdtech.com> wrote in message <07d88128-f64d-4593-b4b4-dbe4199e2a2b@r36g2000prf.googlegroups.com>...
> On Mar 5, 1:39=A0pm, "Tohid " <erfanito...@gmail.com> wrote:
> > I looked trough your treads. I have the same difficulty. My objective fun=
> ction in some iterations gives the complex value and this make the iteratio=
> n to be freezed in fmincon. I do not know how to solve the situation. I kno=
> w that the problem is in having the complex value (which I should not have =
> as the value of objective function...I dont know why I have actually)...
> > Can you tell me how to solve it? when you found that the problem is becas=
> ue of complex value, what did you do?
> > I apprictae.
> > Tohid
>
> Hi
> The problem still persisted in nlconst.m - there is a line (near line
> 664, as I mentioned earlier) where it was stuck in a loop that tries
> to make the hessian positive definite. So I just added a counter in
> the loop that quits with an error if it does not exit after a
> particular number of iterations.
> You might also want to consider a try-catch at the place where you
> call fmincon, so that when this error occurs, you don't terminate
> execution (for example, if you do batch minimizations, where you want
> to continue with the next sample even if one minimization fails).
> hth


I'm having the same exact problem when trying to run batch minimizations. Unfortunately, I'm running matlab off our university's server, and we are unable to manually change script files that are internal matlab functions. (Ie, I can't change the "fmincon.m" file to remove the while loop that seems to be the culprit here.) Any other suggestions as to how to exit the loop and keep my program running to the next minimization? I'd be ok with losing any data from the current minimization as long as the program moves on to the next one.


Thanks,
CF

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us