Saturday, May 23, 2009

Domain error with log

> When I run my GAMS model I get
> *** Error at line 36749: log: FUNC SINGULAR: x = 0
> How can I fix this?

This means that you have a function log(x) in your model (see line 36749 in the listing file), where x assumes the value x=0.

There are several ways to fix this.

  1. Apply a bound X.LO=0.0001;. Of course if you have LOG(EXPRESSION) then this is a little bit more complicated. In that case you need to introduce a new variable Y, and an equation Y =E= EXPRESSION; after which you can add Y.LO=0.0001 and use LOG(Y). The NLP solvers under GAMS will never evaluate a nonlinear function with the arguments outside their bounds. Note that adding a bound also changes the default initial point. Usually the default initial point is zero, but when there are bounds the default initial point becomes the closest bound from zero.
  2. If it is just an intermediate point during the solve you can as a short-cut increase the DOMLIM option to allow a few domain errors. The initial point must be valid, otherwise GAMS will not start the solver (this can be fixed by a better initial point). In general I use this if option 1 is too complicated to implement quickly or if the addition of extra variables and equations makes the model (much) more difficult.
  3. If you have POSITIVE VARIABLE X, then LOG(X+0.0001) is quick way to bypass the problem. The advantage of this formulation is that we still allow X=0 which may improve the readability of the solution reports.

Note that solvers may allow variables to be slightly outside their bounds due to different feasibility tolerances. The suggested value 0.0001 is sufficiently large not to be bothered by this.

2 comments:

  1. Hello Erwin
    Whenever I try to put a power function i get "domain error in nonlinear function" message. How do I solve for this. My present function has 1/beta as the power where beta is just a scalar.

    Thanks
    Sanchari

    ReplyDelete
  2. Same as explained in this post. If you are still confused, you can always get support from support@gams.com.

    ReplyDelete