I am wondering how to eliminate the problem of division by 0 in the objective function.
I consider that the denominator is not 0 but it shows the problem.
Also, is it possible for changing this non-linear programming to linear programming?
I am appreciated for your reply!

Hi
If you don’t initialize your model variables, GAMS assumes as a start value zero. The best way to avoid this is by setting all your variables to a value different from zero:
e.g. BWE.L = 10;

Cheers

Renger
PS. Next time you post code, put them in a code block (the </> button in the editor.

Thank you Renger~
I tried what you said. But there is another question.
I calculated and declared Xvariable.L=606.6816; however, I do not think the calculation is correct.
I think the problem can be traced to “sumofall”, if I calculated by myself, it will not be zero. But the output of the GAMS shows sumofall is 0. Thus, I considered that the problem of BWE got 0 is because of “sumofall” BWE.txt (6.92 KB)

Hi
You can set any level you want for this variable, as long as it solves.
Your second problem formulation doesn’t solve (it is infeasible). Perhaps some of your constraints do now allow for an optimal solution.
Cheers
Renger

I tried to put Xvariable.lo=1 in the equation to avoid division of 0; however, the result of Xvariable is 1.
I do not think the answer is 1 because the equaton：Xvariable=e=sum(t,sqr(X(t)-avgX))/totalt
totalt=card(t) in this case, totalt should be 3
sumofall=E=sum(t,X(t)) in this case, sumofall should be 1609 X LOWER LEVEL UPPER MARGINAL

1 503.4349 503.4349 503.4349 EPS
2 542.8836 542.8836 542.8836 EPS
3 562.6930 562.6930 562.6930 EPS
avgX=e=(sumofall/totalt) in this case, avgX should be 536.33
sum(t,sqr(X(t)-avgX)) should be 606.68
Xvariable should be 202.22

However, here is the result of the question which I post in the last reply

LOWER LEVEL UPPER MARGINAL

---- VAR total . 3.0000 +INF EPS
---- VAR avgX . . +INF EPS
---- VAR sumofall . . +INF EPS
---- VAR Xvariable 1.0000 1.0000 +INF EPS
---- VAR avgq . . +INF EPS
---- VAR sumofallq . . +INF EPS
---- VAR DCvariable . . +INF EPS
---- VAR avgin . . +INF EPS
---- VAR sumofallin . . +INF EPS
---- VAR INvariable . . +INF EPS
---- VAR BWE . . +INF EPS
---- VAR orderbwe . . +INF EPS
---- VAR invenbwe . . +INF EPS
---- VAR z -INF . +INF EPS

I could not find where is the problem.
I appreciate that you help me a lot!

Hi
If you set a lower bound of 1, the variable is not allowed to be below 1. It is a constraint. To avoid division by zero, you have to set the starting value (e.g. X.L and not X.LO).
GAMS uses the level for a variable as a starting point, the final value can be different. If you set X.LO = 1, it takes 1 as starting value, but will not get below 1.
Cheers
Renger

I see! thank you so much!
Thus, I am wondering what is the problem of my equation.
the result shows there is an equation is inconsistent with other equations in the pre-triangular part of the model.

But I have no idea about it. I search the guild manual and it said it is the conflict of the result.

here is my equation. I would like to get CR(t) from X(t) and get CA(t+1) from CR(t) and so on.
Thank you for helping me!

Hi
The only thing I can think of (but this is not my field of expertise) that somewhere in your model you also relate CU and CA (something like CU = q*CA and this conflicts with the two equations defining CU and CA (one being d times and the other 1-d times CR). Or you relate X(t) with those variables and that leads to an inconsistency.
CHeers
Renger

I am trying to find the reason and finding the problem that existed when I changed LP to NLP.
However, I have the multiple and division in variable so I need to use NLP.
I am wondering if any way I can use LP in NLP problem.

Also, I checked my answer and found an answer is negative. but I set the POSITIVE variable.
Is it possible for this error?
Thank you for patiently answering me!

Hi!
Since I still could not find the mistake, I review my code which before I changed to NLP.
I find that the result is infeasiable

So, I am trying to find the mistake.
then i think i need to constriant DU as 0 or other value(if the equation>0) which means DU cannot negitive
Maybe the reason of infeasible is the answer is negitive but I set DU as “positive variable”
this is the original equation

and I changed to

However, the result shows below. I have no idea about it. Even I changed to NLP, it still have the error 57

**** 57 Endogenous relational operations require model type “dnlp”
**** 256 Error(s) in analyzing solve statement. More detail appears
**** Below the solve statement above
**** The following LP errors were detected in model LP:
**** 57 equation E_DU… VAR operands relational or boolean
178 Display MF.L,MU.L,MI.L,MP.L,MIN.L,MIP.L,MO.L,DD.L,

Is any way can help me to check where is the problem of my coding?(about infeasiable or error57)