Expression ContainsInf
orNaN
Optimization modeling functions do not allow you to specify complex,Inf
, orNaN
values. However,Inf
orNaN
expressions can arise during ordinary operations. Often, these expressions lead to erroneous solutions.
Optimization expressions containingInf
orNaN
cannot be displayed. For example, the largest real number in double precision arithmetic is about1.8e308
. So2e308
overflows toInf
.
x = optimvar('x'); y = 1e308; expr = 2*x*y
expr = OptimizationExpression Expression contains Inf or NaN.
Similarly, becauseInf - Inf = NaN
, the following expression cannot be displayed.
expr = 2*x*y - 3*x*y
expr = OptimizationExpression Expression contains Inf or NaN.
If any of your optimization expressions containInf
orNaN
, try to eliminate these values before callingsolve
. To do so:
Search for these expressions by using the
show
orwrite
functions.Check whether the expressions came from a division by zero or from the addition or multiplication of large quantities. If so, eliminate or correct the expressions.
Usually, these expressions appear as the result of errors. However, sometimes they arise from poor scaling. If necessary, divide each relevant expression by a large enough scalar so that the expression no longer overflows, or use another scaling operation.