## Negative exponential

Problems with syntax of GAMS
Alexanre.ito
User
Posts: 36
Joined: 2 years ago

### Negative exponential

Hi I have an equation as

ir >= 0,0055* Qi^(-0,47)
ir <= 4,65 * Qf^(-0,67)
ir (m/m) and Q (L/s) are variable.

I tried to declare into the GAMS as:
Equation:

Code: Select all

``````Slope1..    ir**15 * (Qi)**7 =g= 0.0055**15
Slope2..    ir**3 *   (Qf)**2 =l= 4.65**3       ;
``````

But returns an error:
"All Jacobian elements in the row are very small"

I'm not sure if the scale will help, but I don't know how to use the correct form.

Best regards

abhosekar
Moderator
Posts: 232
Joined: 1 year ago

### Re: Negative exponential

what you show in equations and what you are writing in GAMS are two very different equations. Which one is right?
Based on what you wrote, your equation should be

Code: Select all

``````ir =g= 0.0055*qi**(-0.47)
ir =l= 4.65*Qf**(-0.67)``````
not sure how that translates to what you have in the code block.

- Atharv

Alexanre.ito
User
Posts: 36
Joined: 2 years ago

### Re: Negative exponential

uote=abhosekar post_id=29253 time=1637252514 user_id=1684]
what you show in equations and what you are writing in GAMS are two very different equations. Which one is right?
Based on what you wrote, your equation should be

Code: Select all

``````ir =g= 0.0055*Qi**(-0.47)
ir =l= 4.65*Qf**(-0.67)``````
not sure how that translates to what you have in the code block.

- Atharv
[/quote]

Hi,
Yes, it is different
If I put as

Code: Select all

``````ir =g= 0.0055*Qi**(-0.47)
ir =l= 4.65*Qf**(-0.67)``````
GAMS return

Code: Select all

`` 8 error(s): vcPower: FUNC DOMAIN: x**c, x=0, c<0``
If I put as

Code: Select all

``````ir *Qi**(0.47)=g= 0.0055
ir*Qf**(0.67) =l= 4.65``````
GAMS return

Code: Select all

`` 3 warning(s): vcPower: GRAD SINGULAR: x**c, x=0, 0<c<1``
So I changed
" **(-0.47)", and I multiplied Q to the other side of the equation.
0,47 to a fraction (7/15) and 0,67 (2/3), because GAMS does not accept an exponential number lower than 1.

Code: Select all

`````` ir**15*(Qi)**7 =g= 0.0055**12    ;
ir**3 *(Qf)**2 =l= 4.65 **3     ;``````
This is the form that I not obtain an error.

But returns
"All Jacobian elements in the row are very small."

Using SBB solver, I don't know if this solver interferes with this equation.

I declared
POSITIVE VARIABLES ir;
ir.l = 0.0001;

abhosekar
Moderator
Posts: 232
Joined: 1 year ago

### Re: Negative exponential

It's not true that GAMS does not accept exponentials less than 1. It does not accept exponential less than 1 if the number you are raising to that power is negative.
As you know negative number to fractional power is not defined (imaginary).

The reformulation you have is clever but having something raised to power 12 or 15 is not wise as for some points in the domain your model can face numerical difficulties (and this is what you observe).

So my first question would be - is Qi a positive variable? It should be since your original equation has Qi**-0.47 which is not defined for negative Qi. If it is a positive variable, are you defining it as a positive variable?
Even if you define Qi as positive variable, it can still be zero and cause domain violation. To avoid this, you should provide a small lower bound.

Code: Select all

``````positive variable
Qi;
Qi.lo = 1e-6;
``````
You should also set initial value to avoid numerical difficulties

Code: Select all

``Qi.l = 1``
- Atharv

Alexanre.ito
User
Posts: 36
Joined: 2 years ago

### Re: Negative exponential

Yes,
my Qi and Qf are positive variables.

But in my problem I have to select the direction (binary variable) that if is 1 the Qi is the sum of the flow before of this pipe.
So, some times Qi will be zero, if not ocorre the flow.

1) Should I add the binary variable in this equation? something like:

Code: Select all

``Eq(nn).. ir(nn) =g= 0.0055*(Qi(nn)*binary(nn))**(-0.47)``
or
2) Control the equation as: ??

Code: Select all

``Eq(nn)\$(not binary(nn).l=0).. ir =g= 0.0055*Qi**(-0.47)``
The option (2), I'm not sure if is correct but, this equation will be used if the variable is not 0 (zero), correct?
The option (1), If binary is 0 the variable (ir) always be >= 0?

Have some other option?

Thanks Atharv, this is helping me a lot.

abhosekar
Moderator
Posts: 232
Joined: 1 year ago

### Re: Negative exponential

Hi,

First, note that there is an underlying equation and then there is how you implement it. if the equation is wrong, modeling cannot fix it. In your case, if Qi can be 0, your equation cannot be Qi**-0.47. It's just wrong.

I see that you want
ir(nn) =g= 0.0055*Qi(nn)**(-0.47)
when Qi is not 0.

It is not clear to me what do you want the equation to be if Qi is 0?
do you want ir(nn) =g= 0 if Qi is 0? if yes, then is ir a positive variable?

based on this, you can think about how to model.

Coming the approaches you proposed, second approach is just not allowed. You cannot assign equation based on the level value of a variable (there is no level value until you solve).
First approach is not the most desired because you are raising an integer variable to some power introducing additional nonlinearities when you don't need those. I can only tell you how to model if I know what you want the equation to be when Qi is 0.
- Atharv

Alexanre.ito
User
Posts: 36
Joined: 2 years ago

### Re: Negative exponential

Thanks Atharv,
I'm understanding a little more about GAMS.
first thank you very much for your patience,

So,
I have a condition that I need to test, if the transport occurs from the node (n) to the (np), or the opposite (np,n).
One of this 2 situations will occurs. The other will be zero, or not occurs.
If on of them occurs (Q>0), so, use the equation so ( min >"ir"> max );
if not occurs transportation (Q=0), so "ir" should be none.
(maybe zero?? I'm not surre is none and zero is the same thing to this condition).

abhosekar
Moderator
Posts: 232
Joined: 1 year ago

### Re: Negative exponential

To set ir based on some condition, this is usually handled using binary variables. Using big-M constraints you can do this without introducing additional nonlinearities.

Code: Select all

``````ir =g= 0.0055*qi**(-0.47) - M*binary
ir =l= 4.65*Qf**(-0.67)  + M * binary
``````
where M is a big constant (not too big). When binary is 1, ir is greater than -M and less than M (which is equivalent to setting ir free if M is big enough).
viewtopic.php?f=15&t=12108
viewtopic.php?f=15&t=11430

However, this won't solve the problem that qi cannot be 0. So now, you can simply try replacing qi in the above equation with (qi + small_number). It won't affect the above equations because of big-M.

Code: Select all

``````ir =g= 0.0055*(qi + 1e-10)**(-0.47) - M*binary
ir =l= 4.65*(Qf + 1e-10)**(-0.67)  + M * binary
``````
- Atharv

Alexanre.ito
User
Posts: 36
Joined: 2 years ago

### Re: Negative exponential

Atharv, thanks again

Now I see, I"ll try this condition.
I used the BigM to a another equation, I hadn't thought of using this one too.
And a small number together.

dirkse
Moderator
Posts: 170
Joined: 5 years ago
Location: Fairfax, VA

### Re: Negative exponential

Alexanre,

You wrote:
I have a condition that I need to test, if the transport occurs from the node (n) to the (np), or the opposite (np,n).
One of this 2 situations will occurs. The other will be zero, or not occurs.
If on of them occurs (Q>0), so, use the equation so ( min >"ir"> max );
if not occurs transportation (Q=0), so "ir" should be none.
As you describe it, you want to sense or test whether a continuous variable is 0 or greater than 0, and use this as a logical condition for something else (in your case including an equation or not). It's often not helpful to think of it in this way: it is difficult to sense whether a variable is exactly zero or not. Solvers work with tolerances and exact checks of this nature have mathematical and computational difficulties.

Instead, turn the situation around and consider a binary variable YQ first and Q second. For example, if YQ is 0, then your constraints imply that Q is zero and no additional equations. If YQ is 1, than Q is allowed to be greater than zero and you enforce the constraints min >= IR >= max. This is very similar or perhaps even identical to what Atharv suggested, but it's useful to avoid any idea that the model is sensing that Q > 0 and setting YQ based on this.

HTH,

-Steve